English Random T player in every round

9 replies
Goto Page
To the start Previous 1 Next To the start
Up
kralzaza_3
User
Offline Off
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?
31.12.12 03:35:29 pm
Up
Code:
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.
31.12.12 03:40:30 pm
Up
orkin2913
User
Offline Off
Code:
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
31.12.12 04:01:02 pm
Up
Suprise
BANNED
Offline Off
user Obviously Exactly Myself has written:
Code:
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
31.12.12 04:21:21 pm
Up
kralzaza_3
User
Offline Off
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.
31.12.12 04:55:40 pm
Up
Suprise
BANNED
Offline Off
Code:
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


(?)
31.12.12 05:49:12 pm
Up
Cure Pikachu
User
Offline Off
@user Suprise: Yours will fail at some point. Better:
Code:
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
IMG:https://i.imgur.com/uUrye71.png
IMG:https://i.imgur.com/xpsyQRX.png
31.12.12 05:54:25 pm
Up
Kevanya3
User
Offline Off
I think so...
now it's here 5 BROTERS
31.12.12 08:21:57 pm
Up
kralzaza_3
User
Offline Off
user Cure Pikachu has written:
@user Suprise: Yours will fail at some point. Better:
Code:
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