GET_ACTIVE_PLAYERS: the replacement for player loops

Just a quick hint: when writing new client-side scripts in Lua/JS (C# already has the Players list doing exactly this), you can loop through players by using the GET_ACTIVE_PLAYERS native. See below for an example of before/after:

Before…

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
for i = 0, 255 do
if NetworkIsPlayerActive(i) then
local ped = GetPlayerPed(i)
-- do stuff
end
end
for i = 0, 255 do if NetworkIsPlayerActive(i) then local ped = GetPlayerPed(i) -- do stuff end end
for i = 0, 255 do
    if NetworkIsPlayerActive(i) then
        local ped = GetPlayerPed(i)
        -- do stuff
    end
end

After…

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
for _, player in ipairs(GetActivePlayers()) do
local ped = GetPlayerPed(player)
-- do stuff
end
for _, player in ipairs(GetActivePlayers()) do local ped = GetPlayerPed(player) -- do stuff end
for _, player in ipairs(GetActivePlayers()) do
    local ped = GetPlayerPed(player)
    -- do stuff
end

This should be a bit more performant than 256 native invocations, even if no player slot exists, and it also doesn’t differ based on server-side sync technology slot count – all players with an active ped should be returned by this native.