Alright what I am trying to do is make it so zombies will spawn in spots given every 10 seconds
local function CreateZombie(npc)
local npc = ents.Create("nx_zombie")
npc:SetPos(Vector(table.Random(mytable)))
npc:Spawn()
end
timer.Create( "Zombietimer", 10, 0, CreateZombie, npc)
myTable={}
myTable[1]="433.200470,-657.511597,320.031250;"
myTable[2]="-200.917343,-1239.716431,312.031250"
myTable[3]="4022.880371,646.364136,320.031250;"
myTable[4]="3799.210693,1839.861328,312.031250"
myTable[5]="396.321228,-1197.222412,320.031250;"
you need to hook your timer to [B][URL="http://wiki.garrysmod.com/?title=Gamemode.InitPostEntity"]Gamemode.InitPostEntity [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG][/URL][/B]
and you should remove the " ; " in your table.
[lua]timer.Create( "Zombietimer", 10, 0, function()
local npc = ents.Create("nx_zombie")
npc:SetPos(Vector(table.Random(mytable)))
npc:Spawn()
end )
myTable = {
"433.200470,-657.511597,320.031250",
"-200.917343,-1239.716431,312.031250",
"4022.880371,646.364136,320.031250",
"3799.210693,1839.861328,312.031250",
"396.321228,-1197.222412,320.031250"
}[/lua]
Untested, but should work.
Is nx_zombie a custom NPC?
in yours lucky it just has function which is confusing me.
For a timer, you don't need to name a function, it just works like that.
Also, you only do
[lua]myTable={}
myTable[1]="433.200470,-657.511597,320.031250;"
myTable[2]="-200.917343,-1239.716431,312.031250"
myTable[3]="4022.880371,646.364136,320.031250;"
myTable[4]="3799.210693,1839.861328,312.031250"
myTable[5]="396.321228,-1197.222412,320.031250;" [/lua]
If you want to concatenate all of it, only basic use I can think of.
[QUOTE=LuckyLuke;22565844]For a timer, you don't need to name a function, it just works like that.
Also, you only do
[lua]myTable={}
myTable[1]="433.200470,-657.511597,320.031250;"
myTable[2]="-200.917343,-1239.716431,312.031250"
myTable[3]="4022.880371,646.364136,320.031250;"
myTable[4]="3799.210693,1839.861328,312.031250"
myTable[5]="396.321228,-1197.222412,320.031250;" [/lua]
If you want to concatenate all of it, only basic use I can think of.[/QUOTE]
That's a table of strings, not vectors.
[lua]myTable={}
myTable[1]= Vector(433.200470,-657.511597,320.031250)
myTable[2]= Vector(-200.917343,-1239.716431,312.031250)
myTable[3]= Vector(4022.880371,646.364136,320.031250)
myTable[4]= Vector(3799.210693,1839.861328,312.031250)
myTable[5]= Vector(396.321228,-1197.222412,320.031250)[/lua]
so how would i go about incorporating the vector statement into lucky's code
[editline]12:11AM[/editline]
Would this work
local function CreateZombie(npc)
local npc = ents.Create("nx_zombie")
npc:SetPos((table.Random(mytable)))
npc:Spawn()
end
timer.Create( "Zombietimer", 10, 0, CreateZombie, npc)
myTable={}
myTable[1]= Vector(433.200470,-657.511597,320.031250)
myTable[2]= Vector(-200.917343,-1239.716431,312.031250)
myTable[3]= Vector(4022.880371,646.364136,320.031250)
myTable[4]= Vector(3799.210693,1839.861328,312.031250)
myTable[5]= Vector(396.321228,-1197.222412,320.031250)
Yes, yes it would.
I'm not giving up what the hell is wrong with this i tried the last script and it didn't work
why won't this one work
AddCSLuaFile( "Zombiespawner.lua" )
timer.Create( "NPCSpawnTimer", 15, 0 function()
local ents = ent.Create("nx_zombie")
ents:SetPos(Vector(table.Random(myTable)))
ent:Spawn()
end
myTable = {
"433.200470,-657.511597,320.031250",
"-200.917343,-1239.716431,312.031250",
"4022.880371,646.364136,320.031250",
"3799.210693,1839.861328,312.031250",
"396.321228,-1197.222412,320.031250"}
Because your myTable contains single strings, not 3 number seperated by commas.
Just use vectors in the table.
You forgot a comma between 0 and function. You should be getting errors, if they don't help you post them here. Also why do you need to AddCSLuaFile that file? It's serverside.
Thats the thing thats weird no errors are coming up. This is my code now
timer.Create( "NPCSpawnTimer", 15, 0, function()
local ents = ent.Create("nx_zombie")
ents:SetPos(Vector(table.Random(myTable)))
ent:Spawn()
end
myTable={}
myTable[1]= Vector(433.200470,-657.511597,320.031250)
myTable[2]= Vector(-200.917343,-1239.716431,312.031250)
myTable[3]= Vector(4022.880371,646.364136,320.031250)
myTable[4]= Vector(3799.210693,1839.861328,312.031250)
myTable[5]= Vector(396.321228,-1197.222412,320.031250)
" ... ents:S ... "
[code]
myTable={}
myTable[1]= Vector(433.200470,-657.511597,320.031250)
myTable[2]= Vector(-200.917343,-1239.716431,312.031250)
myTable[3]= Vector(4022.880371,646.364136,320.031250)
myTable[4]= Vector(3799.210693,1839.861328,312.031250)
myTable[5]= Vector(396.321228,-1197.222412,320.031250)
timer.Create( "NPCSpawnTimer", 15, 0, function()
local ent = ents.Create("nx_zombie")
ent:SetPos(Vector(table.Random(myTable)))
ent:Spawn()
end)[/code]
Are you sure its loading propperly, becuse your code should give an error. this one is fixed
[editline]10:29AM[/editline]
1000 Posts! :toot:
[QUOTE=Tobba;22598992][code]
myTable={}
myTable[1]= Vector(433.200470,-657.511597,320.031250)
myTable[2]= Vector(-200.917343,-1239.716431,312.031250)
myTable[3]= Vector(4022.880371,646.364136,320.031250)
myTable[4]= Vector(3799.210693,1839.861328,312.031250)
myTable[5]= Vector(396.321228,-1197.222412,320.031250)
timer.Create( "NPCSpawnTimer", 15, 0, function()
local ent = ents.Create("nx_zombie")
ent:SetPos(Vector(table.Random(myTable)))
ent:Spawn()
end)[/code]
Are you sure its loading propperly, becuse your code should give an error. this one is fixed
[editline]10:29AM[/editline]
1000 Posts! :toot:[/QUOTE]
That should work.
Also, halfway there mate :toot:
The reason the other one probably wasn't working is because you were setting the table after the function so it returned nil. That is my guess anyway.
Alright my code now and still no result.
myTable={}
myTable[1]= Vector(433.200470,-657.511597,320.031250)
myTable[2]= Vector(-200.917343,-1239.716431,312.031250)
myTable[3]= Vector(4022.880371,646.364136,320.031250)
myTable[4]= Vector(3799.210693,1839.861328,312.031250)
myTable[5]= Vector(396.321228,-1197.222412,320.031250)
timer.Create( "NPCSpawnTimer", 15, 0, function()
local ent = ents.Create("nx_zombie")
ent:SetPos(Vector(table.Random(myTable)))
ent:Spawn()
end)
I put it in Lua/autorun/server and I tried Lua/autorun
Would it be this ent:SetPos(table.Random(myTable))
Since vector is already established in the table
Yes, yes it would.
Lol it works only problem now is for some reason the snpc is spawning as an error........
This is ridiculous lol
[editline]11:44PM[/editline]
Nevermind its working. I will try setting up a max amount of the entity spawned at a time on my own
Ok yeah im going to ask how would i make it so only 30 zombies can be on the map at a time and keep the script running?
Sorry, you need to Log In to post a reply to this thread.