Forum

> > CS2D > Scripts > Spawn NPC like in rp_amstria C4 server
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Spawn NPC like in rp_amstria C4 server

23 Antworten
Seite
Zum Anfang Vorherige 1 2 Nächste Zum Anfang

alt Spawn NPC like in rp_amstria C4 server

-DIE Wolf-
User Off Offline

Zitieren
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.

alt Re: Spawn NPC like in rp_amstria C4 server

MikuAuahDark
User Off Offline

Zitieren
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)
1× editiert, zuletzt 28.01.14 06:49:30

alt Re: Spawn NPC like in rp_amstria C4 server

Dousea
User Off Offline

Zitieren
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.

alt Re: Spawn NPC like in rp_amstria C4 server

MikuAuahDark
User Off Offline

Zitieren
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

alt Re: Spawn NPC like in rp_amstria C4 server

MikuAuahDark
User Off Offline

Zitieren
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

alt Re: Spawn NPC like in rp_amstria C4 server

-DIE Wolf-
User Off Offline

Zitieren
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 ?

alt Re: Spawn NPC like in rp_amstria C4 server

ShouldBeNew
BANNED Off Offline

Zitieren
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.

alt Re: Spawn NPC like in rp_amstria C4 server

Dousea
User Off Offline

Zitieren
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

alt Re: Spawn NPC like in rp_amstria C4 server

ReVoltage
User Off Offline

Zitieren
@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.

alt Re: Spawn NPC like in rp_amstria C4 server

Dousea
User Off Offline

Zitieren
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
Zum Anfang Vorherige 1 2 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht