local U = require "scriptbank\\utillib" local Q = require "scriptbank\\quatlib" 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 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 scan_delay = 250 --how often to play the beeping scan_object_name = {} scan_object_e = {} local current_scan = "None" local temp_selection = {} local page = 1 local items_per_page = 10 local panel_sizex = 40 local panel_sizey = 8 local start_px = 2 local start_py = 2 local got_list = 0 local selected = 0 local pressed = 1 local px = 0 local py = 0 local state = "" local _name = "" function scanner_init_name(e,name) state = "wait pick up" _name = name end function scanner_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" Hide(e) CollisionOff(e) end else epress = 0 end end elseif state == "collected" then SetPosition(e,g_PlayerPosX,g_PlayerPosY+500,g_PlayerPosZ) if GetKeyState(select_scan_key) == 1 then if got_list == 0 then --count scannable items so we know how many types we need to list local temp = 0 local skip = 0 for a,b in pairs (scan_object_e) do skip = 0 for c,d in pairs (temp_selection) do if scan_object_name[a] == temp_selection[c] then skip = 1 break end end if skip == 0 then temp = temp + 1 temp_selection[temp] = scan_object_name[a] end end got_list = 1 end ActivateMouse() --show selection on screen local size = 0 px = start_px py = start_py for a = 1, items_per_page do if temp_selection[a+((page-1)*items_per_page)] == nil then break end if a == items_per_page*0.5 then py = start_py px = 50+px end Panel(px,py,px+panel_sizex,py+panel_sizey) size = 2 if g_MouseX >= px and g_MouseX <= px+panel_sizex then if g_MouseY >= py and g_MouseY <= py+panel_sizey then size = 3 end end TextCenterOnX(px+(panel_sizex*0.5),py+(panel_sizey*0.5),size,"("..a..") "..temp_selection[a+((page-1)*items_per_page)]) py = py+panel_sizey+2 end --shows the cursor using a small panel Panel(g_MouseX-0.1,g_MouseY-0.1,g_MouseX+0.1,g_MouseY+0.1) pressed = 1 StartTimer(e) else got_list = 0 if pressed == 1 then py = start_py px = start_px selected = 0 for a = 1, items_per_page do if temp_selection[a+((page-1)*items_per_page)] == nil then break end if a == items_per_page*0.5 then py = start_py px = 50+px end if g_MouseX >= px and g_MouseX <= px+panel_sizex then if g_MouseY >= py and g_MouseY <= py+panel_sizey then selected = temp_selection[a+((page-1)*items_per_page)] end end py = py+panel_sizey+2 end DeactivateMouse() end pressed = 0 end if selected ~= 0 then Prompt("scanning for "..selected) if GetTimer(e) > scan_delay then StartTimer(e) local plx,ply,plz = g_PlayerPosX,g_PlayerPosY,g_PlayerPosZ local dist = 3000 vol = 0 for c = 1, 110 do if vol ~= 0 then break end for a,b in pairs (scan_object_name) do if selected == scan_object_name[a] then if U.PlayerLookingNear( a, dist, c ) then PlaySound(e,1) local ox,oy,oz = GetEntityPosAng(a) local tdist = TCloserThan(plx,ply,plz,ox,oy,oz) tdist = (100-((tdist/dist)*100)*0.75) vol = ((100-c)*0.25)+tdist SetSoundVolume(vol) break end end end end end end end end function scanner_exit(e) 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