Official Soldat Forums
Server Talk => Scripting Releases => Topic started by: Serial K!ller on January 31, 2007, 02:25:30 pm
-
Script Name:/gamemode ctf (dm,rm,pm,inf,htf,tm(or tdm)) command script
Script Description: For people like me who keep forgetting what the number of the gamemode is, just use the abbreviations of the gamemodes (ex: /gametype HTF), also added a warning "say switching to ... gamestyle in 5 seconds" and a countdown.
Original Author(s):Serial K!ller & nub
Core Version:2.5.2
Code(core.pas):
const
GMM_CNTDOWNLENGTH = 5; //gamemodeswitch countdownlength
var
//-----/gamemode xxx variables
startgamemodeswitch:integer;
togamemode:integer;
G_TT : integer;
G_CNT : integer;
//-----------------------------------------
procedure ActivateServer();
begin
end;
procedure AppOnIdle(Ticks: integer);
begin
{ gameswitch procedure }
if (startgamemodeswitch = 1) then begin
G_CNT := G_CNT-1;
Command('/say '+inttostr(G_CNT));
if(G_CNT = 0) then begin Command('/gamemode '+inttostr(togamemode)); startgamemodeswitch := 0; end;
end;
end;
procedure OnCommand(ID:integer; Text:string);
var i:byte;
gamemodeArray: array[0..7] of string;
begin
Text := lowercase(Text);
gamemodeArray[0] := 'dm'; gamemodeArray[1] := 'pm'; gamemodeArray[2] := 'tm';
gamemodeArray[3] := 'ctf'; gamemodeArray[4] := 'rm'; gamemodeArray[5] := 'inf';
gamemodeArray[6] := 'htf';
togamemode := 255;
if(Copy(Text,1,9) = '/gamemode') then begin
for i:= 0 to ArrayHigh(gamemodeArray) do if(Copy(Text,11,Length(Text)) = gamemodeArray[i]) then begin togamemode := i; break; end;
if((togamemode <> 255) and (GameStyle <> togamemode)) then begin
startgamemodeswitch := 1;
command('/say switching to '+gamemodeArray[togamemode]+' gamestyle in '+IntToStr(GMM_CNTDOWNLENGTH)+' seconds, please rejoin');
G_CNT := GMM_CNTDOWNLENGTH;
end;
end;
end;
here's the script without the warning and countdown
procedure OnCommand(ID:integer; Text:string);
var i:byte;
gamemodeArray: array[0..7] of string;
togamemode:integer;
begin
Text := lowercase(Text);
gamemodeArray[0] := 'dm'; gamemodeArray[1] := 'pm'; gamemodeArray[2] := 'tm';
gamemodeArray[3] := 'ctf'; gamemodeArray[4] := 'rm'; gamemodeArray[5] := 'inf';
gamemodeArray[6] := 'htf';
togamemode := 255;
if(Copy(Text,1,9) = '/gamemode') then begin
for i:= 0 to ArrayHigh(gamemodeArray) do if(Copy(Text,11,Length(Text)) = gamemodeArray[i]) then begin togamemode := i; break; end;
if((togamemode <> 255) and (GameStyle <> togamemode)) then begin
Command('/gamemode '+inttostr(togamemode))
end;
end;
end;
[edit]
updated to the much shorter version of nub
-
Sweet, those gamemode numbers can be quite pesky to remember, thanks man.
-
You use Copy wrong.
the correct syntax is
function Copy ( Source : string; StartChar, Count : Integer ) : string;
fore example
Text := '/gamemode ctf'
result := Copy(Text, 11,3);
// result = 'ctf'
-
the compiler accepts it and it works...
-
yes as long no additional letters occur
its not wrong in the way a comiler would not accept it its just wrong ;O
And in this script it maybe doesnt even make problems, but i just noticed that you use it wrong and i just wanted to tell you that :o
Copy(Text,11,12) for example expects 12 other letters after the 11th, but you just want to copy 3, so why copy more?
-
oh lol thought you meant using it directly was wrong; didn't know the 2nd variable was the length thought it was from char 12 to char 13 ::)
[edit] fixed it!
-
is it also possible to make sth in this code that if your playing a ctf map advance will be set to on, and same for survival and realistic. When map changes to trenchwar, advance and survival will be turned off?
-
You are writing too much.
procedure OnCommand(ID:integer; Text:string);
var i:byte;
gamemodeArray: array[0..7] of string;
begin
Text := lowercase(Text);
gamemodeArray[0] := 'dm'; gamemodeArray[1] := 'pm'; gamemodeArray[2] := 'tm';
gamemodeArray[3] := 'ctf'; gamemodeArray[4] := 'rm'; gamemodeArray[5] := 'inf';
gamemodeArray[6] := 'htf';
togamemode := 255;
if(Copy(Text,1,9) = '/gamemode') then begin
for i:= 0 to ArrayHigh(gamemodeArray) do if(Copy(Text,11,Length(Text)) = gamemodeArray[i]) then begin togamemode := i; break; end;
if((togamemode <> 255) and (GameStyle <> togamemode)) then begin
startgamemodeswitch := 1;
command('/say switching to '+gamemodeArray[togamemode]+' gamestyle in '+IntToStr(GMM_CNTDOWNLENGTH)+' seconds, please rejoin');
G_CNT := GMM_CNTDOWNLENGTH;
end;
end;
end;
procedure AppOnIdle(Ticks: integer);
begin
{ gameswitch procedure }
if (startgamemodeswitch = 1) then begin
G_CNT := G_CNT-1;
Command('/say '+inttostr(G_CNT));
if(G_CNT = 0) then begin Command('/gamemode '+inttostr(togamemode)); startgamemodeswitch := 0; end;
end;
end;
-
It works BUT when i trying to type any command it says "Invalid variant type conversion"
Lol?
-
You use Copy wrong.
the correct syntax is
function Copy ( Source : string; StartChar, Count : Integer ) : string;
fore example
Text := '/gamemode ctf'
result := Copy(Text, 11,3);
// result = 'ctf'
I learned copy wrong :P I thought it was start + end char # in... (just tested to make sure) hm :)
-
err, OnCommand is a function ;) you put it as a procedure
function OnCommand(ID:Byte;Text:string):boolean;