Official Soldat Forums

Server Talk => Scripting Discussions and Help => Topic started by: |_ancer on September 07, 2009, 03:46:52 am

Title: DoDamage script not compiling!
Post by: |_ancer on September 07, 2009, 03:46:52 am
Quote
function OnPlayerCommand(ID: Byte; Text: string): boolean;
var allplayersdie : byte;
    dmgamount : integer;
   temps : string;
begin   
if pos('/dmg ',temps) = 1
   then begin
        temps := Text;
        temps := delete(temps,1,5);
        dmgamount := strtoint(temps);
          for allplayersdie := 1 to NumPlayers do
            DoDamage(allplayersdie, dmgamount)
      end
end;

I cannot find anything wrong in the script and it just won't compile. It keeps on saying 'Type mismatch'. Help!
Title: Re: DoDamage script not compiling!
Post by: Toumaz on September 07, 2009, 04:57:10 am
Delete is a procedure that works by reference; it does thus not return a value, but instead modifies the string itself.

tl;dr change temps := delete(temps,1,5); to delete(temps,1,5);.
Title: Re: DoDamage script not compiling!
Post by: |_ancer on September 07, 2009, 06:09:52 am
Quote
09-09-07 21:09:13 
  • DeathDmg -> [Error] (10:9): Identifier expected
It says that when I changed it.
Title: Re: DoDamage script not compiling!
Post by: Toumaz on September 07, 2009, 06:23:53 am
Code: [Select]
function OnPlayerCommand(ID: Byte; Text: string): boolean;
var
allplayersdie : byte;
    dmgamount : integer;
temps : string;
begin
if pos('/dmg ', temps) = 1 then begin
temps := Text;
Delete(temps, 1, 5);
dmgamount := strtoint(temps);

for allplayersdie := 1 to NumPlayers do
DoDamage(allplayersdie, dmgamount)
end
end;
Title: Re: DoDamage script not compiling!
Post by: |_ancer on September 07, 2009, 07:46:34 am
It compiles but whenever I do /dmg 4000, it doesn't seem to kill anyone.
Title: Re: DoDamage script not compiling!
Post by: Polifen on September 07, 2009, 09:55:16 am
You check if temps = /dmg before you set the value, change pos('/dmg ', temps) to pos('/dmg ', Text). Second thing is that it would be better if you use Copy(Text, 1, 5) instead of Pos.
Title: Re: DoDamage script not compiling!
Post by: Gizd on September 07, 2009, 12:12:17 pm
Code: [Select]
if GetPiece(text,' ',0) = '/dmg' then try
  DoDamage(IntToStr(GetPiece(text,' ',1)), IntToStr(GetPiece(text,' ',2)));
except
  WriteConsole(ID,'/dmg <id> <dmg>',$AA0000);
end;