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

Return Ped Entity from spawnPed Function for Improved Management and Deletion #209

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
26 changes: 21 additions & 5 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ exports('DeletePeds', DeletePeds)
local function SpawnPed(data)
local spawnedped
local key, value = next(data)
local createdPeds = {}
if type(value) == 'table' and type(key) ~= 'string' then
for _, v in pairs(data) do
if v.spawnNow then
Expand Down Expand Up @@ -970,6 +971,7 @@ local function SpawnPed(data)
if nextnumber <= 0 then nextnumber = 1 end

Config.Peds[nextnumber] = v
createdPeds[#createdPeds + 1] = v.currentpednumber
end
else
if data.spawnNow then
Expand Down Expand Up @@ -1071,19 +1073,33 @@ local function SpawnPed(data)
if nextnumber <= 0 then nextnumber = 1 end

Config.Peds[nextnumber] = data
createdPeds[#createdPeds + 1] = data.currentpednumber

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could instead return early with the singular ped ID since data wouldn't be a table of peds in this instance.

end
return createdPeds
end

exports('SpawnPed', SpawnPed)

local function RemovePed(peds)

local function removePedByNumber(pedNumber)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this could be a typo of placing a function declaration inside of a function declaration.

for i = #Config.Peds, 1, -1 do -- Reverse loop to avoid index issues
local ped = Config.Peds[i]
if ped.currentpednumber == pedNumber then
SetEntityAsNoLongerNeeded(ped.currentpednumber)
DeletePed(ped.currentpednumber)
table.remove(Config.Peds, i)
break
end
end
end

if type(peds) == 'table' then
for k, v in pairs(peds) do
DeletePed(v)
if Config.Peds[k] then Config.Peds[k].currentpednumber = 0 end
end
for _, pedNumber in pairs(peds) do
removePedByNumber(pedNumber)
end
elseif type(peds) == 'number' then
DeletePed(peds)
removePedByNumber(peds)
end
end

Expand Down
Loading