KiffShark Posted November 17, 2012 Share Posted November 17, 2012 Well.. Hi again everybody I'd like to know if there is something like this "if (time >= 00:00) and (time < 09:00)" (I guess this is 100% wrong but it's an example..) I want to add this in spawn of zombies, I want them only in the night... There is something I can do? Thanks you all! Link to comment
KiffShark Posted November 17, 2012 Author Share Posted November 17, 2012 This is what I've tried.. but now zombies not spawn in any hour What do you think? (I'm noob) my lines: 4,5,6,62,63 --SPAWNS ZOMBIES RANDOMLY NEAR PLAYERS function SpawnZombie () local pacecount = 0 local time = getRealTime() -- ADDED BY ME local hours = time.hour -- ADDED BY ME If ( hours > 00 ) and ( hours < 07 ) then -- ADDED BY ME while pacecount < 5 do --4 ZOMBIES AT A TIME TO PREVENT FPS DROP if (table.getn( everyZombie )+pacecount < newZombieLimit ) and (ZombieStreaming == 1) then local xcoord = 0 local ycoord = 0 local xdirection = math.random(1,2) if xdirection == 1 then xcoord = math.random(15,40) else xcoord = math.random(-40,-15) end local ydirection = math.random(1,2) if ydirection == 1 then ycoord = math.random(15,40) else ycoord = math.random(-40,-15) end local liveplayers = getAlivePlayers () if (table.getn( liveplayers ) > 0 ) then local lowestcount = 99999 local lowestguy = nil for PKey,thePlayer in ipairs(liveplayers) do if isElement(thePlayer) then if (getElementData (thePlayer, "dangercount")) and (getElementData(thePlayer, "zombieProof") ~= true) and (getElementData(thePlayer, "alreadyspawned" ) == true) then if (getElementData (thePlayer, "dangercount") < lowestcount) then local safezone = 0 local gx, gy, gz = getElementPosition( thePlayer ) 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 lowestguy = thePlayer lowestcount = getElementData (thePlayer, "dangercount") end end end end end pacecount = pacecount+1 if isElement(lowestguy) then triggerClientEvent ( "Spawn_Placement", lowestguy, ycoord, xcoord ) else pacecount = pacecount+1 end else pacecount = pacecount+1 end else pacecount = pacecount+1 end end else -- ADDED BY ME end -- ADDED BY ME end And another question, how can I paste the code with color in functions? Link to comment
AhmadQTR Posted November 17, 2012 Share Posted November 17, 2012 This is what I've tried.. but now zombies not spawn in any hour What do you think? (I'm noob) my lines: 4,5,6,62,63 --SPAWNS ZOMBIES RANDOMLY NEAR PLAYERS function SpawnZombie () local pacecount = 0 local time = getRealTime() -- ADDED BY ME local hours = time.hour -- ADDED BY ME If ( hours > 00 ) and ( hours < 07 ) then -- ADDED BY ME while pacecount < 5 do --4 ZOMBIES AT A TIME TO PREVENT FPS DROP if (table.getn( everyZombie )+pacecount < newZombieLimit ) and (ZombieStreaming == 1) then local xcoord = 0 local ycoord = 0 local xdirection = math.random(1,2) if xdirection == 1 then xcoord = math.random(15,40) else xcoord = math.random(-40,-15) end local ydirection = math.random(1,2) if ydirection == 1 then ycoord = math.random(15,40) else ycoord = math.random(-40,-15) end local liveplayers = getAlivePlayers () if (table.getn( liveplayers ) > 0 ) then local lowestcount = 99999 local lowestguy = nil for PKey,thePlayer in ipairs(liveplayers) do if isElement(thePlayer) then if (getElementData (thePlayer, "dangercount")) and (getElementData(thePlayer, "zombieProof") ~= true) and (getElementData(thePlayer, "alreadyspawned" ) == true) then if (getElementData (thePlayer, "dangercount") < lowestcount) then local safezone = 0 local gx, gy, gz = getElementPosition( thePlayer ) 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 lowestguy = thePlayer lowestcount = getElementData (thePlayer, "dangercount") end end end end end pacecount = pacecount+1 if isElement(lowestguy) then triggerClientEvent ( "Spawn_Placement", lowestguy, ycoord, xcoord ) else pacecount = pacecount+1 end else pacecount = pacecount+1 end else pacecount = pacecount+1 end end else -- ADDED BY ME end -- ADDED BY ME end And another question, how can I paste the code with color in functions? use [lua] [ /lua] tags to 'paste the code with color in functions' Link to comment
AhmadQTR Posted November 17, 2012 Share Posted November 17, 2012 Sorry for double post ^ try this function SpawnZombie () local pacecount = 0 local time = getRealTime() -- ADDED BY ME local hours = time.hour -- ADDED BY ME if ( hours > 00 ) and ( hours < 07 ) then -- ADDED BY ME while pacecount < 5 do --4 ZOMBIES AT A TIME TO PREVENT FPS DROP if (table.getn( everyZombie )+pacecount < newZombieLimit ) and (ZombieStreaming == 1) then local xcoord = 0 local ycoord = 0 local xdirection = math.random(1,2) if xdirection == 1 then xcoord = math.random(15,40) else xcoord = math.random(-40,-15) end local ydirection = math.random(1,2) if ydirection == 1 then ycoord = math.random(15,40) else ycoord = math.random(-40,-15) end local liveplayers = getAlivePlayers () if (table.getn( liveplayers ) > 0 ) then local lowestcount = 99999 local lowestguy = nil for PKey,thePlayer in ipairs(liveplayers) do if isElement(thePlayer) then if (getElementData (thePlayer, "dangercount")) and (getElementData(thePlayer, "zombieProof") ~= true) and (getElementData(thePlayer, "alreadyspawned" ) == true) then if (getElementData (thePlayer, "dangercount") < lowestcount) then local safezone = 0 local gx, gy, gz = getElementPosition( thePlayer ) 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 lowestguy = thePlayer lowestcount = getElementData (thePlayer, "dangercount") end end end end end pacecount = pacecount+1 if isElement(lowestguy) then triggerClientEvent ( "Spawn_Placement", lowestguy, ycoord, xcoord ) else pacecount = pacecount+1 end else pacecount = pacecount+1 end else pacecount = pacecount+1 end end end end Link to comment
KiffShark Posted November 19, 2012 Author Share Posted November 19, 2012 doesn't work if it is eaier may be time of game, it'd be nice too... then, to do it with realtime I could put a sync resource and it'd works = nop? Link to comment
myonlake Posted November 19, 2012 Share Posted November 19, 2012 (edited) You don't know what you're doing if you're doing it that way. getRealTime() fetches the server's time. If you really want that, then okay, I have included two types of code below. In real life time: Server-side function SpawnZombie() local pacecount = 0 local time = getRealTime() if (time.hour > 0) and (time.hour < 7) then while pacecount < 5 do if (table.getn(everyZombie)+pacecount < newZombieLimit) and (ZombieStreaming == 1) then local xcoord = 0 local xdirection = math.random(1,2) if xdirection == 1 then xcoord = math.random(15,40) else xcoord = math.random(-40,-15) end local ycoord = 0 local ydirection = math.random(1,2) if ydirection == 1 then ycoord = math.random(15,40) else ycoord = math.random(-40,-15) end if (table.getn(getAlivePlayers()) > 0) then local lowestcount = 99999 local lowestguy = nil for PKey,thePlayer in ipairs(getAlivePlayers()) do if isElement(thePlayer) then if (getElementData(thePlayer, "dangercount")) and (getElementData(thePlayer, "zombieProof") ~= true) and (getElementData(thePlayer, "alreadyspawned") == true) then if (getElementData(thePlayer, "dangercount") < lowestcount) then local safezone = 0 local gx, gy, gz = getElementPosition(thePlayer) for theKey,theradar in ipairs(getElementsByType("radararea")) do if getElementData(theradar, "zombieProof") == true then if isInsideRadarArea(theradar, gx, gy) then safezone = 1 end end end if safezone == 0 then lowestguy = thePlayer lowestcount = getElementData(thePlayer, "dangercount") end end end end end pacecount = pacecount+1 if isElement(lowestguy) then triggerClientEvent("Spawn_Placement", lowestguy, ycoord, xcoord) else pacecount = pacecount+1 end else pacecount = pacecount+1 end else pacecount = pacecount+1 end end end end In-game time: Server-side function SpawnZombie() local pacecount = 0 local hour, minute = getTime() if (hour > 0) and (hour < 7) then while pacecount < 5 do if (table.getn(everyZombie)+pacecount < newZombieLimit) and (ZombieStreaming == 1) then local xcoord = 0 local xdirection = math.random(1,2) if xdirection == 1 then xcoord = math.random(15,40) else xcoord = math.random(-40,-15) end local ycoord = 0 local ydirection = math.random(1,2) if ydirection == 1 then ycoord = math.random(15,40) else ycoord = math.random(-40,-15) end if (table.getn(getAlivePlayers()) > 0) then local lowestcount = 99999 local lowestguy = nil for PKey,thePlayer in ipairs(getAlivePlayers()) do if isElement(thePlayer) then if (getElementData(thePlayer, "dangercount")) and (getElementData(thePlayer, "zombieProof") ~= true) and (getElementData(thePlayer, "alreadyspawned") == true) then if (getElementData(thePlayer, "dangercount") < lowestcount) then local safezone = 0 local gx, gy, gz = getElementPosition(thePlayer) for theKey,theradar in ipairs(getElementsByType("radararea")) do if getElementData(theradar, "zombieProof") == true then if isInsideRadarArea(theradar, gx, gy) then safezone = 1 end end end if safezone == 0 then lowestguy = thePlayer lowestcount = getElementData(thePlayer, "dangercount") end end end end end pacecount = pacecount+1 if isElement(lowestguy) then triggerClientEvent("Spawn_Placement", lowestguy, ycoord, xcoord) else pacecount = pacecount+1 end else pacecount = pacecount+1 end else pacecount = pacecount+1 end end end end Edited November 19, 2012 by Guest Link to comment
KiffShark Posted November 19, 2012 Author Share Posted November 19, 2012 zombies don't spawn and console says: Error in: for PKey,thePlayer in ipairs(liveplayers) do (line 26 of the copied script) "Bad argument #1 to 'ipairs' (table expected, got nil)" That's means it doesn't detect alive players? (I was playing and alive in that moment) Link to comment
myonlake Posted November 19, 2012 Share Posted November 19, 2012 Copy my code again, didn't see the second check. 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