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 Re: Spawn NPC like in rp_amstria C4 server

Dousea
User Off Offline

Quote
user -DIE Wolf- has written
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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
table = {
	time = 10000;
	pos = { {10, 20}; {20, 30}; };
	count = 0; limit = 10;
}

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

spawnTimer()
function spawnNPC()
	if table.count ~= table.limit and table.count < table.limit then
		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)
			table.count = table.count + 1
		end
	end
	spawnTimer()
end

addhook([[kill]], [[spawnKill]])
function spawnKill(killer, victim, weapon)
	if weapon >= 248 and weapon <= 249 then
		while table.count > 0 do
			table.count = table.count - 1
		end
	end
end

old Re: Spawn NPC like in rp_amstria C4 server

Dousea
User Off Offline

Quote
user -DIE Wolf- has written
The limit is work. But they just not respawn after i kill. I need kind of it ALWAYS be 10 NPC.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
table = {
	time = 5000;
	pos = { {10, 20}; {20, 30} };
	count = 0; limit = 10;
}

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

spawnTimer()
function spawnNPC()
	if table.count >= 0 and table.count < table.limit then
		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)
			table.count = table.count + 1
		end
	end
	spawnTimer()
end

addhook([[startround]], [[spawnStartRound]])
function spawnStartRound()
	table.count = 0
end

addhook([[objectkill]], [[spawnObjectKill]])
function spawnObjectKill(id)
     if object(id, [[type]]) == 30 then
          table.count = table.count - 1
     end
end
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview