function AddPed(_thePlayer)
local x, y, z = getElementPosition(_thePlayer);
x = x + math.sin(math.rad(getElementRotation(_thePlayer))) * 2
y = y - math.cos(math.rad(getElementRotation(_thePlayer))) * 2
--thePed = createPed (math.random(10, 270), x, y, z)
ped = createPed (math.random(10, 270), x, y, z)
local pedsCount = tonumber(getElementData(_thePlayer,'peds')) or 0
setElementData(_thePlayer,'peds',pedsCount+1)
setElementData(ped,tostring(getPlayerAccount(_thePlayer)),tonumber(getElementData(_thePlayer,'peds')))
end
addCommandHandler ("ped", AddPed)
function RemovePed(_thePlayer,cmd,player,pedid)
local player = getPlayerFromName(tostring(player))
pedsCount = tonumber(getElementData(player,'peds')) or 0
if pedsCount > 0 then
for k,v in ipairs(getElementsByType( "ped" )) do
if getElementData(v,tostring(getPlayerAccount(player))) and getElementData(v,tostring(getPlayerAccount(player))) == tonumber(pedid) then
destroyElement(v)
setElementData(player,'peds',pedsCount-1)
end
end
end
end
addCommandHandler("pedRemoveFromPlayer", RemovePed)
I'm not sure if it works