English Lua request

7 replies
Goto Page
To the start Previous 1 Next To the start
20.09.14 07:24:53 pm
Up
HajusHai
User
Offline Off
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!
20.09.14 07:37:54 pm
Up
Alpha Beta
User
Offline Off
Maybe this?
Code:
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
20.09.14 07:40:44 pm
Up
TopNotch
User
Offline Off
Code:
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.
20.09.14 08:02:59 pm
Up
HajusHai
User
Offline Off
user Alpha Beta has written:
Maybe this?
Code:
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)
20.09.14 08:15:30 pm
Up
Alpha Beta
User
Offline Off
Yeah, just tried. Doesn't really work.
Both codes are buggy here.
I don't know why startround_prespawn is called multiple times...
20.09.14 10:04:39 pm
Up
Zeik
User
Offline Off
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
20.09.14 10:12:01 pm
Up
HajusHai
User
Offline Off
user Zeik, Thanks!

Admin/mod comment:

OMG. Removed quote of post above yours! /user useigor
20.09.14 10:24:14 pm
Up
Zeik
User
Offline Off
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.

Code:
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