Official Soldat Forums

Server Talk => Scripting Releases => Topic started by: Serial K!ller on January 31, 2007, 02:25:30 pm

Title: /gamemode ctf (dm,rm,pm,inf,htf,tm(or tdm)) command script
Post 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):
Code: [Select]
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
Code: [Select]
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
Title: Re: /gamemode ctf (dm,rm,pm,inf,htf,tm(or tdm)) command script
Post by: ultraman on February 01, 2007, 05:41:58 am
Sweet, those gamemode numbers can be quite pesky to remember, thanks man.
Title: Re: /gamemode ctf (dm,rm,pm,inf,htf,tm(or tdm)) command script
Post by: KeYDoN on February 19, 2007, 08:12:32 am
You use Copy wrong.
the correct syntax is
Code: [Select]
function Copy ( Source  : string; StartChar, Count  : Integer ) : string;fore example
Code: [Select]
Text := '/gamemode ctf'
result := Copy(Text, 11,3);
// result = 'ctf'
Title: Re: /gamemode ctf (dm,rm,pm,inf,htf,tm(or tdm)) command script
Post by: Serial K!ller on February 19, 2007, 12:31:52 pm
the compiler accepts it and it works...
Title: Re: /gamemode ctf (dm,rm,pm,inf,htf,tm(or tdm)) command script
Post by: KeYDoN on February 19, 2007, 08:48:58 pm
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?
Title: Re: /gamemode ctf (dm,rm,pm,inf,htf,tm(or tdm)) command script
Post by: Serial K!ller on February 20, 2007, 04:05:26 am
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!
Title: Re: /gamemode ctf (dm,rm,pm,inf,htf,tm(or tdm)) command script
Post by: spkka on March 18, 2007, 09:53:05 pm
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?
Title: Re: /gamemode ctf (dm,rm,pm,inf,htf,tm(or tdm)) command script
Post by: nub on March 19, 2007, 08:04:38 am
You are writing too much.

Code: [Select]
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;
Title: Re: /gamemode ctf (dm,rm,pm,inf,htf,tm(or tdm)) command script
Post by: Freedom on November 17, 2007, 04:51:04 am
It works BUT when i trying to type any command it says "Invalid variant type conversion"

Lol?
Title: Re: /gamemode ctf (dm,rm,pm,inf,htf,tm(or tdm)) command script
Post by: DorkeyDear on November 17, 2007, 08:21:43 am
You use Copy wrong.
the correct syntax is
Code: [Select]
function Copy ( Source  : string; StartChar, Count  : Integer ) : string;fore example
Code: [Select]
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 :)
Title: Re: /gamemode ctf (dm,rm,pm,inf,htf,tm(or tdm)) command script
Post by: Kavukamari on November 20, 2007, 08:44:13 pm
err, OnCommand is a function ;) you put it as a procedure

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