Forum

> > CS2D > Scripts > Random T player in every round
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Random T player in every round

9 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Random T player in every round

kralzaza_3
User Off Offline

Zitieren
Hello, its me again.

I have a deathrun server and i'm trying make it more special.

First, all players will be CT. Terrorist team is not available.
Every roundstart, a random CT player will be Terrorist.

How can i select a random CT player to change his team to T?

alt Re: Random T player in every round

Obviously Exactly Myself
User Off Offline

Zitieren
1
2
3
4
5
6
7
addhook("roundstart","happynewyear")
function happynewyear()
	for lol=1,32 do
		parse("makect "..lol)
	end
	parse("maket "..math.random(1,32))
end
Untested.
I haven't been scripting for CS2D for so long, don't know if this is correct.

alt Re: Random T player in every round

orkin2913
User Off Offline

Zitieren
1
2
3
4
5
6
7
8
9
10
11
addhook("startround_prespawn","start")
function start()
	for i=1,#player(0,"table") do
		parse("makect "..i)
		max_players = #player(0,"table")
		random_player = math.random(1,max_players)
			if player(random_player,'exists') then
				parse("maket "..random_player)
			end
	end
end
1× editiert, zuletzt 31.12.12 15:50:37

alt Re: Random T player in every round

Suprise
BANNED Off Offline

Zitieren
user Obviously Exactly Myself hat geschrieben
1
2
3
4
5
6
7
addhook("roundstart","happynewyear")
function happynewyear()
	for lol=1,32 do
		parse("makect "..lol)
	end
	parse("maket "..math.random(1,32))
end
Untested.
I haven't been scripting for CS2D for so long, don't know if this is correct.


There is no roundstart hook

alt Re: Random T player in every round

kralzaza_3
User Off Offline

Zitieren
Thank you for your helps guys but somethings wrong in this code i think.

I'm trying this code with bots. I make them CT, and turned off teambalance.

When i start, 5 players joins to T team and ofcourse, CT is win. I don't know whats happening really out there but its doesnt seems correct.

Can we try make it on round end? Every round ending, current T player will join to CT, and a random player will join to T.

alt Re: Random T player in every round

Suprise
BANNED Off Offline

Zitieren
1
2
3
4
5
6
7
8
9
addhook("endround","_end")
function _end(mode)
local random = math.random(1,#player(0,'team2living'))
local team1 = player(0,'team1')
	for _,id in pairs(team1) do
		parse('makect '..id)
	end
	parse('maket '..random)
end

(?)

alt Re: Random T player in every round

Cure Pikachu
User Off Offline

Zitieren
@user Suprise: Yours will fail at some point. Better:
1
2
3
4
5
6
7
8
9
addhook("endround","rng")
function rng()
	for _, id in ipairs(player(0,"team1")) do
		parse("makect "..id)
	end
	local team2 = player(0,"team2")
	local c = math.random(1,#team2)
	parse("maket "..team2[c])
end
1× editiert, zuletzt 31.12.12 18:04:19

alt Re: Random T player in every round

kralzaza_3
User Off Offline

Zitieren
user Cure Pikachu hat geschrieben
@user Suprise: Yours will fail at some point. Better:
1
2
3
4
5
6
7
8
9
addhook("endround","rng")
function rng()
	for _, id in ipairs(player(0,"team1")) do
		parse("makect "..id)
	end
	local team2 = player(0,"team2")
	local c = math.random(1,#team2)
	parse("maket "..team2[c])
end


Its give error sometimes. A CT transfering to T, end of the round, another player is transfering T to, and other round, 2 more players transfering to. But not everytime, sometimes and in some cases. It says

"LUA ERROR: sys/lua/autorun/randomt.lua:7: bad argument #2 to 'random' (interval is empty)"

4-5 times.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht