Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ESX.Players): metamethod for counting players #1246

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion [core]/es_extended/server/classes/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,

if weapon then
weapon.ammo = weapon.ammo - ammoCount
self.triggerEvent('esx:setWeaponAmmo', weaponName, weapon.ammo)
_SetPedAmmo(GetPlayerPed(self.source), joaat(weaponName), weapon.ammo)
end
end

Expand Down
10 changes: 10 additions & 0 deletions [core]/es_extended/server/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ Core.playersByIdentifier = {}

Core.vehicleTypesByModel = {}

setmetatable(ESX.Players, {
__len = function()
local c = 0
for _, _ in pairs(ESX.Players) do
c = c + 1
end
return c
end
})

AddEventHandler("esx:getSharedObject", function()
local Invoke = GetInvokingResource()
print(("[^1ERROR^7] Resource ^5%s^7 Used the ^5getSharedObject^7 Event, this event ^1no longer exists!^7 Visit https://documentation.esx-framework.org/tutorials/tutorials-esx/sharedevent for how to fix!"):format(Invoke))
Expand Down
2 changes: 1 addition & 1 deletion [core]/es_extended/server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ end

function ESX.GetNumPlayers(key, val)
if not key then
return #GetPlayers()
return #ESX.Players
end

if type(val) == "table" then
Expand Down
Loading