unkwn Posted April 5, 2020 Share Posted April 5, 2020 Hello. Prescribed the issuance of skins to bots by "levels". But I ran into a problem: the first bot will spawn with a random skin, and then there is a spawn on the levels. addEvent( "onZombieSpawn", true ) function RanSpawn_Z ( gx, gy, gz, rot, zombieType, row ) local safezone = 0 local allradars = getElementsByType("radararea") for theKey,theradar in ipairs(allradars) do if getElementData(theradar, "zombieProof") == true then if isInsideRadarArea ( theradar, gx, gy ) then safezone = 1 end end end if safezone == 0 then if table.getn ( everyZombie ) < newZombieLimit then if not rot then rot = math.random (1,359) end randomZskin = math.random ( 1, table.getn ( ZombiePedSkins ) ) local zomb = createPed( tonumber( ZombiePedSkins[randomZskin] ), gx, gy, gz ) setElementData( zomb, "zombie:type", zombieType ) if zombieType == 1 then ZombiePedSkins = {10} local zomb = createPed( tonumber( ZombiePedSkins[randomZskin] ), gx, gy, gz ) setElementData( zomb, "head:n", 1) setElementData( zomb, "head:now", 0 ) elseif zombieType == 2 then ZombiePedSkins = {10} exports.extra_health:setElementExtraHealth ( zomb, 400 ) setElementData( zomb, "head:n", 3 ) setElementData( zomb, "head:now", 0 ) elseif zombieType == 3 then ZombiePedSkins = {11} setElementData( zomb, "respawn:zombie", row ) exports.extra_health:setElementExtraHealth ( zomb, 800 ) end if zomb ~= false then setElementData ( zomb, "zombie", true ) table.insert( everyZombie, zomb ) setTimer ( function (zomb, rot) if ( isElement ( zomb ) ) then setPedRotation ( zomb, rot ) end end, 500, 1, zomb, rot ) local chaseanim, checkspeed = getZombieType ( zomb ) setTimer ( function (zomb) if ( isElement ( zomb ) ) then setPedAnimation ( zomb, "ped", chaseanim, -1, true, true, true ) end end, 1000, 1, zomb ) setTimer ( function (zomb) if ( isElement ( zomb ) ) then setElementData ( zomb, "status", "idle" ) end end, 2000, 1, zomb ) triggerClientEvent ( "Zomb_STFU", getRootElement(), zomb ) end end end end addEventHandler( "onZombieSpawn", getRootElement(), RanSpawn_Z ) I think it's related to these lines: randomZskin = math.random ( 1, table.getn ( ZombiePedSkins ) ) local zomb = createPed( tonumber( ZombiePedSkins[randomZskin] ), gx, gy, gz ) setElementData( zomb, "zombie:type", zombieType ) Link to comment
The_GTA Posted April 5, 2020 Share Posted April 5, 2020 (edited) 2 hours ago, unkwn said: Hello. Prescribed the issuance of skins to bots by "levels". But I ran into a problem: the first bot will spawn with a random skin, and then there is a spawn on the levels. Hello unkwn, I think the issue is simple code structure. The problem is that you are creating a ped while you do not know what skin it should have at first. You should first determine the array of available skins and then create the ped: addEvent( "onZombieSpawn", true ) function RanSpawn_Z ( gx, gy, gz, rot, zombieType, row ) local safezone = 0 local allradars = getElementsByType("radararea") for theKey,theradar in ipairs(allradars) do if getElementData(theradar, "zombieProof") == true then if isInsideRadarArea ( theradar, gx, gy ) then safezone = 1 end end end if safezone == 0 then if table.getn ( everyZombie ) < newZombieLimit then if not rot then rot = math.random (1,359) end local ZombiePedSkins = false; if (zombieType == 1) or (zombieType == 2) then ZombiePedSkins = {10} elseif (zombieType == 3) then ZombiePedSkins = {11} end if (ZombiePedSkins) then local randomZskin = math.random ( 1, table.getn ( ZombiePedSkins ) ) local zomb = createPed( tonumber( ZombiePedSkins[randomZskin] ), gx, gy, gz ) if (zomb ~= false) then setElementData( zomb, "zombie:type", zombieType ) if zombieType == 1 then setElementData( zomb, "head:n", 1) setElementData( zomb, "head:now", 0 ) elseif zombieType == 2 then exports.extra_health:setElementExtraHealth ( zomb, 400 ) setElementData( zomb, "head:n", 3 ) setElementData( zomb, "head:now", 0 ) elseif zombieType == 3 then setElementData( zomb, "respawn:zombie", row ) exports.extra_health:setElementExtraHealth ( zomb, 800 ) end setElementData ( zomb, "zombie", true ) table.insert( everyZombie, zomb ) setTimer ( function (zomb, rot) if ( isElement ( zomb ) ) then setPedRotation ( zomb, rot ) end end, 500, 1, zomb, rot ) local chaseanim, checkspeed = getZombieType ( zomb ) setTimer ( function (zomb) if ( isElement ( zomb ) ) then setPedAnimation ( zomb, "ped", chaseanim, -1, true, true, true ) end end, 1000, 1, zomb ) setTimer ( function (zomb) if ( isElement ( zomb ) ) then setElementData ( zomb, "status", "idle" ) end end, 2000, 1, zomb ) triggerClientEvent ( "Zomb_STFU", getRootElement(), zomb ) end end end end end end addEventHandler( "onZombieSpawn", getRootElement(), RanSpawn_Z ) Hope this helps! - Martin Edited April 5, 2020 by The_GTA fixed a tiny bug Link to comment
unkwn Posted April 5, 2020 Author Share Posted April 5, 2020 (edited) Yes, it really helped, thank you. Can you help me with another error in the same lines? ERROR: [gameplay]/zombies/zombie_server. Lua:428: attempt to compare number with nil if safezone == 0 then if table.getn ( everyZombie ) < newZombieLimit then --428 line if not rot then rot = math.random (1,359) end Edited April 5, 2020 by unkwn Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now