Forum

> > CS2D > Scripts > Lua request
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua request

7 replies
To the start Previous 1 Next To the start

old Lua request

HajusHai
User Off Offline

Quote
Hello,

I'd like for someone to write a script which swaps teams after each round. For example if the player is a CT than after round he would be T. I would use it my server, as well it would help me learn about lua more.

Thanks!

old Re: Lua request

Alpha Beta
User Off Offline

Quote
Maybe this?
1
2
3
4
5
6
7
8
9
10
11
addhook("startround_prespawn", "swapteams")
function swapteams(mode)
	local playerlist=player(0,"table")
	for _,id in pairs(playerlist) do
		if (player(id, "team") == 1) then
			parse("makect "..id)
		elseif (player(id, "team") == 2) then
			parse("maket "..id)			
		end
	end
end

old Re: Lua request

TopNotch
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
addhook("endround","_endround")
function _endround(m)
local playerlist=player(0,"table")
    for _,id in pairs(playerlist) do
        if player(id, "team") == 1 then
            parse("makect "..id)
        elseif player(id, "team") == 2 then
            parse("maket "..id)               
        end
    end
end
EDIT: I guess user Alpha Beta's code will be better since it doesn't kill the surviving players.

old Re: Lua request

HajusHai
User Off Offline

Quote
user Alpha Beta has written
Maybe this?
1
2
3
4
5
6
7
8
9
10
11
addhook("startround_prespawn", "swapteams")
function swapteams(mode)
	local playerlist=player(0,"table")
	for _,id in pairs(playerlist) do
		if (player(id, "team") == 1) then
			parse("makect "..id)
		elseif (player(id, "team") == 2) then
			parse("maket "..id)			
		end
	end
end


Unless i'm doing something wrong, this script keeps switching teams, because everytime it switches teams it ends the round which switches the teams again and so continuing in a endless loop. (I hope i explained it right)

old Re: Lua request

Alpha Beta
User Off Offline

Quote
Yeah, just tried. Doesn't really work.
Both codes are buggy here.
I don't know why startround_prespawn is called multiple times...

old Re: Lua request

Zeik
User Off Offline

Quote
This isn't right: >

EDIT: tried it for a while an sometimes it bugs, I don't know why.
edited 1×, last 21.09.14 06:29:03 am

old Re: Lua request

Zeik
User Off Offline

Quote
The problem is that when a team wins, the game calls the endround hook in <that team's win mode>, so when the last man standing dies -when switching sides- from the winner team, the game calls the endround hook in the <game draw> mode. So the endround hook is called twice.

I think that the only way of fixing this is not running the hook on <game draw>. But it won't work when a real draw occurs.

1
2
3
4
5
6
7
8
9
10
11
12
13
addhook("endround","_endround")
function _endround(m)
local playerlist=player(0,"table")
	if(m ~= 4 and m ~= 3) then
		for _,id in pairs(playerlist) do
			if player(id, "team") == 1 then
				parse("makect "..id)
			elseif player(id, "team") == 2 then
				parse("maket "..id)               
			end
		end
	end
end
edited 1×, last 21.09.14 06:23:58 am
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview