Chaos Posted January 15, 2014 Posted January 15, 2014 hi, i have problem with this code when sometimes i kill 30 zombies the zombies won't respawn again why ? ZombieKills = 0 function teste() for i=1,50 do exports [ "zombiegamemode" ]:createZombie(-1095.76440+math.random(-4,30),-984.83356+math.random(-4,50),129.2187) end end addEventHandler ( "onResourceStart", getRootElement(), teste ) addEventHandler("onZombieWasted",root, function() if (ZombieKills ~= 30) then ZombieKills = ZombieKills+1 else ZombieKills = 0 teste() end end)
WASSIm. Posted January 16, 2014 Posted January 16, 2014 function teste() for i=1,50 do exports [ "zombiegamemode" ]:createZombie(-1095.76440+math.random(-4,30),-984.83356+math.random(-4,50),129.2187) end end addEventHandler ( "onResourceStart", getRootElement(), teste ) addEventHandler("onZombieWasted",root, function() if not (ZombieKills) then if (ZombieKills >= 30) then teste () end ZombieKills = ZombieKills+1 else ZombieKills = 1 end end )
KieronWiltshire Posted January 16, 2014 Posted January 16, 2014 You should always really try to avoid recursive function calling unless it's absolutely needed which for example is in this case.
Moderators IIYAMA Posted January 16, 2014 Moderators Posted January 16, 2014 Should be: if ZombieKills < 30 then-- till 29 ZombieKills = ZombieKills+1 else --30 or higher = reset. ZombieKills = 0 teste() end
Moderators IIYAMA Posted January 18, 2014 Moderators Posted January 18, 2014 ... addEvent ( "onZombieWasted", true )
Chaos Posted January 18, 2014 Author Posted January 18, 2014 IIYAMA still i already did added that ZombieKills = 0 function teste() for i=1,100 do exports [ "zombiegamemode" ]:createZombie(2132.2060546875+math.random(-4,10),1025.4853515625+math.random(-4,10),10.8203125) end end addEventHandler ( "onResourceStart", getRootElement(), teste ) addEvent ( "onZombieWasted", true ) addEventHandler("onZombieWasted",root, function() if ZombieKills < 30 then-- till 29 ZombieKills = ZombieKills+1 else --30 or higher = reset. ZombieKills = 0 teste() end end)
Moderators IIYAMA Posted January 18, 2014 Moderators Posted January 18, 2014 and where are your debug stuff? You don't even know if the event did triggered when a zombie died.
Moderators IIYAMA Posted January 18, 2014 Moderators Posted January 18, 2014 and the variables are correct? During the proces
Chaos Posted January 18, 2014 Author Posted January 18, 2014 and the variables are correct? During the proces yes
Moderators IIYAMA Posted January 19, 2014 Moderators Posted January 19, 2014 Then why are you saying it doesn't work..... when it does work..... When the zombies spawn some of them will end up in buildings etc. and will fall in to ground. So there will never be 50 at the same Area Also: addEventHandler ( "onResourceStart", getRootElement(), teste ) Should be: addEventHandler ( "onResourceStart", resourceRoot, teste ) Else with every resource that starts, there will be more zombies.
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