Forum

> > CS2D > Scripts > Lua request
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Lua request

7 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Lua request

HajusHai
User Off Offline

Zitieren
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!

alt Re: Lua request

Alpha Beta
User Off Offline

Zitieren
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

alt Re: Lua request

TopNotch
User Off Offline

Zitieren
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.

alt Re: Lua request

HajusHai
User Off Offline

Zitieren
user Alpha Beta hat geschrieben
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)

alt Re: Lua request

Alpha Beta
User Off Offline

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

alt Re: Lua request

Zeik
User Off Offline

Zitieren
This isn't right: >

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

alt Re: Lua request

Zeik
User Off Offline

Zitieren
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
1× editiert, zuletzt 21.09.14 06:23:58
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht