Forum

> > CS2D > Scripts > Force specator to spawn
Forums overviewCS2D overview Scripts overviewLog in to reply

English Force specator to spawn

4 replies
To the start Previous 1 Next To the start

old Force specator to spawn

Promaster
User Off Offline

Quote
I know this might be an stupid question but i whatever...

How can i make a script that force a spectator to spawn in the server by Lua code?

Like first, setplayers team = Random(1,2)
Then spawn the player...

old Re: Force specator to spawn

Zeik
User Off Offline

Quote
1
2
3
4
5
6
7
8
addhook("join","onJoin")
function onJoin(id)
	if (math.random(0,2) >= 1)
		parse('maket '..id)
	else
		parse('makect '..id)
	end
end

old Re: Force specator to spawn

Nekomata
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
addhook("join", "_join")
function _join(id)
	-- forceRandomTeamRespawn when they join the server
	forceRandomTeamRespawn(id)
end

addhook("team", "teamselect")
function teamselect(id, team)
	if team == 0 then -- if they join spec, forceRandomTeamRespawn then
		forceRandomTeamRespawn(id)
	end
end

function forceRandomTeamRespawn(id)
	-- have them join a random team
	local team = math.random(1,2)
	if team == 1 then
		parse('maket '..id)
	else
		parse('makect '..id)
	end
	-- spawn them
	parse('spawnplayer '..id)
end
edited 1×, last 07.06.16 05:24:39 am

old Re: Force specator to spawn

Zeik
User Off Offline

Quote
@user Nekomata:'s answer is better because he contemplates the case when the player joins spectator after joining the game. Also, I thought math.random(a,b) returned a real number between a and b (I misread the documentation).
edited 1×, last 07.06.16 06:52:50 am
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview