Hello guys could somebody tell me where I went wrong with the tables?
I'm basically trying to give each zombie an id so they can follow the player
local maxzombies = 30
local zombiecount = 0
zombie{}
function spawn()
local x,y,z = getElementPosition (localPlayer)
zombie[tostring(zombiecount)] = zombiecount
local zombie[zombiecount] = createPed (20,x+math.random(-7,7),y+math.random(-7,7),z)
end
function follow()
zpx,zpy,zpz = getElementPosition (zombie[zombiecount])
local zombie_angle = (360 - math.deg(math.atan2((zpx - x), (zpy - y)))) % 360
local dist = getDistanceBetweenPoints2D(x, y, zpx, zpy)
if (dist > 2) then
setPedCameraRotation (zombie[zombiecount],zombie_angle)
setPedControlState(zombie[zombiecount], "forwards", true)
elseif (dist < 2) then
setPedControlState(zombie[zombiecount], "forwards", false)
setPedControlState(zombie[zombiecount], "fire", true)
end
end
setTimer (follow, 1000, 0)
function zombie_check()
if (zombiecount < maxzombies) then
spawn()
zombiecount = zombiecount + 1
end
end
setTimer (zombie_check, 100, 0)
function zombie_died()
zombiecount = zombiecount - 1
end
addEventHandler("onClientPedWasted", getRootElement(), zombie_died)