Forum

> > CS2D > Scripts > Random T player in every round
Forums overviewCS2D overview Scripts overviewLog in to reply

English Random T player in every round

9 replies
To the start Previous 1 Next To the start

old Random T player in every round

kralzaza_3
User Off Offline

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

old Re: Random T player in every round

Obviously Exactly Myself
User Off Offline

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

old Re: Random T player in every round

orkin2913
User Off Offline

Quote
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
edited 1×, last 31.12.12 03:50:37 pm

old Re: Random T player in every round

Suprise
BANNED Off Offline

Quote
user Obviously Exactly Myself has written
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

old Re: Random T player in every round

kralzaza_3
User Off Offline

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

old Re: Random T player in every round

Suprise
BANNED Off Offline

Quote
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

(?)

old Re: Random T player in every round

Cure Pikachu
User Off Offline

Quote
@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
edited 1×, last 31.12.12 06:04:19 pm

old Re: Random T player in every round

kralzaza_3
User Off Offline

Quote
user Cure Pikachu has written
@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.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview