Forum

> > CS2D > Scripts > Randomize Teams and Leave Hook
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Randomize Teams and Leave Hook

10 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Randomize Teams and Leave Hook

mrc
User Spielt CS2D

Zitieren
-- Randomize Teams
I just need a script for that.

Detect current players at T and CT then randomize and pick 5 for T and 5 for CT, the rest is moved to spectators.

--Leave Hook

If a player leave (reason id 0) then temp. ban else don't ban.
2× editiert, zuletzt 16.03.19 05:51:17

alt Re: Randomize Teams and Leave Hook

Rainoth
Moderator Off Offline

Zitieren
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
function shuffle()
teams = {
  ct = {},
  t = {},
  spec = {},
  counter = 1
}
  for k,v in pairs (player(0,"team1")) do
    if teams.counter <= 5 then 
      teams.counter = teams.counter + 1
      teams.t[#teams.t+1] = v
    else
      teams.spec[#teams.spec+1] = v
    end
  end
  teams.counter = 1
  for k,v in pairs (player(0,"team2")) do
    if teams.counter <= 5 then 
      teams.counter = teams.counter + 1
      teams.ct[#teams.ct+1] = v
    else
      teams.spec[#teams.spec+1] = v
    end
  end
  for k,v in pairs (teams) do
    if type(v) == "table" then
      for _, id in pairs (v) do
        parse("make"..k.." "..id)
      end
    end
  end
end


1
2
3
4
5
6
addhook("leave","_leave")
function _leave(id,reason)
  if reason == 0 then
    parse("banip "..player(id,"ip").." -1")
  end
end

Untested. Good luck.
1× editiert, zuletzt 17.03.19 12:50:27

alt Re: Randomize Teams and Leave Hook

mrc
User Spielt CS2D

Zitieren
The Randomize Teams script is always moving to T. Maybe another way is easier to do? Checking all IDs of T and CT only and mix them. No need to move for spectators.
7× editiert, zuletzt 17.03.19 05:39:30

alt Re: Randomize Teams and Leave Hook

DC
Admin Off Offline

Zitieren
I found a simple table shuffle here:
1
2
3
4
5
6
7
function shuffle(tbl)
	for i = #tbl, 2, -1 do
		local j = math.random(i)
		tbl[i], tbl[j] = tbl[j], tbl[i]
		end
	return tbl
end

With that all we have to do is
• get all Ts and CTs and put their IDs in one big array (
getPlayersInTeams
)
• shuffle that array (swap entries randomly) (
shuffle
)
• make first 5 T, next 5 CT and rest spec (
assignRandomTeams
)
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
function getPlayersInTeams()
	-- Get and join team1 and team2 players
	local t = player(0,"team1")
	local tCount = #t

	local ct = player(0,"team2")
	local ctCount = #ct

	for i = 1, ctCount do
		t[tCount + i] = ct[i]
	end

	return t
end

function assignRandomTeams(playersPerTeam)
	-- Get and shuffle players
	local ids = getPlayersInTeams()
	shuffle(ids)

	-- Assign teams
	local playerCount = #ids
	for i = 1, playerCount do
		if (i <= playersPerTeam) then
			parse("maket " .. ids[i])
		else if (i <= playersPerTeam * 2) then
			parse("makect " .. ids[i])
		else
			parse("makespec " .. ids[i])
		endif
	end
end

Needs to be called like
assignRandomTeams(5)


I didn't test that and there's certainly something wrong but I hope you get the idea.

alt Re: Randomize Teams and Leave Hook

Rainoth
Moderator Off Offline

Zitieren
@user mrc: Oops!
I copy pasted the code from moving to t to moving ct and I just needed to add a letter "c" in front of every "t" but I managed to write
teamsc.t
instead of
teams.ct

I fixed it in my original post.
Sorry >.< !

alt Re: Randomize Teams and Leave Hook

Hajt
User Off Offline

Zitieren
@user mrc: After usage
parse("banusgn "..id.." 10")
player leave the server so this variable id doesn't belong to him anymore. You should storage his steamid, ip and name in temporary variables.

Moreover I don't get why you put loop in that leave hook.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht