Forum

> > CS2D > Scripts > Spawn NPC like in rp_amstria C4 server
Forums overviewCS2D overview Scripts overviewLog in to reply

English Spawn NPC like in rp_amstria C4 server

23 replies
Page
To the start Previous 1 2 Next To the start

old Spawn NPC like in rp_amstria C4 server

-DIE Wolf-
User Off Offline

Quote
Hey all. I need LUA scripts that :
-Spawn NPC Zombie every X second.
-In random area like rp_amstria in C4 server : Zombie Spawn Randomly but always in the beach

Sorry im bad English.

old Re: Spawn NPC like in rp_amstria C4 server

MikuAuahDark
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
X = 5	-- spawn NPC every 5 seconds. Change it if necessary
spawns={
	{{1,5},{5,10}},	-- Example spawn location, not on pixels but on tiles, separated by comma. {{Start_X,Start_Y},{End_X},{End_Y}},
}

function doSpawnNPC()
	local num,x,y
	num=math.random(1,#spawns)
	x=math.random(spawns[num][1][1],spawns[num][2][1])
	y=math.random(spawns[num][1][2],spawns[num][2][2])
	parse("spawnnpc 1 "..x.." "..y)
end

timer(X*1000,"doSpawnNPC","",-1)
edited 1×, last 28.01.14 06:49:30 am

old Re: Spawn NPC like in rp_amstria C4 server

Dousea
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
table = {
	time = 10000;
	pos = { 2; {10, 20}; {20, 30}; };
}

timer(table.time, [[doSpawnNPC]])
function doSpawnNPC()
	local random, rotation = math.random(1, table.pos[1]), math.random(1, 360)
	local x, y = table.pos[2][random], table.pos[3][random]
	parse([[spawnnpc 1 ]]..x..[[ ]]..y..[[ ]]..rotation)
end

I am not really sure about this script because I did not test it yet after I created this but I think it works. Remember, table.time (10000) is using milliseconds, not seconds. table.pos[1] (2) is the count of x or y coordinates, example:
{10, 20} that means 2 value in x or y table. table.pos[2] ({10, 20}) as x coordinates and table.pos[3] ({20, 30}) as y coordinates.

old Re: Spawn NPC like in rp_amstria C4 server

MikuAuahDark
User Off Offline

Quote
Replace this function with existing function

1
2
3
4
5
6
7
8
9
function doSpawnNPC()
	local num,x,y=0,0,0
	while tile(x,y,"frame")~=6 do	-- I hope that coordinates 0|0 on map is NOT sand tile
		num=math.random(1,#spawns)
		x=math.random(spawns[num][1][1],spawns[num][2][1])
		y=math.random(spawns[num][1][2],spawns[num][2][2])
	end
	parse("spawnnpc 1 "..x.." "..y)
end

old Re: Spawn NPC like in rp_amstria C4 server

MikuAuahDark
User Off Offline

Quote
Make sure that:
> Sand tile frame is 6(CS2D can't know if tile with frame 6 is sand)
> There many sand tile(tile frame 6) at there

It use loop-search system. So if the criteria doesn't match, it search new position again and check the criteria again. If it always found no criteria, then your game hangs

old Re: Spawn NPC like in rp_amstria C4 server

-DIE Wolf-
User Off Offline

Quote
I did change coordinates 0|0 to grass. And my map have big sand tile.
But look like they just respawn close coordinates 0|0 . About from 0|0 to 10|10 area. But my map is bigger. What happend ?

old Re: Spawn NPC like in rp_amstria C4 server

ShouldBeNew
BANNED Off Offline

Quote
You don't need a script to do this. All you have to do in the map editor is this:

Create Delay and then properties:
Delay (delays: 5)
Trigger: (name of creature) but the zombie must have a name.

EDIT: Sorry i wasn't paying attention to the you'r new comment. Ughhh please trash my comment.

old Re: Spawn NPC like in rp_amstria C4 server

Dousea
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
table = {
     time = 10000;
     pos = { {10, 20}; {20, 30}; };
}

timer(table.time, [[doSpawnNPC]])
function doSpawnNPC()
	 local x, y, rotation = math.random(table.pos[1][1], table.pos[1][2]), math.random(table.pos[2][1], table.pos[2][2]), math.random(1, 360)
	 if tile(x, y, [[frame]]) == 6 then parse([[spawnnpc 1 ]]..x..[[ ]]..y..[[ ]]..rotation) end
end

old Re: Spawn NPC like in rp_amstria C4 server

ReVoltage
User Off Offline

Quote
@user sheeL: Lol what is your code?
He want a script to spawn zombie, and u post a completly different codes lol.
@user -DIE Wolf-: Im using this function too, spawning zombie in an area but random x|y.
Like this:
1
2
3
4
5
6
7
8
9
10
function SpawnZombie()
local x=math.random(0,40)
local y=math.random(59,99)
local rot=math.random(0,360)
if tile(x,y,"walkable")==true then
parse("spawnnpc "..(1).." "..x.." "..y.." "..rot)
else
SpawnZombie()
end
end
user MikuAuahDark's code are more simple (and have more darkness) than my messed up code.

old Re: Spawn NPC like in rp_amstria C4 server

Dousea
User Off Offline

Quote
What about now?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
table = {
	time = 10000;
	pos = { {10, 20}; {20, 30}; };
}

function spawnTimer()
	timer(table.time, [[spawnNPC]])
end

spawnTimer()
function spawnNPC()
	local x, y, rotation = math.random(table.pos[1][1], table.pos[1][2]), math.random(table.pos[2][1], table.pos[2][2]), math.random(0, 360)
	if tile(x, y, [[frame]]) == 6 then parse([[spawnnpc 1 ]]..x..[[ ]]..y..[[ ]]..rotation) end
	spawnTimer()
end

old Re: Spawn NPC like in rp_amstria C4 server

-DIE Wolf-
User Off Offline

Quote
Yeah ! Thank user Dousea . It work ! Thank you so much
Last litter question : Can you add spawn limit for them ? Like it just spawn 10 NPC then stop. And if u kill some of them, it will spawn again until 10 NPC then stop.
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview