Author Topic: Error in the script  (Read 1184 times)

0 Members and 3 Guests are viewing this topic.

Offline shay

  • Major(1)
  • Posts: 21
Error in the script
« on: April 09, 2013, 02:39:16 pm »
Hi
I have a problem with climb script.

What is this error?
TopCap -> (OnFlagScore): Could not convert variant of type (String) into type (Double)

Code: [Select]
procedure OnFlagScore(Id, TeamFlag: byte);
var
    Time: cardinal;
    Stat: string;
begin
    if (not Ignore) then begin
    Time := GetTime;
    Stat := GetPlayerStat(Id, 'Name') + #3 + InttoStr(GetPlayerStat(Id, 'Team')) + #3 + GetPlayerStat(Id, 'Deaths') + #3 + InttoStr(Time - Player[Id].RespawnTime) + #3 + InttoStr(Time - Player[Id].JoinTime) + #3 + InttoStr(Time - MapStartTime) + #3 + FormatDate('yy-mm-dd') + #3 + FormatDate('hh:nn:zzz') + #3 + CurrentMap;
    WriteLnFile('scripts/' + ScriptName + '/logs/date/' + FormatDate('yy-mm-dd') +'.log',Stat);
    WriteLnFile('scripts/' + ScriptName + '/logs/player/' + MD5(GetPlayerStat(Id, 'Name')) +'.log',Stat);
    WriteLnFile('scripts/' + ScriptName + '/logs/map/' + CurrentMap +'.log',Stat);
    WriteLn(GetPlayerStat(Id, 'Name') + ' capped ' + CurrentMap + ' in ' + FloattoStr(PlayerTime(Player[Id]) / 1000) + 's with ' + InttoStr(GetPlayerStat(Id, 'Deaths')) + ' death' + iif(GetPlayerStat(Id, 'Deaths') = 1, '', 's'));
    WriteConsole(0, GetPlayerStat(Id, 'Name') + ' capped ' + CurrentMap + ' in ' + FloattoStr(PlayerTime(Player[Id]) / 1000) + 's with ' + InttoStr(GetPlayerStat(Id, 'Deaths')) + ' death' + iif(GetPlayerStat(Id, 'Deaths') = 1, '', 's'), Color);
    if (not CapNext and CapKill) then DoDamage(Id, 4000);
    if (CapNext) then Command('/nextmap');
    if (CapRes) then Player[Id].RespawnTime := GetTime;
    end else begin
    WriteLn('Unable to log ' + GetPlayerStat(Id, 'Name') + '''s cap');
    WriteConsole(0, 'Unable to log ' + GetPlayerStat(Id, 'Name') + '''s cap', Color);
    if (not CapNext and CapKill) then DoDamage(Id, 4000);
    if (CapNext) then Command('/nextmap');
    if (CapRes) then Player[Id].RespawnTime := GetTime;
    end;
end;

Thanks for help...
« Last Edit: April 09, 2013, 02:46:22 pm by shay »

Offline GhostRiderSwiss

  • Camper
  • ***
  • Posts: 294
  • Scripting beginner, mapper&owner of BCB servers.
    • BCB-Forum
Re: Error in the script
« Reply #1 on: April 09, 2013, 03:26:16 pm »
Hi
I have a problem with climb script.

What is this error?
TopCap -> (OnFlagScore): Could not convert variant of type (String) into type (Double)


Hey!
Does it actualy crash your soldatserver or does it just give you the error message in arsse sometimes?
BCB-Clan Page
You also can find clan BCB on our servers.

BCB-Soldier till i die!

Offline shay

  • Major(1)
  • Posts: 21
Re: Error in the script
« Reply #2 on: April 09, 2013, 03:36:00 pm »
Error is that,when I score,doesn't write to folders.

Offline GhostRiderSwiss

  • Camper
  • ***
  • Posts: 294
  • Scripting beginner, mapper&owner of BCB servers.
    • BCB-Forum
Re: Error in the script
« Reply #3 on: April 09, 2013, 03:41:50 pm »
Error is that,when I score,doesn't write to folders.

hmmm ok, i will try to make it work but as im not a professional scripter i wont make promises^^
BCB-Clan Page
You also can find clan BCB on our servers.

BCB-Soldier till i die!

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: Error in the script
« Reply #4 on: April 09, 2013, 04:31:42 pm »
Should be ok.

Code: [Select]
procedure OnFlagScore(Id, TeamFlag: byte);
var
    Time: cardinal;
    Stat: string;
begin
    if (not Ignore) then begin
        Time := GetTime;
        Stat := GetPlayerStat(Id, 'Name') + #3 + InttoStr(GetPlayerStat(Id, 'Team')) + #3 + IntToStr(GetPlayerStat(Id, 'Deaths')) + #3 + InttoStr(Time - Player[Id].RespawnTime) + #3 + InttoStr(Time - Player[Id].JoinTime) + #3 + InttoStr(Time - MapStartTime) + #3 + FormatDate('yy-mm-dd') + #3 + FormatDate('hh:nn:zzz') + #3 + CurrentMap;
        WriteLnFile('scripts/' + ScriptName + '/logs/date/' + FormatDate('yy-mm-dd') +'.log',Stat);
        WriteLnFile('scripts/' + ScriptName + '/logs/player/' + MD5(GetPlayerStat(Id, 'Name')) +'.log',Stat);
        WriteLnFile('scripts/' + ScriptName + '/logs/map/' + CurrentMap +'.log',Stat);
        WriteLn(GetPlayerStat(Id, 'Name') + ' capped ' + CurrentMap + ' in ' + FloattoStr(PlayerTime(Player[Id]) / 1000) + 's with ' + InttoStr(GetPlayerStat(Id, 'Deaths')) + ' death' + iif(GetPlayerStat(Id, 'Deaths') = 1, '', 's'));
        WriteConsole(0, GetPlayerStat(Id, 'Name') + ' capped ' + CurrentMap + ' in ' + FloattoStr(PlayerTime(Player[Id]) / 1000) + 's with ' + InttoStr(GetPlayerStat(Id, 'Deaths')) + ' death' + iif(GetPlayerStat(Id, 'Deaths') = 1, '', 's'), Color);
    end else begin
        WriteLn('Unable to log ' + GetPlayerStat(Id, 'Name') + '''s cap');
        WriteConsole(0, 'Unable to log ' + GetPlayerStat(Id, 'Name') + '''s cap', Color);       
    end;
    if (not CapNext and CapKill) then DoDamage(Id, 4000);
    if (CapNext) then Command('/nextmap');
    if (CapRes) then Player[Id].RespawnTime := GetTime;
end;
« Last Edit: April 10, 2013, 01:58:43 am by FalconPL »
If you're not paying for something, you're not the customer; you're the product being sold.
- Andrew Lewis

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

Offline shay

  • Major(1)
  • Posts: 21
Re: Error in the script
« Reply #5 on: April 09, 2013, 04:43:57 pm »
FalconPL Forever!!!! :)
Yes now without error,You're god!
where the error was?

Offline shay

  • Major(1)
  • Posts: 21
Re: Error in the script
« Reply #6 on: April 09, 2013, 05:06:54 pm »
Now just last issue:
I do not want to go to ask for maps and players.
example: !top ctf_ash and !stats Major
I need only !top (will show the player statistics)(only ID) and too for !stats
How this fix?

because if not file.log, so the server will crash
How's it going to solve?

Code: [Select]
procedure ShowStats(const Num: integer; const Style: string; Filename: string; ID: byte);
var
  Team, Deaths: byte;
  i: integer;
  RespawnTime, JoinTime, MapTime: cardinal;
  Buffer, Name, Date, Time, sMap: string;
  Stats: tStats;
  PStats: tPlayer;
  Split: array of string;
begin
  Style := LowerCase(Style);
  Buffer := ReadFile('scripts/' + ScriptName + '/logs/' + Style + '/' + iif(Style = 'player', MD5(Filename), Filename) + '.log');
  if (Buffer <> '') then begin
    Buffer := StrReplace(Buffer, #13, #10);
    Buffer := StrReplace(Buffer, #10#10, #10);
    Split := Explode(Buffer, #10);
    SetArrayLength(Split, GetArrayLength(Split) - 1);
    Buffer := '';
    if (GetArrayLength(Split) > 0) then begin
      if (Num > 0) then begin
        Buffer := Uppercase(Style[1]) + Copy(Style, 2, Length(Style)) + ' stats for ' + Filename + ' (' + InttoStr(MinI([GetArrayLength(Split), Num])) + '/' + InttoStr(GetArrayLength(Split)) + ' results):' + #10;
          if (Style = 'map') then QuickSort(Split, 0, GetArrayLength(Split) - 1);
            for i := GetArrayLength(Split) - 1 downto MaxI([0, GetArrayLength(Split) - Num]) do begin
            if (Split[i] <> '') then begin
            Stats := ParseStat(Split[i]);
            Buffer := Buffer + Stats.Name + ' capped ' + Stats.Map + ' in ' + FloattoStr(StatsTime(Stats) / 1000) + 's with ' + InttoStr(Stats.Deaths) + ' death' + iif(Stats.Deaths = 1, '', 's') + ' (' + GetPiece(Stats.Date, '-', 1) + '-' + GetPiece(Stats.Date, '-', 2) + '-' + GetPiece(Stats.Date, '-', 0) + ')' + #10;
          end;
        end;
      end else Buffer := '';
    end else Buffer := '';
  end else Buffer := '';
  if (Buffer <> '') then begin
  SetArrayLength(Split, 0);
  Split := Explode(Buffer, #10);
  SetArrayLength(Split, GetArrayLength(Split) - 1)
  if GetArrayLength(Split) > 0 then begin
    for i := 0 to GetArrayLength(Split) - 1 do begin
      WriteConsole(ID, Split[i], Color);
      end;
    end else WriteConsole(ID, 'No ' + Style + ' stats for ' + iif(Style = 'date', GetPiece(Filename, '-', 1) + '-' + GetPiece(Filename, '-', 2) + '-' + GetPiece(Filename, '-', 0), Filename), Color);
  end else WriteConsole(ID, 'No ' + Style + ' stats for ' + iif(Style = 'date', GetPiece(Filename, '-', 1) + '-' + GetPiece(Filename, '-', 2) + '-' + GetPiece(Filename, '-', 0), Filename), Color);
end;

procedure OnPlayerSpeak(Id: byte; Text: string);
var
  Num: byte;
  Arg: string;
begin
  // !top[n=3] [map=CM]; !stats[n=3] [name=self]; !date[n=3] [date=today]; !time //
    if (Text[1] = '!') then begin
    Delete(Text, 1, 1);
    if (StrPos(' ', Text) = 0) then Text := Text + ' ';
    if (LowerCase(Copy(Text, 1, 3)) = 'top') then begin
    try
    Num := MinI([nHigh, StrtoInt(Copy(Text, 4, StrPos(' ', Text) - 4))]);
    except
    Num := 3;
    end;
    Arg := Copy(Text, StrPos(' ', Text) + 1, Length(Text));
    if (Arg = '') then Arg := CurrentMap;
    ShowStats(Num, 'map', Arg, ID);
    end else if (LowerCase(Copy(Text, 1, 5)) = 'stats') then begin
    try
    Num := MinI([nHigh, StrtoInt(Copy(Text, 6, StrPos(' ', Text) - 6))]);
    except
    Num := 3;
    end;
    Arg := Copy(Text, StrPos(' ', Text) + 1, Length(Text));
    if (Arg = '') then Arg := GetPlayerStat(Id, 'Name');
    ShowStats(Num, 'player', Arg, ID);
    end else if (LowerCase(Copy(Text, 1, 4)) = 'date') then begin
    try
    Num := MinI([nHigh, StrtoInt(Copy(Text, 5, StrPos(' ', Text) - 5))]);
    except
    Num := 3;
    end;
    Arg := Copy(Text, StrPos(' ', Text) + 1, Length(Text));
    if ((Arg = '') or (LowerCase(Arg) = 'today')) then begin
    Arg := FormatDate('yy-mm-dd');
    end else if ((LowerCase(Arg) = 'yest') or (LowerCase(Arg) = 'yesterday')) then begin
    Arg := FormatDate('yy-mm-dd');
    Arg := GetPiece(Arg, '-', 0) + '-' + GetPiece(Arg, '-', 1) + '-' + TwoDigit(InttoStr(1 + StrtoInt(GetPiece(Arg, '-', 2))));
    end else begin
    Arg := StrReplace(Arg, '/', '-');
    Arg := StrReplace(Arg, ':', '-');
    Arg := TwoDigit(GetPiece(Arg, '-', 2)) + '-' + TwoDigit(GetPiece(Arg, '-', 0)) + '-' + TwoDigit(GetPiece(Arg, '-', 1));
    end;
    ShowStats(Num, 'date', Arg, ID);
    end;
  end;
end;

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: Error in the script
« Reply #7 on: April 10, 2013, 02:00:07 am »
Answering your first question:
Stat := GetPlayerStat(Id, 'Name') + #3 + InttoStr(GetPlayerStat(Id, 'Team')) + #3 + IntToStr(GetPlayerStat(Id, 'Deaths')) + #3 + InttoStr(Time - Player[Id].RespawnTime) + #3 + InttoStr(Time - Player[Id].JoinTime) + #3 + InttoStr(Time - MapStartTime) + #3 + FormatDate('yy-mm-dd') + #3 + FormatDate('hh:nn:zzz') + #3 + CurrentMap;

I'll try to look into the 2nd issue today evening.
If you're not paying for something, you're not the customer; you're the product being sold.
- Andrew Lewis

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

Offline shay

  • Major(1)
  • Posts: 21
Re: Error in the script
« Reply #8 on: April 10, 2013, 01:12:24 pm »
Thank you for clarifying :)
I think also "Soldat Developer" for you is in the right place!

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: Error in the script
« Reply #9 on: April 10, 2013, 01:42:06 pm »
Ok, if i decoded your engrish correctly, you want to have only one trigger (!top, for instance) for all player/map/date stats. So I'd take one parameter which would be either player nickname, or map name, or date, all might be also either incomplete or partially invalid or, in case of date, in different format.
If that's the case then let me get this straight: this is going to be a hard task.
First, you'd have to parse player list and maplist (or even map directory) to guess which one player mean. But the player is just a human, and he could made a typo or write, for instance, incomplete map name. Parsing that requires some serious magic that although is doable in scriptcore (maybe with some external/dll help though), is still very hard to implement.

tl;dr: Not possible, forget it.
« Last Edit: April 10, 2013, 01:44:45 pm by FalconPL »
If you're not paying for something, you're not the customer; you're the product being sold.
- Andrew Lewis

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.