• Send all spawned zombies at one person.
    7 replies, posted
Been working at this for a while...with lots of errors - I am not very experienced in Lua so expect some stupid things in my code =) What I am trying to do is send all spawned zombies at one random player every 60 seconds, for testing purposes i lowered it to 20. I am no longer getting errors, but the zombies don't move at all. I had re-noded the map with the nodegraph editor, so im certain it's not because of the map nodes. [lua] for i = 0, math.random( 10, 18 ) do local zombies = #ents.FindByClass( "npc_zombie" ) local fzombies = #ents.FindByClass( "npc_poisonzombie" ) if ( zombies + fzombies > 18 ) then break end local pos = Vector( math.random( -6000, 6000 ), math.random( -6000, 6000 ), 1800 ) local tr = util.TraceLine( { start = pos, endpos = pos - Vector( 0, 0, 9999 ) } ) if ( tr.HitWorld ) then timer.Destroy( "SendZombies" ) local class = "npc_zombie" if ( math.random( 0, 100 ) < 25 ) then class = "npc_poisonzombie" end local zombie = ents.Create( class ) zombie:SetPos( tr.HitPos + Vector( 0, 0, 64 ) ) zombie:SetHealth( 128 ) zombie:SetNWString( "Owner", "World" ) zombie:SetKeyValue( "spawnflags", "1280" ) zombie:SetKeyValue( "squadname", "zombie" ) zombie:Spawn() zombie:Fire( "Wake" ) zombie:Activate() table.insert( Zombies, zombie ) local ourEnemy = player.GetByID( math.random( 1, #player.GetAll() ) ) if ( IsValid( ourEnemy ) ) then zombie:SetEnemy( ourEnemy ) zombie:SetLastPosition( ourEnemy:GetPos() ) zombie:SetSchedule( SCHED_FORCED_GO ) end end end end end ) timer.Create( "SendZombies", 20, 0, function() ZombieAttack() end ) end [/lua] [lua] function ZombieAttack() if( ( #ents.FindByClass( "npc_zombie" ) ) + ( #ents.FindByClass( "npc_poisonzombie" ) ) > 0 ) then local ourEnemy = player.GetByID( math.random( 1, #player.GetAll() ) ) PrintMessage( HUD_PRINTTALK, "The zombies are targeting " .. ourEnemy:Nick() .. "!" ) if ( IsValid( ourEnemy ) ) then for k, v in pairs ( Zombies ) do v:SetLastPosition( ourEnemy:GetPos() ) v:SetEnemy(ourEnemy) v:UpdateEnemyMemory( ourEnemy, ourEnemy:GetPos() ) v:SetSchedule( SCHED_CHASE_ENEMY ) end else return end end end [/lua] The majority of the zombie spawning script, mostly everything except the timer and a couple values are originated from the Stranded gamemode, not me. Another issue I am having is the timer failing, and ending, if someone is noclipped (the GetPos() breaks i am assuming), any insight into how to fix that as well would be appreciated. [editline]7th November 2013[/editline] Those are just two chunks of the entire script, should have all of the needed variables to explain what is going on. Last question, on the top of the script I just have Zombies = {} there, is that the proper way to set up a table for use in this? Never done it before.
Your best bet would be ent_fire. you would call this by doing (assuming var "zombie" is the npc) the LUA call for ent_fire, which is [code]Entity:Fire( string input, string param, number delay )[/code] now, the input will probably be something like settarget or selecttarget or something; I'm not so sure what the input is and if it even exists, and I'm unable to get to gmod for now but this is probably the most viable solution.
[QUOTE=BFG9000;42785063]Your best bet would be ent_fire. you would call this by doing (assuming var "zombie" is the npc) the LUA call for ent_fire is [code]Entity:Fire( string input, string param, number delay )[/code] now, the input will probably be something like settarget or selecttarget or something; I'm not so sure what the input is and if it even exists, and I'm unable to get to gmod for now but this is probably the most viable solution.[/QUOTE] Alright, I'll try that in the morning, getting tired and it takes too long for it to become nighttime in Stranded (zombies spawn at night).
I should note that in order to discover the ent_fire inputs, you should spawn a zombie, ent_setname it to something like mylittlezombie, then type: [code]ent_fire mylittlezombie [/code] at which point a long list of suggestions will pop up. scroll through the list using the arrow keys until you find anything that looks remotely related to what you're doing.
[QUOTE=BFG9000;42785323]I should note that in order to discover the ent_fire inputs, you should spawn a zombie, ent_setname it to something like mylittlezombie.[/QUOTE] Very Helpful, I had no idea how Fire() worked.
Bumping to see if you were able to find any inputs?
I ended up coding a NextBot zombie =p Much better AI and more customization.
Ah, nice.
Sorry, you need to Log In to post a reply to this thread.