Forum

> > CS2D > Scripts > Spawn function
Forums overviewCS2D overview Scripts overviewLog in to reply

English Spawn function

9 replies
To the start Previous 1 Next To the start

old Spawn function

Quattro
GAME BANNED Off Offline

Quote
Could someone help with this script?

1
2
3
4
5
6
7
8
9
addhook("die", "resetkill")

function resetkill()
timer(500,"spawnn")
end

function spawnn(id)
??
end

I want to spawn player by force after he dies in deathmatch. How to spawn him on spawn points as if it was a round restart?

old Re: Spawn function

Cure Pikachu
User Off Offline

Quote
Something like this I guess:
1
2
3
4
function spawnn(id)
	local tx, ty = randomentity(player(id,"team")-1)
	parse("spawnplayer "..id.." "..(tx*32+16).." "..(ty*32+16))
end

old Re: Spawn function

DC
Admin Off Offline

Quote
cs2d lua cmd timer parameter is always a string. If you're already passing the player ID in correctly make sure to cast it:
1
local tx, ty = randomentity(player(tonumber(id),"team")-1)
The type doesn't matter for parse because you're passing a big string there anyway and CS2D does the conversion for you.

old Re: Spawn function

Quattro
GAME BANNED Off Offline

Quote
@user DC:
It now gives another

1
2
3
4
function spawnn(id)
     local tx, ty = randomentity(player(tonumber(id),"team")-1)
     parse('spawnplayer '..id..' '..(tx*32+16)..' '..(ty*32+16))
end

result:
LUA ERROR: maps/dm_quake.lua:237: bad argument #1 to 'player' (number expected, got nil)

237 is the local tx, ty line!

old Re: Spawn function

DC
Admin Off Offline

Quote
Then you're not passing in the player ID. It's also missing in the snippet you provided in the beginning.
timer(500,"spawnn")

That part requires 1 more parameter. See cs2d lua cmd timer
The 3rd parameter needs to be the ID of the player you want to respawn.

old Re: Spawn function

Quattro
GAME BANNED Off Offline

Quote
@user DC:
Passing the id did the trick!
Also it spawns player in one of the starting positions.

Thank you!

old Re: Spawn function

DC
Admin Off Offline

Quote
Yes, what user Cure Pikachu's line does is getting the ID of a random Info_T or Info_CT depending on the team. Since Info_T is entity 0 and Info_CT entity 1, it works by just subtracting 1 from the team value (1 is T and 2 is CT).

Of course you can alter that part and spawn the player wherever you like.

old Re: Spawn function

Quattro
GAME BANNED Off Offline

Quote
Nice explanation, it will be useful in the future. Started learning lua today and it's quite fun
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview