English Spawn function

9 replies
Goto Page
To the start Previous 1 Next To the start
30.04.18 10:45:11 pm
Up
Quattro
User
Offline Off
Could someone help with this script?

Code:
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?
30.04.18 10:55:54 pm
Up
Cure Pikachu
User
Offline Off
Something like this I guess:
Code:
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
IMG:https://i.imgur.com/uUrye71.png
IMG:https://i.imgur.com/xpsyQRX.png
30.04.18 10:59:49 pm
Up
LoaderFRA
User
Offline Off
You need spawnplayer and setpos
30.04.18 11:17:46 pm
Up
Quattro
User
Offline Off
user Cure Pikachu has written:

LUA ERROR: maps/dm_quake.lua:238: bad argument #1 to 'player' (number expected, got string)
30.04.18 11:20:04 pm
Up
DC
Admin
Offline Off
cs2d lua cmd timer parameter is always a string. If you're already passing the player ID in correctly make sure to cast it:
Code:
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.
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
30.04.18 11:23:33 pm
Up
Quattro
User
Offline Off
@user DC:
It now gives another

Code:
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!
30.04.18 11:25:09 pm
Up
DC
Admin
Offline Off
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.
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
30.04.18 11:31:03 pm
Up
Quattro
User
Offline Off
@user DC:
Passing the id did the trick!
Also it spawns player in one of the starting positions.

Thank you!
30.04.18 11:35:28 pm
Up
DC
Admin
Offline Off
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.
www.UnrealSoftware.de | www.CS2D.com | www.CarnageContest.com | Use the forum & avoid PMs!
30.04.18 11:39:32 pm
Up
Quattro
User
Offline Off
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