Official Soldat Forums

Server Talk => Scripting Releases => Topic started by: Vyka on October 27, 2008, 02:53:01 pm

Title: /swap - ctf team swap (alpha<>blue)
Post by: Vyka on October 27, 2008, 02:53:01 pm
if somebody need team swapping script, here it is! enjoy.

/swap - team swapping

(in code, for slots, change  number of server slots, where script will work)

Code: [Select]
const
slots=10;

var
bool: array[1..32] of boolean;
i: integer;

function OnCommand(ID: Byte; Text: string): boolean;
begin
if MaskCheck(lowercase(Text),'/swap')=true then begin
for i:=1 to slots do bool[i]:=true;
for i:=1 to slots do begin
if ((getplayerstat(i,'active')=true) and (getplayerstat(i,'team')=1) and (bool[i]=true)) then begin
command('/setteam2 '+inttostr(i));
bool[i]:=false;
end;
if ((getplayerstat(i,'active')=true) and (getplayerstat(i,'team')=2) and (bool[i]=true)) then begin
command('/setteam1 '+inttostr(i));
bool[i]:=false;
end;
end;
end;
end;
Title: Re: /swap - ctf team swap (alpha<>blue)
Post by: GSx_Major on October 27, 2008, 04:15:21 pm
Seems overcomplicated.

Code: [Select]
function OnCommand(ID: Byte; Text: string): boolean;
var i: Byte;
begin

  // Swap teams
  if Text = '/swap' then
    for i := 1 to 32 do
      if GetPlayerStat(i, 'Active') then
        if GetPlayerStat(i, 'Team') = 1 then
          Command('/setteam2 ' + IntToStr(i))
        else
          if GetPlayerStat(i, 'Team') = 2 then
            Command('/setteam1 ' + IntToStr(i));
 

end;
Title: Re: /swap - ctf team swap (alpha<>blue)
Post by: EnEsCe on October 27, 2008, 11:45:30 pm
Quote
      if GetPlayerStat(i, 'Active') then
Return is a variant not a boolean. You need to add " = true".
Title: Re: /swap - ctf team swap (alpha<>blue)
Post by: UPNPAD on October 28, 2008, 12:53:26 am
Code: [Select]
const
  Teams = 3; //How many teams are playing plus one, (CTF, INF, HTF = 3, TDM = 5)

function OnCommand(ID: Byte; Text: string): boolean;
var i: Byte;
begin
  // Swap teams
  if Text = '/swap' then
    for i := 1 to 32 do
      if (GetPlayerStat(i, 'Active') = true) and (GetPlayerStat(i, 'Team') <> 5) then
        Command('/setteam' + IntToStr(Teams - GetPlayerStat(i, 'Team')) + ' ' + IntToStr(i));
end;
Title: Re: /swap - ctf team swap (alpha<>blue)
Post by: Norbo on October 28, 2008, 02:36:05 am
this isn't following the releases template
Title: Re: /swap - ctf team swap (alpha<>blue)
Post by: deevus on October 28, 2008, 02:47:07 am
Quote
      if GetPlayerStat(i, 'Active') then
Return is a variant not a boolean. You need to add " = true".

Would be safer and better practice to cast to a boolean.

Eg.

lbActive := GetPlayerStat(i, 'Active')
if lbActive then begin
etc
Title: Re: /swap - ctf team swap (alpha<>blue)
Post by: iDante on October 28, 2008, 03:46:55 am
Quote
      if GetPlayerStat(i, 'Active') then
Return is a variant not a boolean. You need to add " = true".

Would be safer and better practice to cast to a boolean.

Eg.

lbActive := GetPlayerStat(i, 'Active')
if lbActive then begin
etc
No. The issue is that on the 32nd one, for some reason it returns something other than a boolean.
If the script is going to be run on a server with 32 people on it, then add in = true. Saying that makes my heart cry out.
Title: Re: /swap - ctf team swap (alpha<>blue)
Post by: danmer on October 28, 2008, 07:31:27 am
just from my experience, switching lots of players at the same time tends to cause the colorbug. When you move them all to spec and then to the needed teams after a couple of seconds (in apponidle), everything works perfectly well. Of course most people will think "wtf" at least once, but that shouldn't be too much of a problem compared to the colorbug <.<
Title: Re: /swap - ctf team swap (alpha<>blue)
Post by: GSx_Major on October 28, 2008, 09:02:36 am
Enesce, maybe you need to read up on your delphi variants? ;) It will work (and has) without problems - probably cause you wrote "= true" somewhere (well, more like ":= true"). Being clear is very important when working with big projects - not with 8 lines of Soldat script.
Title: Re: /swap - ctf team swap (alpha<>blue)
Post by: deevus on October 29, 2008, 03:03:21 am
Nah, would be '= true'. := is only used for assigning values :)
Title: Re: /swap - ctf team swap (alpha<>blue)
Post by: GSx_Major on October 29, 2008, 04:43:15 am
As in when setting what GetPlayerStat returns...