-- LUA Script - precede every function and global member with lowercase name of script + '_main' g_notes = {} g_all_notes_collected = false local randomPositions = { -- number for testing only replace with real locations {x = 25200.10, y = 600.00, z = 26200.00, ang = 10.00, used = false}, {x = 25300.20, y = 600.00, z = 26500.00, ang = 90.10, used = false}, {x = 25600.30, y = 600.00, z = 26100.50, ang = 270.50, used = false}, {x = 25400.80, y = 600.00, z = 26400.20, ang = 180.20, used = false}, {x = 25100.80, y = 600.00, z = 26600.20, ang = 0.20, used = false}, {x = 25700.80, y = 600.00, z = 26200.20, ang = 80.20, used = false}, {x = 25900.80, y = 600.00, z = 26100.20, ang = 300.20, used = false}, -- etc -- add more entries as needed {x = 25800.00, y = 600.00, z = 26500.40, ang = 45.00, used = false}} function collect_note_init(e) g_notes[e] = {positioned = false, collected = false} end local function allCollected() for k,_ in pairs(g_notes) do if not g_notes[k].collected then return false end end return true end local function CloserThan(Ent, dist) local dX, dZ = Ent.x - g_PlayerPosX, Ent.z - g_PlayerPosZ return (dX*dX + dZ*dZ) < dist*dist end function collect_note_main(e) local note = g_notes[e] if note == nil then return end if not note.positioned then local randPos = nil while randPos == nil do local i = math.random(1,#randomPositions) if not randomPositions[i].used then randPos = randomPositions[i] randPos.used = true end end CollisionOff(e) ResetPosition(e, randPos.x, randPos.y, randPos.z) ResetRotation(e, 0, randPos.ang, 0) CollisionOn(e) note.positioned = true end if note.positioned and not note.collected then local Ent = g_Entity[e] if not CloserThan(Ent, 150) then return end if g_PlayerHealth > 0 then local SourceAngle = g_PlayerAngY while SourceAngle < 0 do SourceAngle = SourceAngle + 360 end while SourceAngle > 360 do SourceAngle = SourceAngle - 360 end local DX = Ent.x - g_PlayerPosX local DZ = Ent.z - g_PlayerPosZ local DestAngle = math.atan2(DZ, DX) -- Convert to degrees DestAngle = (DestAngle * 57.2957795) - 90.0 local Result = math.abs(math.abs(SourceAngle)-math.abs(DestAngle)) if Result > 180 then Result = 0 end if Result < 20 then if g_PlayerController == 0 then Prompt ("Press E to pick up the note") else Prompt ("Press Y Button to pick up the note") end if g_KeyPressE == 1 then PromptDuration("Collected the note", 3000) if allCollected() then g_all_notes_collected = true end Destroy(e) ActivateIfUsed(e) note.collected = true end end end end end