Author Topic: /swap - ctf team swap (alpha<>blue)  (Read 2483 times)

0 Members and 1 Guest are viewing this topic.

Offline Vyka

  • Major
  • *
  • Posts: 59
/swap - ctf team swap (alpha<>blue)
« 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;
« Last Edit: October 27, 2008, 02:55:59 pm by Vyka »

Offline GSx_Major

  • Major
  • *
  • Posts: 97
Re: /swap - ctf team swap (alpha<>blue)
« Reply #1 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;
...and headbutt the sucker through your banana suit!

Offline EnEsCe

  • Retired Soldat Developer
  • Flamebow Warrior
  • ******
  • Posts: 3101
  • http://enesce.com/
    • [eC] Official Website
Re: /swap - ctf team swap (alpha<>blue)
« Reply #2 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".

Offline UPNPAD

  • Major(1)
  • Posts: 36
Re: /swap - ctf team swap (alpha<>blue)
« Reply #3 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;
« Last Edit: October 28, 2008, 04:27:51 am by UPNPAD »

Offline Norbo

  • Camper
  • ***
  • Posts: 338
Re: /swap - ctf team swap (alpha<>blue)
« Reply #4 on: October 28, 2008, 02:36:05 am »
this isn't following the releases template

Offline deevus

  • Major(1)
  • Posts: 16
Re: /swap - ctf team swap (alpha<>blue)
« Reply #5 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

Offline iDante

  • Veteran
  • *****
  • Posts: 1966
Re: /swap - ctf team swap (alpha<>blue)
« Reply #6 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.

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: /swap - ctf team swap (alpha<>blue)
« Reply #7 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 <.<

Offline GSx_Major

  • Major
  • *
  • Posts: 97
Re: /swap - ctf team swap (alpha<>blue)
« Reply #8 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.
...and headbutt the sucker through your banana suit!

Offline deevus

  • Major(1)
  • Posts: 16
Re: /swap - ctf team swap (alpha<>blue)
« Reply #9 on: October 29, 2008, 03:03:21 am »
Nah, would be '= true'. := is only used for assigning values :)

Offline GSx_Major

  • Major
  • *
  • Posts: 97
Re: /swap - ctf team swap (alpha<>blue)
« Reply #10 on: October 29, 2008, 04:43:15 am »
As in when setting what GetPlayerStat returns...
...and headbutt the sucker through your banana suit!