Forum

> > CS2D > Scripts > Team change
Forums overviewCS2D overview Scripts overviewLog in to reply

English Team change

14 replies
To the start Previous 1 Next To the start

old Team change

Masea
Super User Off Offline

Quote
Hello! In this thread, I'm going to want something from you guys!

I want to make function that changes team of players. With an example, there is 4 Terrorists and 4 Counter-Terrorists. When I use that function, those 4 Terrorists will change their teams to Counter-Terrorist automatically. Same for Counter-Terrorist players as like Terrorist players.

Thanks!

old Re: Team change

Nekomata
User Off Offline

Quote
edit: use waldin's code

1
2
3
4
5
6
7
8
9
10
function inverseTeams()
	local playerlist = player(0, "table")
	for _, id in ipairs(playerlist) do
		if player(id, "team") == 1 then
			parse('makect '..id)
		elseif player(id, "team") == 2 then
			parse('maket '..id)
		end
	end
end
edited 1×, last 15.08.16 02:46:12 am

old Re: Team change

Waldin
User Off Offline

Quote
i made this for a friend:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function switchTeams()
	local atb = game("mp_autoteambalance")
	if atb == "1" then
		parse("mp_autoteambalance 0")
	end
	for _,id in ipairs(player(0,"table")) do
		if player(id,"team") ~= 0 then
			parse("make"..(player(id,"team")==1 and "ct" or "t").." "..id)
		end
	end
	if atb == "1" then
		parse("mp_autoteambalance 1")
	end
end
edited 3×, last 14.08.16 11:47:12 pm

old Re: Team change

Nekomata
User Off Offline

Quote
1
parse("make"..(player(id,"team")==1 and "ct" or "t").." "..id)
TIL. didn't know that was possible

If team balance causes an issue then be sure to disable it.

old Re: Team change

Yates
Reviewer Off Offline

Quote
@user Waldin:
Once you get a list of players where two or more of following incrementing IDs (1, 2, 3 or 2, 5, 9 if the IDs in between are not used) which are on the same team your script won't work.

Simply because if you try to make 2 players a CT while not keeping the same balance on the T side then team balance will screw you over and put the player back.

The solution is to check if cs2d cmd mp_autoteambalance is on, turn it off loop & switch the players then turn it back on.

old Re: Team change

Mami Tomoe
User Off Offline

Quote
What is
1
2
3
if atb == "1" then
          parse("mp_autoteambalance 1")
     end
for?

old Re: Team change

Waldin
User Off Offline

Quote
@user Mami Tomoe: The code cheks if autoteambalance is 1 twice, before and after switching teams. If is 1 before, the code will set it 0,and after set back it to 1 again (we changed it before).

old Re: Team change

Mami Tomoe
User Off Offline

Quote
1
2
3
if atb == "1" then
          parse("mp_autoteambalance 0")
     end
Checks if atb is 1 or 0
If 1 then make it 0

1
2
3
if atb == "1" then
          parse("mp_autoteambalance 1")
     end
Checks if atb is 1 or 0
If 1 then make it 1


Read that again:
If 1 then make it 1
It's already 1!

Shouldn't it be like this?:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function switchTeams()
     local atb = game("mp_autoteambalance")
     if atb == "1" then
          parse("mp_autoteambalance 0")
		  local temp=true
     end
     for _,id in ipairs(player(0,"table")) do
          if player(id,"team") ~= 0 then
               parse("make"..(player(id,"team")==1 and "ct" or "t").." "..id)
          end
     end
	 if temp=true then
		parse("mp_autoteambalance 1") -- This has been changed
		local temp=nil
	end
end

old Re: Team change

Waldin
User Off Offline

Quote
@user Mami Tomoe: the abt value will be 0 if teambalance off, 1 otherwise.
It will not change if i change the team balance.
And your code will not work.
If you cant understand:
1
2
3
if atb == "1" then
          parse("mp_autoteambalance 0")
     end
This change the teambalance and NOT the atb value.

old Re: Team change

Mami Tomoe
User Off Offline

Quote
local atb = game("mp_autoteambalance")

For example the game("mp_autoteambalance") is 1

1
2
3
if atb == "1" then
          parse("mp_autoteambalance 1")
     end
If it is 1 it will change to 1?
But it is already 1 so why to change it to 1 again?

old Re: Team change

Waldin
User Off Offline

Quote
ill explain you:
Here is the code >


Okay, see the first part:
local atb = game("mp_autoteambalance")

If you can read it, here we set the value of the team balance to the local variable
atb
. if auto balance is on, it will be the string "1", otherwise will be the string "0", can you understand this? we will continue.

Now read this
1
2
3
if atb == "1" then
          parse("mp_autoteambalance 0")
     end
Here we check if the
atb
's value is the string "1", that means team balance is ON. if it is on, then we disable it.

**This part switchs teams, i think that u already understand.**

And the last one:

1
2
3
if atb == "1" then
          parse("mp_autoteambalance 1")
     end
See, we re checking if atb is the string "1" again, why again? we checked it before!
The answer: if it was "1" (if team balance was on) before, we changed the team balance to 0 (that means OFF), but did not changed the value of
atb
.
So if we changed team balance in before, now we set it again to 1 (that means ON).

Can you understand now? no? srs? i have bad news for you.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview