--requires images in scriptbank\\images\\motion_tracker\\" --sound slot 1 = motion detected noise --these should roughly match the shape of your motion tracker image --*note settings below expect the center of the tracker image to represent the player's position --you should add empty pixels to your image if that is not the case* local max_tracking_distance = 1400 --max range at which motion can be detected local max_tracking_fov = 90 --max field of view in which motion can be detected local select_scan_key = 16 --sets which key to hold to open scanner selection page --18 = E key , 16 = Q (codes can be found online) local show_dot_time = 1500 --how long to display the dot for while tracking local tracker_sizex = 60 --how wide the motion tracker is on screen (1-100) local tracker_sizey = 80 --how tall the motion tracker is on screen (1-100) local tracker_pos_x = 50 --middle x position of the motion tracker local tracker_pos_y = 60 --middle y position of the motion tracker local dot_sizex = 1 --how big the motion dots appear (wide) local dot_sizey = 1.3 --how big the motion dots appear (tall) local U = require "scriptbank\\utillib" local rad = math.rad local deg = math.deg local floor = math.floor local atan = math.atan2 local abs = math.abs local sqrt = math.sqrt local sin = math.sin local cos = math.cos local mt_img = LoadImage("scriptbank\\images\\motion_tracker\\motion_tracker.png") local mt_spr = CreateSprite(mt_img) local dot_img = LoadImage("scriptbank\\images\\motion_tracker\\motion_dot.png") local dot_spr = CreateSprite(dot_img) SetSpritePosition(dot_spr,200,200) SetSpritePosition(mt_spr,200,200) SetSpriteSize(mt_spr,tracker_sizex,tracker_sizey) SetSpriteSize(dot_spr,dot_sizex,dot_sizey) local tracking = 1 SetSpriteOffset(mt_spr,tracker_sizex*0.5,tracker_sizey*0.5) local last_pos = {} local show_dot = {} local dot_posx = {} local dot_posy = {} local state = "" local _name = "" epress = 0 function motion_tracker_init_name(e,name) state = "wait pick up" _name = name end function motion_tracker_main(e) if state == "wait pick up" then if U.PlayerLookingAt( e, 100, 0) then PromptLocal(e,"Collect the ".._name.."? (e)") if g_KeyPressE == 1 then if epress == 0 then epress = 1 state = "collected" CollisionOff(e) Hide(e) end else epress = 0 end end elseif state == "collected" then local px,py,pz = g_PlayerPosX,g_PlayerPosY,g_PlayerPosZ SetPosition(e,px,py+500,pz) if GetKeyState(select_scan_key) == 1 then tracking = 1 else tracking = 0 end if tracking == 1 then PasteSpritePosition(mt_spr,tracker_pos_x,tracker_pos_y) for a,b in pairs (ai_bot_state) do if show_dot[a] == nil then show_dot[a] = 0 end if last_pos[a] == nil then last_pos[a] = 1 last_pos[a] = {} end if U.PlayerLookingNear( a, max_tracking_distance, max_tracking_fov ) then local cx,cy,cz = GetEntityPosAng(a) if last_pos[a][1] == nil then last_pos[a][1] = cx last_pos[a][2] = cy last_pos[a][3] = cz else if TCloserThan(last_pos[a][1],last_pos[a][2],last_pos[a][3],cx,cy,cz) > 70 then show_dot[a] = g_Time+show_dot_time PlaySound(e,1) last_pos[a][1] = cx last_pos[a][2] = cy last_pos[a][3] = cz local angle = pointAtPlayer(a) + rad(g_PlayerAngY) local dist = GetPlayerDistance(a) if dist > max_tracking_distance then dist = max_tracking_distance end dot_posx[a] = tracker_pos_x + (( sin(angle) * ( dist / 50.0 ) * (GetDeviceHeight()/GetDeviceWidth()) )) dot_posy[a] = tracker_pos_y + ( cos(angle) * ( dist / 50.0 ) ) end end end if show_dot[a] > 0 then --work out position on tracker image to display the dot PasteSpritePosition ( dot_spr , dot_posx[a] , dot_posy[a] ) if g_Time > show_dot[a] then show_dot[a] = 0 end end end end end end function motion_tracker_exit(e) end function pointAtPlayer (i) x = g_PlayerPosX - g_Entity[i]['x']; z = g_PlayerPosZ - g_Entity[i]['z']; angle = math.atan2( z , x ); angle = angle + (-90.0*0.0174533); return angle; end function TCloserThan( x1, y1, z1, x2, y2, z2) local dx, dy, dz = x1 - x2, y1 - y2, z1 - z2 return sqrt(dx*dx+dy*dy+dz*dz) end