Forum

> > CS2D > Scripts > Random players should get special rank each round
Forums overviewCS2D overview Scripts overviewLog in to reply

English Random players should get special rank each round

7 replies
To the start Previous 1 Next To the start

old Random players should get special rank each round

Ajmin
User Off Offline

Quote
HI once Again.
I decided to make a new Script.
BUT there's a error.
i need a script which will randomly choose player for a special rank.
each team should have 1 player with the special rank.
i made the script but the script dont works correctly.
IT works like this:
it will choose a player randomly among the all the players but not among the team.
But i need among the team,not among all the players.
Like this:
i need each team with 1 player having special rank.

example:
if there are 3 players in ct then 1 among the 3 should get the special rank.
and
if there are 3 players in t then 1 among the 3 should get the special rank.
basically:1 special rank user should be in t and 1 in ct.

the special rank user should equip laser and medic armor (this kind of script is already made,as i told u i made the lua but error)

Here is My Script which i made :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
parse('restart 3')

function getplayers()
	local s={}
	for id=1,32 do
		if player(id,"exists") and player(id,"team")~=0 and player(id,"health")>0 then
			table.insert(s,id)
		end
	end
	return s
end



function iArray(m,v)
     local array = {}
     for i = 1, m do
          array[i]=v
     end
     return array
end

function initArray(m)
	local array = {}
		for i = 1, m do
			array[i]=0
		end
return array
end
function totable(t,match)
     local cmd = {}
     if not match then match = "[^%s]+" end
     for word in string.gmatch(t, match) do
          table.insert(cmd, word)
     end
     return cmd
end


join=initArray(32)
king=0

addhook('startround','Ajm_Start')
function Ajm_Start()
local t=getplayers()
king=math.random(1,#t)
for id= king,king do
parse('equip '..id..' 45')
parse('setmaxhealth '..id..' 150')
parse('setarmor '..id..' 83')
end
end

old Re: Random players should get special rank each round

_Yank
User Off Offline

Quote
Ehm..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
parse("restart 3") -- Why this ? Anyway...
addhook("startround", "Ajm_start")
function Ajm_start()
	local tTab = player(0, "team1")
	local ctTab = player(0, "team2")
	local rank = {}
	
	for _, id in pairs(tTab) do table.insert(rank, id) end
	king = math.random(1, #rank)
	parse('equip '..king..' 45')
	parse('setmaxhealth '..king..' 150')
	parse('setarmor '..king..' 83')
	rank = {}

	for _, id in pairs(ctTab) do table.insert(rank, id) end
	king = math.random(1, #rank)
	parse('equip '..king..' 45')
	parse('setmaxhealth '..king..' 150')
	parse('setarmor '..king..' 83')
end

There's lot of way to do this, this one was the first who came up.

old Re: Random players should get special rank each round

Ajmin
User Off Offline

Quote
i think it does not works.
when i tested i am always the king and also the other team bot is not getting king.

maybe we need to make a another special rank for ct.

like this:
King (it is the special rank for t)
kingct (it is the special rank for ct)

it also gives error in console:
Lua error:
bad argument to random(interval is empty)

old Re: Random players should get special rank each round

_Yank
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
parse("restart 3") -- Why this ? Anyway...
addhook("startround", "Ajm_start")
function Ajm_start()
     local tTab = player(0, "team1")
     local ctTab = player(0, "team2")

	if #tTab + #ctTab < 2 then return end
     local rank = {}
     
     for _, id in pairs(tTab) do table.insert(rank, id) end
     king = rank[math.random(1, #rank)]
     parse('equip '..king..' 45')
     parse('setmaxhealth '..king..' 150')
     parse('setarmor '..king..' 83')
     rank = {}

     for _, id in pairs(ctTab) do table.insert(rank, id) end
     king = rank[math.random(1, #rank)]
     parse('equip '..king..' 45')
     parse('setmaxhealth '..king..' 150')
     parse('setarmor '..king..' 83')
end
If it doesn't works, you're doing something wrong.
edited 1×, last 08.09.14 05:33:46 pm

old Re: Random players should get special rank each round

Ajmin
User Off Offline

Quote
still the same.
interval is empty

Worked.
i removed a unwanted thing.
for _, id in pairs(tTab) do table.insert(rank, id) end
king = math.random(1, #rank)
parse('equip '..king..' 45')
parse('setmaxhealth '..king..' 150')
parse('setarmor '..king..' 83')
rank = {}

that rank was not needed but a small error still.
it sometime dont gives laser to me or ct and sometime it gives.
edited 1×, last 08.09.14 05:35:23 pm

old Re: Random players should get special rank each round

_Yank
User Off Offline

Quote
No, I didn't tested it but, you're the one who did the things wrong. Cause that line only checks if there at least 1 player at each team (not literally) and avoids that error message which appears on the console.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview