Official Soldat Forums
Server Talk => Scripting Releases => Topic started 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)
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;
-
Seems overcomplicated.
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;
-
if GetPlayerStat(i, 'Active') then
Return is a variant not a boolean. You need to add " = true".
-
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;
-
this isn't following the releases template
-
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
-
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.
-
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 <.<
-
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.
-
Nah, would be '= true'. := is only used for assigning values :)
-
As in when setting what GetPlayerStat returns...