• Problem: How do I spawn a NPC where I can choose the pos?
    28 replies, posted
Hi, I am trying to make a Zombiesurvaval game, and a big problem is how can make the server spawn a zombie each 10 seconds at a position I can define in my code.
[lua]timer.Create( 10, 0, function() --Code here end)[/lua] You could also create a table of co-ordinates as spawn locations, just go to the palces you want as spawn positions and theres a command which gives you your exact co-ordinates, forgot it though, and then put them in a table. And call it in the function with table.random(tablename) [editline]08:27PM[/editline] Or if you want a seperate spawn position you could use [lua]local spawnpos = "positionhere"[/lua]
[QUOTE=HeavyMtl123;22067207][lua]timer.Create( 10, 0, function() --Code here end)[/lua] You could also create a table of co-ordinates as spawn locations, just go to the palces you want as spawn positions and theres a command which gives you your exact co-ordinates, forgot it though, and then put them in a table. And call it in the function with table.random(tablename) [editline]08:27PM[/editline] Or if you want a seperate spawn position you could use [lua]local spawnpos = "positionhere"[/lua][/QUOTE] I could do so. If I knew how to spawn an npc...
[lua] timer.Create("SpawnZombie", 10, 0, function() local Zombie = ents.Create("npc_zombie") Zombie:SetPos(Vector(X,Y,Z)) Zombie:Spawn() end) [/lua] X Y and Z is the Positions, Example: Vector(-2000,1300,20)
you can also use something like this to spawn your npc when the map start[lua]hook.Add( "InitPostEntity", "Createspawpoint", function() local NpC=ents.Create("npc_gman") NpC:SetPos(Vector(-4771, 1497, -383)) NpC:Spawn() end)[/lua]
Ok. Thanks a lot. But is there any way to find out where I am standing so I can spawn a zombie there. (msg my current pos for example) And make a table with some different locations?
[lua] concommand.Add("ZombieSpawnPos", function( ply ) local POS = ply:GetPos() timer.Create("SpawnZombie", 10, 0, function() local Zombie = ents.Create("npc_zombie") Zombie:SetPos(POS) Zombie:Spawn() end) end) [/lua] This would make so when you enter the command: "ZombieSpawnPos", it will create a timer there of 10 seconds that spawns zombies there.
Ok. So if I want to find my pos I can use Msg((ply:GetPos())) ? Or do I have to define ply first? In case how to?
[QUOTE=userman122;22067668]Ok. So if I want to find my pos I can use Msg((ply:GetPos())) ? Or do I have to define ply first? In case how to?[/QUOTE] If you want to find out your position, you could create a command for it. [lua] concommand.Add("GetMyPos", function( ply ) local Pos = ply:GetPos() Msg("Vector("..Pos.x..","..Pos.y..","..Pos.z..")") end) [/lua] That would print your position.
Nice! One step closer my gamemode! Ticker owns! (I found out there was a new post in my thread with it)
Or just type getpos in the console?
Lol! Ill do it now and make a table fr different positions.
But where to put the code? Server or client?
[QUOTE=userman122;22079647]But where to put the code? Server or client?[/QUOTE] Server as it is the server spawning the zombies.
Ok. Thanks.
[QUOTE=Dragge;22067448][lua] timer.Create("SpawnZombie", 10, 0, function() local Zombie = ents.Create("npc_zombie") Zombie:SetPos(Vector(X,Y,Z)) Zombie:Spawn() end) [/lua] X Y and Z is the Positions, Example: Vector(-2000,1300,20)[/QUOTE] Dude, this does not work... The gamemode dont load when I start the game. [editline]03:59PM[/editline] OK. This time I put the code in shared.lua, but stil doesent work. Error: Can't find factory for entity: npc_zombie Timer Error: zombiekiller\gamemode\shared.lua:23: Tried to use a NULL entity! Can't find factory for entity: npc_zombie Timer Error: zombiekiller\gamemode\shared.lua:23: Tried to use a NULL entity! [editline]04:02PM[/editline] This code did I use: [lua] timer.Create("SpawnZombie", 10, 0, function() local Zombie = ents.Create("npc_zombie") Zombie:SetPos(Vector(3817.039795, -1362.936646, -79.968750)) Zombie:Spawn() end) [/lua] [editline]04:27PM[/editline] Problem fixed!!!!
Hey! Something weird is happening! When the server spawns a zombie, it does not"see" me (it does not follow me) unless I move very close to it, or attack it. Sometimes, they move away from me!!!
Because it's an NPC. Make a Scripted NPC. (Tutorial at Wiki)
But when you spawn one manually in sandbox, they see me, even if I dont attack it. [editline]12:21PM[/editline] Just try.
The map may not be noded for npcs.
What...? It was flatgrass so everything should be fine.
[QUOTE=userman122;22105502]What...? It was flatgrass so everything should be fine.[/QUOTE] Flatgrass doesent have any nodes I believe.
Yeah, flatgrass isn't noded. Construct however, is if you want to test there.
OK... But firs of all: What is nodes? [editline]06:18AM[/editline] Ive tried that. However, when my mode is completed I want to make a map to it. So what is nodes?
Nodes are what tells the npc how to move around. Basically it moves from node to node to get around (I'm awful at explaining things btw lol). So if you aren't on a noded map you wont be able to use working npc's.
Ok. How can I create a node then? Any tut?
I think this may help although I'm not too sure. [url]http://developer.valvesoftware.com/wiki/Map_edit#Editing_node_graphs_in-game[/url]
Create a new map with them, don't think you can place one with Lua :3
Yes, of curse. I will create a new map. [editline]09:18AM[/editline] ill test this [url]http://developer.valvesoftware.com/wiki/Map_edit#Editing_node_graphs_in-game[/url]
Sorry, you need to Log In to post a reply to this thread.