Author Topic: OnMapChange Invalid Float  (Read 1594 times)

0 Members and 2 Guests are viewing this topic.

Offline MrHamsTR

  • Soldier
  • **
  • Posts: 209
  • One day, everything will end..
OnMapChange Invalid Float
« on: June 06, 2013, 02:46:22 am »
What's that? (baka admin)

ctf_Ash by chakapoko maker
[Error] TopHNS -> (OnMapChange): Invalid float
ASE Port: 23156
Connection for file server started. Port: 23043
Registering server @ ASE Master Server
02:41:40 Registering server @ 67.23.118.179
Game server added to lobby server @ 67.23.118.179
02:42:23 /nextmap (192.168.1.2)
Next map: hamsrun
02:42:29 By Hamstr ~ First Try! Thanks Haste
[Error] TopHNS -> (OnMapChange): Invalid float
Is there anybody can write script?
Good, go and play soldat ^^

DarkCrusade

  • Guest
Re: OnMapChange Invalid Float
« Reply #1 on: June 06, 2013, 03:30:14 am »
Post the script TopHNS to this forum and we can see what's wrong.

Offline MrHamsTR

  • Soldier
  • **
  • Posts: 209
  • One day, everything will end..
Re: OnMapChange Invalid Float
« Reply #2 on: June 06, 2013, 03:41:54 am »
OK; Here

Code: [Select]
procedure OnMapChange(NewMap: String);
begin
addscorehns();
//Backup;
sleep(2);
Sortowanie(Database,0,ArrayHigh(Database));
sleep(2);
writeConsole(0, 'Yedekleme başarılı', RGB(132,112,255));
end;

procedure AppOnIdle(Ticks: integer);
begin
if (Ticks mod (60 * 140) = 0) then begin
//writeConsole(0, 'Oyuncu sıralaması icin !top ya da !stats yazın', RGB(255,255,0));
_SnapDatabase();
end;
if (Ticks mod (3600 * 120) = 0) then begin
Backup;
end;
////
//if Ticks mod (60 * 10) = 0 then begin //every 10 seconds
// GiveBonus(ID, 1); // pred mode
// end;
end;
« Last Edit: June 06, 2013, 03:45:05 am by MrHamsTR »
Is there anybody can write script?
Good, go and play soldat ^^

DarkCrusade

  • Guest
Re: OnMapChange Invalid Float
« Reply #3 on: June 06, 2013, 04:10:55 am »
Where is the procedure addscorehns()?

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: OnMapChange Invalid Float
« Reply #4 on: June 06, 2013, 06:46:09 am »
Why would you use sleeps? Also please post definition of Sortowanie().
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 MrHamsTR

  • Soldier
  • **
  • Posts: 209
  • One day, everything will end..
Re: OnMapChange Invalid Float
« Reply #5 on: June 06, 2013, 06:47:32 am »
I dont understand :/ what did you want say about "sleeps"?
Is there anybody can write script?
Good, go and play soldat ^^

Offline MrHamsTR

  • Soldier
  • **
  • Posts: 209
  • One day, everything will end..
Re: OnMapChange Invalid Float
« Reply #6 on: June 07, 2013, 05:22:31 am »
And guys, I dont know what is invalid float for issue but my BIOS battery doesnt work so my time and date isnt true. I guess float error is occurring due date and time?
Is there anybody can write script?
Good, go and play soldat ^^

Offline skrX

  • Soldier
  • **
  • Posts: 112
  • x ye.
Re: OnMapChange Invalid Float
« Reply #7 on: June 07, 2013, 07:55:53 am »
I see, most procedures are with script "stats & rank"

btw, check this code:

Code: [Select]
procedure AppOnIdle(Ticks: integer);
begin

if (Ticks mod (3600 * 2) = 0) then
begin
Sortowanie(Database,0,ArrayHigh(Database));
end;

if (Ticks mod (60 * 140) = 0) then
begin
{writeConsole(0, 'Oyuncu siralamasi icin !top ya da !stats yazin', RGB(255,255,0));}
_SnapDatabase();
end;

if (Ticks mod (3600 * 120) = 0) then
begin
Backup;
end;
{
if Ticks mod (60 * 10) = 0 then
begin
GiveBonus(ID, 1);
end; }

end;

procedure OnMapChange(NewMap: String);
begin
addscorehns();
Sortowanie(Database,0,ArrayHigh(Database));
writeConsole(0, 'Yedekleme başarili', RGB(132,112,255));
end;

If you want, delete this signs "{" "}"

Share this procedures:

Code: [Select]
Sortowanie
addscorehns();
« Last Edit: June 08, 2013, 07:49:54 am by skrX »

Offline MrHamsTR

  • Soldier
  • **
  • Posts: 209
  • One day, everything will end..
Re: OnMapChange Invalid Float
« Reply #8 on: June 07, 2013, 08:52:40 am »
ScriptCore v2.4 loaded! Found 7 scripts...
Compiling admin fun -> fun.PAS...
 Compiling default -> Core.pas...
Compiling default -> NetworkCore.pas...
 Compiling default -> AdminCore.pas...
Compiling HnS -> hns2.pas...
Compiling mapc -> mapc.pas...
Compiling otomsj -> otomsj.pas...
Compiling renkli -> colour.pas...
Compiling TopHNS -> StatsHNS.pas...
TopHNS -> [Hint] (571:10): Variable 'Result' never used
TopHNS -> [Error] (623:11): Duplicate identifier 'ONMAPCHANGE'
 Unable to find variable
 Shutting down server...
 Disconnected.
Is there anybody can write script?
Good, go and play soldat ^^

Offline dominikkk26

  • Camper
  • ***
  • Posts: 404
    • PMGsite
Re: OnMapChange Invalid Float
« Reply #9 on: June 08, 2013, 06:15:19 am »
You have used two procedures onmapchange.
You have to combine them or remove one of them.
« Last Edit: June 08, 2013, 06:18:02 am by dominikkk26 »

Offline MrHamsTR

  • Soldier
  • **
  • Posts: 209
  • One day, everything will end..
Re: OnMapChange Invalid Float
« Reply #10 on: June 08, 2013, 07:03:27 am »
You have used two procedures onmapchange.
You have to combine them or remove one of them.

Man code is here;

Code: [Select]
const
  FOLDER_DATABASE = 'DATA_PLAYERS/TOP/';
  NAME_DATABASE = 'statsHNS.txt';
  Players = 16;

var
RetID: integer;
RetValidar: integer;
RetCount: integer;

ultimovenc: byte;
  database : array of string;
  Exception: string;
  Kills,Deaths,Caps,SelfKills: array [1..Players] of Word;
  _FOLDER_DATABASE,_NAME_DATABASE:String;

procedure OnErrorOccur(const ERROR_MSG: string);
begin
  Exception:= ERROR_MSG;
end;

function Rnd(A:String):String;
var
Temp:Single;
begin
Temp:=StrToFloat(A)*1000;
Temp:=Round(Temp);
Result:=FloatToStr(Temp/1000);
end;

function Rnc(A:String):String;
var
Temp:Single;
begin
Temp:=StrToFloat(A)*100;
Temp:=Round(Temp);
Result:=FloatToStr(Temp);
end;

function IXSplit(Source: string; const Delimiter: string): array of string;
var
  Position, DelLength, ResLength: integer;
begin
  DelLength := Length(Delimiter);
  Source := Source + Delimiter;
  repeat
    Position := Pos(Delimiter, Source);
    SetArrayLength(Result, ResLength + 1);
    Result[ResLength] := Copy(Source, 1, Position - 1);
    ResLength := ResLength + 1;
    Delete(Source, 1, Position + DelLength - 1);
  until (Position = 0);
  SetArrayLength(Result, ResLength - 1);
end;

function ReadFromFile(File: string): string;
begin
  Result:= ReadFile(File);
  Result:= Copy(Result, 0, length(Result) - 2);
end;

function DoesFileExist(Name: string): boolean;
begin
  if (GetSystem() = 'windows') then
  begin
    if (FileExists(Name)) then
    begin
      result:= true;
    end;
  end else
  begin
    if ((FileExists(Name)) or (ReadFromFile(Name) <> '')) then
    begin
      result:= true;
    end;
  end;
end;

procedure _LoadDatabase();
begin
  if (DoesFileExist(_FOLDER_DATABASE + _NAME_DATABASE)) then
  begin
    database:= IXSplit(ReadFromFile(_FOLDER_DATABASE + _NAME_DATABASE), #13#10);
  end else
  begin
    WriteFile(_FOLDER_DATABASE + _NAME_DATABASE, '');
  end;
end;

procedure _SnapDatabase();
var
  i: integer;
  b: string;
begin
  for i:= 0 to GetArrayLength(database) - 1 do
  begin
    if (b <> '') then
    begin
      b:= b + #13#10 + database[i];
    end else
    begin
      b:= database[i];
    end;
  end;
  WriteFile(_FOLDER_DATABASE + _NAME_DATABASE, b);
end;

function _RowExists(RowID: integer): boolean;
begin
  result:= ArrayHigh(database) >= RowID;
end;

function _getColumnInfo(RowID, ColumnID: integer): integer;
var
  ch, x, tabs: integer;
  b: string;
begin
  tabs:= -1;
  b:= database[RowID];
  while (tabs <> ColumnID) do
  begin
    x:= StrPos(#9, b);
    if ((x = 0) and (tabs <> ColumnID)) then
    begin
      exit;
    end;
    Inc(tabs, 1);
    if (tabs = ColumnID) then
    begin
      result:= ch + 1;
      break;
    end else
    begin
      ch:= ch + x;
      Delete(b, 1, x);
    end;
  end;
end;

function GetTypeOF(Value: variant): string;
begin
  case VarType(Value) of
    3  : result:= IntToStr(Value);
    5  : result:= FloatToStr(Value);
    11 : result:= iif(Value, 'true', 'false');
    256: result:= Value;
    else result:= 'unknown Type';
  end;
end;

procedure _CreateRow(Columns: array of variant);
var
  i, x: integer;
begin
  SetArrayLength(database, GetArrayLength(database) + 1);
  x:= GetArrayLength(database) - 1;
  for i:= 0 to GetArrayLength(Columns) - 1 do
  begin
    database[x]:= database[x] + GetTypeOF(Columns[i]) + #9;
  end;
  _SnapDatabase();
end;

function _DeleteRow(RowID: integer): boolean;
var
  HIndex: integer;
begin
  if (_RowExists(RowID)) then
  begin
    HIndex:= GetArrayLength(database) - 1;
    if (RowID <> HIndex) then
    begin
      database[RowID]:= database[HIndex];
    end;
    SetArrayLength(database, iif(HIndex > 0, HIndex - 1, 0));
    _SnapDatabase();
    result:= true;
  end else
  begin
    OnErrorOccur('RowID ' + IntToStr(RowID) + ' does not exist');
  end;
end;

function _UpdateColumn(RowID, ColumnID: integer; Increase: extended): boolean;
var
  data, Sum: string;
  poz: integer;
begin
  if (_RowExists(RowID)) then
  begin
    poz:= _getColumnInfo(RowID, ColumnID);
    if (poz > 0) then
    begin
      data:= GetPiece(database[RowID], #9, ColumnID);
      if (RegExpMatch('^-?(\d+|\d+.?\d+)$', data)) then
      begin
        Sum:= FloatToStr(StrToFloat(data) + Increase);
        Delete(database[RowID], poz, length(data));
        Insert(Sum, database[RowID], poz);
        result:= true;
      end else
      begin
        OnErrorOccur('Column "' + IntToStr(ColumnID) + '" represents no numeric value');
      end;
    end else
    begin
      OnErrorOccur('ColumnID ' + IntToStr(ColumnID) + ' does not exist');
    end;
  end else
  begin
    OnErrorOccur('RowID ' + IntToStr(RowID) + ' does not exist');
  end;
end;

function _SetColumn(RowID, ColumnID: integer; Value: variant): boolean;
var
  poz: integer;
  data: string;
begin
  if (_RowExists(RowID)) then
  begin
    poz:= _getColumnInfo(RowID, ColumnID);
    if (poz > 0) then
    begin
      data:= GetPiece(database[RowID], #9, ColumnID);
      Delete(database[RowID], poz, length(data));
      Insert(GetTypeOF(Value), database[RowID], poz);
      result:= true;
    end else
    begin
      OnErrorOccur('ColumnID ' + IntToStr(ColumnID) + ' does not exist');
    end;
  end else
  begin
    OnErrorOccur('RowID ' + IntToStr(RowID) + ' does not exist');
  end;
end;

function _AppendColumn(RowID: integer; Value: variant): boolean;
begin
  if (_RowExists(RowID)) then
  begin
    database[RowID]:= database[RowID] + GetTypeOF(Value) + #9;
    result:= true;
  end else
  begin
    OnErrorOccur('RowID ' + IntToStr(RowID) + ' does not exist');
  end;
end;


procedure ActivateServer();
begin
_FOLDER_DATABASE:=FOLDER_DATABASE;
_NAME_DATABASE:=NAME_DATABASE;
_LoadDatabase();
RetValidar:= 0;
RetCount:= 0;

writeln('Script TopHNS compilado com sucesso!');

end;

Procedure Backup;
begin
_FOLDER_DATABASE:='temp/';
_NAME_DATABASE:='stats_'+FormatDate('yy-mm-dd hh-mm')+'.txt';
_SnapDatabase;
_NAME_DATABASE:=NAME_DATABASE;
_FOLDER_DATABASE:=FOLDER_DATABASE;
end;

procedure Sortowanie(var Field: array of string; Left, Right: integer);
var
  l, r: integer;
  Buffer: string;
  Pivot: Extended;
begin
  // Check whether there is at least more than one element to sort
  if (Left < Right) then
  begin
    l:= Left;
    r:= Right;
    // Pick the Pivot element
    Pivot:= StrToFloat(GetPiece(Field[(Left + Right) shr 1], #9, 1));
    // Presort
    repeat
      // Search an element which is smaller than the piviot
      while (StrToFloat(GetPiece(Field[l], #9, 1)) > Pivot) do
      begin
        Inc(l, 1);
      end;
      // Search an element which is greater than the pivot
      while (StrToFloat(GetPiece(Field[r], #9, 1)) < Pivot) do
      begin
        Dec(r, 1);
      end;
      // Swap the greater element with the smaller one
      if (l <= r) then
      begin
        Buffer:= Field[r];
        Field[r]:= Field[l];
        Field[l]:= Buffer;
        Inc(l, 1);
        Dec(r, 1);
      end;
    until (l >= r);
    if (Left < r) then
    begin
      Sortowanie(Field, Left, r);
    end;
    if (Right > l) then
    begin
      Sortowanie(Field, l, Right);
    end;
  end else
  begin
    exit;
  end;
end;


function IDByName(Name: string): byte;
var i: byte;
begin
result := 0;
for i := 1 to 32 do if getplayerstat(i,'active')=true then begin
if containsstring(lowercase(getplayerstat(i,'name')),lowercase(Name)) then begin
result := i;
break;
end;
end;
end;

function ConsultRowByPlayer(Name:String):longword;
var
i:Integer;
Found:Boolean;
begin
Found:=False;
For i:=0 to GetArrayLength(Database)-1 do begin
if ContainsString(lowercase(GetPiece(Database[i], #9, 0)),lowercase(Name)) = true then begin Found:=True; Result:=i; Break; end;
end;
end;




function GetRowByPlayer(Name:String):longword;
var
i:Integer;
Found:Boolean;
begin
Found:=False;
For i:=0 to GetArrayLength(Database)-1 do begin
if Name=GetPiece(Database[i], #9, 0) then begin Found:=True; Result:=i; Break; end;
end;
If Not Found then begin
Result:=GetArrayLength(Database);
_CreateRow([Name,'0','0','1']);
end;
end;

procedure SaveAllStats;
var
i:byte;
row:Longword;
Killss,Deathss,Capss:Word;
begin
for i:=1 to Players do begin
sleep(2);
If GetPlayerStat(I,'active')=True then begin
row:=GetRowByPlayer(IdToName(i));
Capss:=StrToInt(GetPiece(Database[Row], #9, 1));
Killss:=StrToInt(GetPiece(Database[Row], #9, 2))-1;
Deathss:=StrToInt(GetPiece(Database[Row], #9, 3))-1;
_SetColumn(Row, 2 , IntToStr(Killss+Kills[I]));
_SetColumn(Row, 3 , IntToStr(Deathss+Deaths[I]));
//_SetColumn(Row, 1 , Rnc(FloatToStr((Killss/Deathss*Killss)/100)));
_SetColumn(Row, 1 , IntToStr(Capss+Caps[I]));//////////////////////////////////////////
Kills[I]:=0;
Deaths[I]:=0;
Caps[I]:=0;
end;
end;
_SnapDatabase();
end;

procedure SaveStats(i:Byte);
var
row:Longword;
Killss,Deathss,Capss:Integer;
begin
row:=GetRowByPlayer(IdToName(i));
Capss:=StrToInt(GetPiece(Database[Row], #9, 1));
Killss:=StrToInt(GetPiece(Database[Row], #9, 2));
Deathss:=StrToInt(GetPiece(Database[Row], #9, 3));
_SetColumn(Row, 2 , IntToStr(Killss+Kills[I]));
_SetColumn(Row, 3 , IntToStr(Deathss+Deaths[I]));
//_SetColumn(Row, 1 , Rnc(FloatToStr((Killss/Deathss*Killss)/100)));
_SetColumn(Row, 1 , IntToStr(Capss+Caps[I]));//////////////////////////////////////////
Kills[I]:=0;
Deaths[I]:=0;
Caps[I]:=0;
end;

procedure addscorehns();
var
i:byte;
begin
for i:=1 to 32 do begin
if GetPlayerStat(i, 'team')=1 then begin
if ultimovenc = i then exit;
if Caps[i] <= 0 then begin
Caps[i]:= 0;
end;
Caps[i]:=Caps[i]+1;
SaveStats(i);
ultimovenc :=i;
//command('/say Adicionado 1 ponto ao vencedor!')
exit;
end;
end;
end;



Procedure ShowStatsQuickly(Id:Byte);
var
Row:Longword;
begin
Row:=GetRowByPlayer(IdToName(Id));
//DrawText(Id,'Sıra ' +IntToStr(Row+1)+ ' / ' +IntToStr(GetArrayLength(Database)),330,RGB(255,255,255),0.18,40,370);
WriteConsole(Id,'Sıra ' +IntToStr(Row+1)+ ' / ' +IntToStr(GetArrayLength(Database)),RGB(114,248,80));
WriteConsole(Id, 'Puan: '+ GetPiece(Database[Row], #9, 1), RGB(114,248,80));
end;

 //////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// KILL                                         ////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////

procedure OnPlayerKill(Killer, Victim: byte; Weapon: string);
begin
If (Killer<>Victim) and (GetPlayerStat(Killer,'Team')<>GetPlayerStat(Victim,'Team')) then begin
Kills[Killer]:=Kills[Killer]+1;
Deaths[Victim]:=Deaths[Victim]+1;
SaveStats(Killer);
SaveStats(Victim);
end;

end;

///////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// FLAG RETURN!!                               /////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
procedure OnFlagReturn(ID, TeamFlag: byte);
begin
// RetID := ID;
// RetValidar:= 1;
// RetCount:=6;
end;


procedure OnLeaveGame(ID, Team: byte;Kicked: boolean);
begin
end;


Procedure ShowStats(Id:Byte);
var
Row:Longword;
begin
Row:=GetRowByPlayer(IdToName(Id));
DrawText(Id,'Sıra ' +IntToStr(Row+1)+ ' toplam ' +IntToStr(GetArrayLength(Database)),330, RGB(255,255,255),0.18,40,370);
WriteConsole(Id, '    ', RGB(220,220,220));
sleep(2);
WriteConsole(Id, ' Oyuncu ' + IdToName(Id) + ' Durum:',RGB(220,220,220));
sleep(2);
WriteConsole(Id, ' --------------------------------------------------',RGB(220,220,220));
sleep(2);
WriteConsole(Id, ' Sıra: '+ IntToStr(Row+1)+ 'º toplam '+ IntToStr(GetArrayLength(Database)), RGB(220,220,220));
sleep(2);
WriteConsole(Id, ' *Puan: '+ GetPiece(Database[Row], #9, 1), RGB(255,255,0));
sleep(2);
WriteConsole(Id, ' Oldurme: '+ GetPiece(Database[Row], #9, 2) + ' kez', RGB(173,255,47));
sleep(2);
WriteConsole(Id, ' Oldurulme: '+ GetPiece(Database[Row], #9, 3) + ' kez', RGB(173,255,47));
//sleep(2);
//WriteConsole(Id, ' Sonuc: '+ Rnd(FloatToStr(StrToFloat(GetPiece(Database[Row], #9, 2))/StrToFloat(GetPiece(Database[Row], #9, 3)))) + ' (1=Regular, 1.5=Bom, 2+=Excelente)', RGB(255,248,80));
sleep(2);
WriteConsole(Id, '   ', RGB(220,220,220));

//WriteConsole(ID,' ---------------------',RGB(114,248,80));
end;

procedure ShowTop10(Id:byte);
var
i:byte;
begin
WriteConsole(Id, ' ',RGB(220,220,220));
WriteConsole(Id, '--------------------------------------------------', RGB(220,220,220));
sleep(2);
WriteConsole(Id, 'Top 20 players no HIDE N SEEK:',RGB(114,248,80));
sleep(2);
WriteConsole(Id, '--------------------------------------------------', RGB(220,220,220));
sleep(2);
For i:=0 to iif(GetArrayLength(Database)>20,19,GetArrayLength(Database)-1) do begin
If i<9 then WriteConsole(Id, IntToStr(i+1)+'  - '+GetPiece(Database[i], #9, 0)+' = '+GetPiece(Database[i], #9, 1)+' Puan',RGB(255,255,0)); //, RGB(100,255,80));
If i>=9 then WriteConsole(Id, IntToStr(i+1)+' - '+GetPiece(Database[i], #9, 0)+' = '+GetPiece(Database[i], #9, 1)+' Puan',RGB(255,255,0)); //, RGB(100,255,80));
sleep(2);
end;
end;

 ///////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////    SPEAK                                     /////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
procedure OnPlayerSpeak(ID: Byte; Text: string);
var
ranks:string;
Row:Longword;
begin
//Row := " "
if (Text = '!stats') or (Text = '!Stats') or (Text = '!STATS') or (Text = '!Rank') or (Text = '!rank') or (Text = '!RANK') then ShowStats(ID);
if regExpMatch('^!(top|top20)$', Text) then ShowTop10(ID);
if (MaskCheck(Text,'!stats *')) then begin
ranks := GetPiece(Text,'!stats ',1);
//Row := GetRowByPlayer(ranks);
Row := ConsultRowByPlayer(ranks);
WriteConsole(ID, '   ', RGB(220,220,220));
WriteConsole(ID, ' Sonuç: '  +IntToStr(Row+1) + 'º = ' +GetPiece(Database[Row], #9, 0), RGB(220,220,220));
//Row:=GetRowByPlayer(IdToName(Id))
//if Row <> " " then begin
//DrawText(Id,'Rank ' +IntToStr(Row+1)+ ' / ' +IntToStr(GetArrayLength(Database)),330,RGB(255,255,255),0.18,40,370);

if GetPiece(Database[Row], #9, 0) = '0' then begin
WriteConsole(ID, 'Oyuncu bulanamadı...',RGB(255,88,80));
end else
begin
DrawText(ID,' Sıra ' +IntToStr(Row+1)+ ' toplam ' +IntToStr(GetArrayLength(Database)),330, RGB(255,255,255),0.18,40,370);
sleep(2);
WriteConsole(ID, '   ', RGB(220,220,220));
sleep(2);
WriteConsole(ID, ' Oyuncu ' + GetPiece(Database[Row], #9, 0) + ' Hide and SEEK:',RGB(220,220,220));
sleep(2);
WriteConsole(ID, ' --------------------------------------------------',RGB(220,220,220));
sleep(2);
WriteConsole(ID, ' Sıra: '+ IntToStr(Row+1)+ 'º toplam '+ IntToStr(GetArrayLength(Database)), RGB(220,220,220));
sleep(2);
WriteConsole(ID, ' *Puan: '+ GetPiece(Database[Row], #9, 1), RGB(255,255,0));
sleep(2);
WriteConsole(ID, ' Oldurme: '+ GetPiece(Database[Row], #9, 2) + ' kez', RGB(173,255,47));
sleep(2);
WriteConsole(ID, ' Oldurulme: '+ GetPiece(Database[Row], #9, 3) + ' kez', RGB(173,255,47));
sleep(2);
//WriteConsole(ID, ' Sonuc: '+ Rnd(FloatToStr(StrToFloat(GetPiece(Database[Row], #9, 2))/StrToFloat(GetPiece(Database[Row], #9, 3)))) + ' (1=Regular, 1.5=Bom, 2+=Excelente)', RGB(255,248,80));
//sleep(2);
WriteConsole(ID, '   ', RGB(220,220,220));

//WriteConsole(ID,' ---------------------',RGB(114,248,80));
end;
end;

end;

///////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////    COMANDOS                                 /////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
function OnCommand(ID: Byte; Text: string): boolean;
begin
if lowercase(Text) = '/backup' then begin
writeConsole(ID, 'Yedekleme başarılı',RGB(132,112,255));
Backup;
end;
if lowercase(Text) = '/organizar' then begin
writeConsole(ID, 'Classificando players',RGB(255,165,0));
Sortowanie(Database,0,ArrayHigh(Database));
end;

end;

///////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// MAP                                         /////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
procedure OnMapChange(NewMap: String);
begin
addscorehns();
//Backup;
sleep(2);
Sortowanie(Database,0,ArrayHigh(Database));
sleep(2);
writeConsole(0, 'Yedekleme başarılı', RGB(132,112,255));
end;

procedure AppOnIdle(Ticks: integer);
begin
if (Ticks mod (60 * 140) = 0) then begin
//writeConsole(0, 'Sıralama icin !stats ve !top yazın', RGB(255,255,0));
_SnapDatabase();
end;
if (Ticks mod (3600 * 120) = 0) then begin
Backup;
end;
////
//if Ticks mod (60 * 10) = 0 then begin //cada 10 segundos
// GiveBonus(ID, 1); // modo pred
// end;
end;
« Last Edit: June 08, 2013, 07:07:12 am by MrHamsTR »
Is there anybody can write script?
Good, go and play soldat ^^

Offline skrX

  • Soldier
  • **
  • Posts: 112
  • x ye.
Re: OnMapChange Invalid Float
« Reply #11 on: June 08, 2013, 07:49:31 am »
You added this
Code: [Select]
sleep(2);??? ?

big mess in the script
« Last Edit: June 08, 2013, 07:51:08 am by skrX »

Offline MrHamsTR

  • Soldier
  • **
  • Posts: 209
  • One day, everything will end..
Re: OnMapChange Invalid Float
« Reply #12 on: June 08, 2013, 08:23:42 am »
to where :(
code is here;

Code: [Select]
const
  FOLDER_DATABASE = 'DATA_PLAYERS/TOP/';
  NAME_DATABASE = 'statsHNS.txt';
  Players = 16;

var
RetID: integer;
RetValidar: integer;
RetCount: integer;

ultimovenc: byte;
  database : array of string;
  Exception: string;
  Kills,Deaths,Caps,SelfKills: array [1..Players] of Word;
  _FOLDER_DATABASE,_NAME_DATABASE:String;

procedure OnErrorOccur(const ERROR_MSG: string);
begin
  Exception:= ERROR_MSG;
end;

function Rnd(A:String):String;
var
Temp:Single;
begin
Temp:=StrToFloat(A)*1000;
Temp:=Round(Temp);
Result:=FloatToStr(Temp/1000);
end;

function Rnc(A:String):String;
var
Temp:Single;
begin
Temp:=StrToFloat(A)*100;
Temp:=Round(Temp);
Result:=FloatToStr(Temp);
end;

function IXSplit(Source: string; const Delimiter: string): array of string;
var
  Position, DelLength, ResLength: integer;
begin
  DelLength := Length(Delimiter);
  Source := Source + Delimiter;
  repeat
    Position := Pos(Delimiter, Source);
    SetArrayLength(Result, ResLength + 1);
    Result[ResLength] := Copy(Source, 1, Position - 1);
    ResLength := ResLength + 1;
    Delete(Source, 1, Position + DelLength - 1);
  until (Position = 0);
  SetArrayLength(Result, ResLength - 1);
end;

function ReadFromFile(File: string): string;
begin
  Result:= ReadFile(File);
  Result:= Copy(Result, 0, length(Result) - 2);
end;

function DoesFileExist(Name: string): boolean;
begin
  if (GetSystem() = 'windows') then
  begin
    if (FileExists(Name)) then
    begin
      result:= true;
    end;
  end else
  begin
    if ((FileExists(Name)) or (ReadFromFile(Name) <> '')) then
    begin
      result:= true;
    end;
  end;
end;

procedure _LoadDatabase();
begin
  if (DoesFileExist(_FOLDER_DATABASE + _NAME_DATABASE)) then
  begin
    database:= IXSplit(ReadFromFile(_FOLDER_DATABASE + _NAME_DATABASE), #13#10);
  end else
  begin
    WriteFile(_FOLDER_DATABASE + _NAME_DATABASE, '');
  end;
end;

procedure _SnapDatabase();
var
  i: integer;
  b: string;
begin
  for i:= 0 to GetArrayLength(database) - 1 do
  begin
    if (b <> '') then
    begin
      b:= b + #13#10 + database[i];
    end else
    begin
      b:= database[i];
    end;
  end;
  WriteFile(_FOLDER_DATABASE + _NAME_DATABASE, b);
end;

function _RowExists(RowID: integer): boolean;
begin
  result:= ArrayHigh(database) >= RowID;
end;

function _getColumnInfo(RowID, ColumnID: integer): integer;
var
  ch, x, tabs: integer;
  b: string;
begin
  tabs:= -1;
  b:= database[RowID];
  while (tabs <> ColumnID) do
  begin
    x:= StrPos(#9, b);
    if ((x = 0) and (tabs <> ColumnID)) then
    begin
      exit;
    end;
    Inc(tabs, 1);
    if (tabs = ColumnID) then
    begin
      result:= ch + 1;
      break;
    end else
    begin
      ch:= ch + x;
      Delete(b, 1, x);
    end;
  end;
end;

function GetTypeOF(Value: variant): string;
begin
  case VarType(Value) of
    3  : result:= IntToStr(Value);
    5  : result:= FloatToStr(Value);
    11 : result:= iif(Value, 'true', 'false');
    256: result:= Value;
    else result:= 'unknown Type';
  end;
end;

procedure _CreateRow(Columns: array of variant);
var
  i, x: integer;
begin
  SetArrayLength(database, GetArrayLength(database) + 1);
  x:= GetArrayLength(database) - 1;
  for i:= 0 to GetArrayLength(Columns) - 1 do
  begin
    database[x]:= database[x] + GetTypeOF(Columns[i]) + #9;
  end;
  _SnapDatabase();
end;

function _DeleteRow(RowID: integer): boolean;
var
  HIndex: integer;
begin
  if (_RowExists(RowID)) then
  begin
    HIndex:= GetArrayLength(database) - 1;
    if (RowID <> HIndex) then
    begin
      database[RowID]:= database[HIndex];
    end;
    SetArrayLength(database, iif(HIndex > 0, HIndex - 1, 0));
    _SnapDatabase();
    result:= true;
  end else
  begin
    OnErrorOccur('RowID ' + IntToStr(RowID) + ' does not exist');
  end;
end;

function _UpdateColumn(RowID, ColumnID: integer; Increase: extended): boolean;
var
  data, Sum: string;
  poz: integer;
begin
  if (_RowExists(RowID)) then
  begin
    poz:= _getColumnInfo(RowID, ColumnID);
    if (poz > 0) then
    begin
      data:= GetPiece(database[RowID], #9, ColumnID);
      if (RegExpMatch('^-?(\d+|\d+.?\d+)$', data)) then
      begin
        Sum:= FloatToStr(StrToFloat(data) + Increase);
        Delete(database[RowID], poz, length(data));
        Insert(Sum, database[RowID], poz);
        result:= true;
      end else
      begin
        OnErrorOccur('Column "' + IntToStr(ColumnID) + '" represents no numeric value');
      end;
    end else
    begin
      OnErrorOccur('ColumnID ' + IntToStr(ColumnID) + ' does not exist');
    end;
  end else
  begin
    OnErrorOccur('RowID ' + IntToStr(RowID) + ' does not exist');
  end;
end;

function _SetColumn(RowID, ColumnID: integer; Value: variant): boolean;
var
  poz: integer;
  data: string;
begin
  if (_RowExists(RowID)) then
  begin
    poz:= _getColumnInfo(RowID, ColumnID);
    if (poz > 0) then
    begin
      data:= GetPiece(database[RowID], #9, ColumnID);
      Delete(database[RowID], poz, length(data));
      Insert(GetTypeOF(Value), database[RowID], poz);
      result:= true;
    end else
    begin
      OnErrorOccur('ColumnID ' + IntToStr(ColumnID) + ' does not exist');
    end;
  end else
  begin
    OnErrorOccur('RowID ' + IntToStr(RowID) + ' does not exist');
  end;
end;

function _AppendColumn(RowID: integer; Value: variant): boolean;
begin
  if (_RowExists(RowID)) then
  begin
    database[RowID]:= database[RowID] + GetTypeOF(Value) + #9;
    result:= true;
  end else
  begin
    OnErrorOccur('RowID ' + IntToStr(RowID) + ' does not exist');
  end;
end;


procedure ActivateServer();
begin
_FOLDER_DATABASE:=FOLDER_DATABASE;
_NAME_DATABASE:=NAME_DATABASE;
_LoadDatabase();
RetValidar:= 0;
RetCount:= 0;

writeln('Script TopHNS compilado com sucesso!');

end;

Procedure Backup;
begin
_FOLDER_DATABASE:='temp/';
_NAME_DATABASE:='stats_'+FormatDate('yy-mm-dd hh-mm')+'.txt';
_SnapDatabase;
_NAME_DATABASE:=NAME_DATABASE;
_FOLDER_DATABASE:=FOLDER_DATABASE;
end;

procedure Sortowanie(var Field: array of string; Left, Right: integer);
var
  l, r: integer;
  Buffer: string;
  Pivot: Extended;
begin
  // Check whether there is at least more than one element to sort
  if (Left < Right) then
  begin
    l:= Left;
    r:= Right;
    // Pick the Pivot element
    Pivot:= StrToFloat(GetPiece(Field[(Left + Right) shr 1], #9, 1));
    // Presort
    repeat
      // Search an element which is smaller than the piviot
      while (StrToFloat(GetPiece(Field[l], #9, 1)) > Pivot) do
      begin
        Inc(l, 1);
      end;
      // Search an element which is greater than the pivot
      while (StrToFloat(GetPiece(Field[r], #9, 1)) < Pivot) do
      begin
        Dec(r, 1);
      end;
      // Swap the greater element with the smaller one
      if (l <= r) then
      begin
        Buffer:= Field[r];
        Field[r]:= Field[l];
        Field[l]:= Buffer;
        Inc(l, 1);
        Dec(r, 1);
      end;
    until (l >= r);
    if (Left < r) then
    begin
      Sortowanie(Field, Left, r);
    end;
    if (Right > l) then
    begin
      Sortowanie(Field, l, Right);
    end;
  end else
  begin
    exit;
  end;
end;


function IDByName(Name: string): byte;
var i: byte;
begin
result := 0;
for i := 1 to 32 do if getplayerstat(i,'active')=true then begin
if containsstring(lowercase(getplayerstat(i,'name')),lowercase(Name)) then begin
result := i;
break;
end;
end;
end;

function ConsultRowByPlayer(Name:String):longword;
var
i:Integer;
Found:Boolean;
begin
Found:=False;
For i:=0 to GetArrayLength(Database)-1 do begin
if ContainsString(lowercase(GetPiece(Database[i], #9, 0)),lowercase(Name)) = true then begin Found:=True; Result:=i; Break; end;
end;
end;




function GetRowByPlayer(Name:String):longword;
var
i:Integer;
Found:Boolean;
begin
Found:=False;
For i:=0 to GetArrayLength(Database)-1 do begin
if Name=GetPiece(Database[i], #9, 0) then begin Found:=True; Result:=i; Break; end;
end;
If Not Found then begin
Result:=GetArrayLength(Database);
_CreateRow([Name,'0','0','1']);
end;
end;

procedure SaveAllStats;
var
i:byte;
row:Longword;
Killss,Deathss,Capss:Word;
begin
for i:=1 to Players do begin
sleep(2);
If GetPlayerStat(I,'active')=True then begin
row:=GetRowByPlayer(IdToName(i));
Capss:=StrToInt(GetPiece(Database[Row], #9, 1));
Killss:=StrToInt(GetPiece(Database[Row], #9, 2))-1;
Deathss:=StrToInt(GetPiece(Database[Row], #9, 3))-1;
_SetColumn(Row, 2 , IntToStr(Killss+Kills[I]));
_SetColumn(Row, 3 , IntToStr(Deathss+Deaths[I]));
//_SetColumn(Row, 1 , Rnc(FloatToStr((Killss/Deathss*Killss)/100)));
_SetColumn(Row, 1 , IntToStr(Capss+Caps[I]));//////////////////////////////////////////
Kills[I]:=0;
Deaths[I]:=0;
Caps[I]:=0;
end;
end;
_SnapDatabase();
end;

procedure SaveStats(i:Byte);
var
row:Longword;
Killss,Deathss,Capss:Integer;
begin
row:=GetRowByPlayer(IdToName(i));
Capss:=StrToInt(GetPiece(Database[Row], #9, 1));
Killss:=StrToInt(GetPiece(Database[Row], #9, 2));
Deathss:=StrToInt(GetPiece(Database[Row], #9, 3));
_SetColumn(Row, 2 , IntToStr(Killss+Kills[I]));
_SetColumn(Row, 3 , IntToStr(Deathss+Deaths[I]));
//_SetColumn(Row, 1 , Rnc(FloatToStr((Killss/Deathss*Killss)/100)));
_SetColumn(Row, 1 , IntToStr(Capss+Caps[I]));//////////////////////////////////////////
Kills[I]:=0;
Deaths[I]:=0;
Caps[I]:=0;
end;

procedure addscorehns();
var
i:byte;
begin
for i:=1 to 32 do begin
if GetPlayerStat(i, 'team')=1 then begin
if ultimovenc = i then exit;
if Caps[i] <= 0 then begin
Caps[i]:= 0;
end;
Caps[i]:=Caps[i]+1;
SaveStats(i);
ultimovenc :=i;
//command('/say Adicionado 1 ponto ao vencedor!')
exit;
end;
end;
end;



Procedure ShowStatsQuickly(Id:Byte);
var
Row:Longword;
begin
Row:=GetRowByPlayer(IdToName(Id));
//DrawText(Id,'Sıra ' +IntToStr(Row+1)+ ' / ' +IntToStr(GetArrayLength(Database)),330,RGB(255,255,255),0.18,40,370);
WriteConsole(Id,'Sıra ' +IntToStr(Row+1)+ ' / ' +IntToStr(GetArrayLength(Database)),RGB(114,248,80));
WriteConsole(Id, 'Puan: '+ GetPiece(Database[Row], #9, 1), RGB(114,248,80));
end;

 //////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// KILL                                         ////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////

procedure OnPlayerKill(Killer, Victim: byte; Weapon: string);
begin
If (Killer<>Victim) and (GetPlayerStat(Killer,'Team')<>GetPlayerStat(Victim,'Team')) then begin
Kills[Killer]:=Kills[Killer]+1;
Deaths[Victim]:=Deaths[Victim]+1;
SaveStats(Killer);
SaveStats(Victim);
end;

end;

///////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// FLAG RETURN!!                               /////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
procedure OnFlagReturn(ID, TeamFlag: byte);
begin
// RetID := ID;
// RetValidar:= 1;
// RetCount:=6;
end;


procedure OnLeaveGame(ID, Team: byte;Kicked: boolean);
begin
end;


Procedure ShowStats(Id:Byte);
var
Row:Longword;
begin
Row:=GetRowByPlayer(IdToName(Id));
DrawText(Id,'Sıra ' +IntToStr(Row+1)+ ' toplam ' +IntToStr(GetArrayLength(Database)),330, RGB(255,255,255),0.18,40,370);
WriteConsole(Id, '    ', RGB(220,220,220));
sleep(2);
WriteConsole(Id, ' Oyuncu ' + IdToName(Id) + ' Durum:',RGB(220,220,220));
sleep(2);
WriteConsole(Id, ' --------------------------------------------------',RGB(220,220,220));
sleep(2);
WriteConsole(Id, ' Sıra: '+ IntToStr(Row+1)+ 'º toplam '+ IntToStr(GetArrayLength(Database)), RGB(220,220,220));
sleep(2);
WriteConsole(Id, ' *Puan: '+ GetPiece(Database[Row], #9, 1), RGB(255,255,0));
sleep(2);
WriteConsole(Id, ' Oldurme: '+ GetPiece(Database[Row], #9, 2) + ' kez', RGB(173,255,47));
sleep(2);
WriteConsole(Id, ' Oldurulme: '+ GetPiece(Database[Row], #9, 3) + ' kez', RGB(173,255,47));
//sleep(2);
//WriteConsole(Id, ' Sonuc: '+ Rnd(FloatToStr(StrToFloat(GetPiece(Database[Row], #9, 2))/StrToFloat(GetPiece(Database[Row], #9, 3)))) + ' (1=Regular, 1.5=Bom, 2+=Excelente)', RGB(255,248,80));
sleep(2);
WriteConsole(Id, '   ', RGB(220,220,220));

//WriteConsole(ID,' ---------------------',RGB(114,248,80));
end;

procedure ShowTop10(Id:byte);
var
i:byte;
begin
WriteConsole(Id, ' ',RGB(220,220,220));
WriteConsole(Id, '--------------------------------------------------', RGB(220,220,220));
sleep(2);
WriteConsole(Id, 'Top 20 players no HIDE N SEEK:',RGB(114,248,80));
sleep(2);
WriteConsole(Id, '--------------------------------------------------', RGB(220,220,220));
sleep(2);
For i:=0 to iif(GetArrayLength(Database)>20,19,GetArrayLength(Database)-1) do begin
If i<9 then WriteConsole(Id, IntToStr(i+1)+'  - '+GetPiece(Database[i], #9, 0)+' = '+GetPiece(Database[i], #9, 1)+' Puan',RGB(255,255,0)); //, RGB(100,255,80));
If i>=9 then WriteConsole(Id, IntToStr(i+1)+' - '+GetPiece(Database[i], #9, 0)+' = '+GetPiece(Database[i], #9, 1)+' Puan',RGB(255,255,0)); //, RGB(100,255,80));
sleep(2);
end;
end;

 ///////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////    SPEAK                                     /////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
procedure OnPlayerSpeak(ID: Byte; Text: string);
var
ranks:string;
Row:Longword;
begin
//Row := " "
if (Text = '!stats') or (Text = '!Stats') or (Text = '!STATS') or (Text = '!Rank') or (Text = '!rank') or (Text = '!RANK') then ShowStats(ID);
if regExpMatch('^!(top|top20)$', Text) then ShowTop10(ID);
if (MaskCheck(Text,'!stats *')) then begin
ranks := GetPiece(Text,'!stats ',1);
//Row := GetRowByPlayer(ranks);
Row := ConsultRowByPlayer(ranks);
WriteConsole(ID, '   ', RGB(220,220,220));
WriteConsole(ID, ' Sonuç: '  +IntToStr(Row+1) + 'º = ' +GetPiece(Database[Row], #9, 0), RGB(220,220,220));
//Row:=GetRowByPlayer(IdToName(Id))
//if Row <> " " then begin
//DrawText(Id,'Rank ' +IntToStr(Row+1)+ ' / ' +IntToStr(GetArrayLength(Database)),330,RGB(255,255,255),0.18,40,370);

if GetPiece(Database[Row], #9, 0) = '0' then begin
WriteConsole(ID, 'Oyuncu bulanamadı...',RGB(255,88,80));
end else
begin
DrawText(ID,' Sıra ' +IntToStr(Row+1)+ ' toplam ' +IntToStr(GetArrayLength(Database)),330, RGB(255,255,255),0.18,40,370);
sleep(2);
WriteConsole(ID, '   ', RGB(220,220,220));
sleep(2);
WriteConsole(ID, ' Oyuncu ' + GetPiece(Database[Row], #9, 0) + ' Hide and SEEK:',RGB(220,220,220));
sleep(2);
WriteConsole(ID, ' --------------------------------------------------',RGB(220,220,220));
sleep(2);
WriteConsole(ID, ' Sıra: '+ IntToStr(Row+1)+ 'º toplam '+ IntToStr(GetArrayLength(Database)), RGB(220,220,220));
sleep(2);
WriteConsole(ID, ' *Puan: '+ GetPiece(Database[Row], #9, 1), RGB(255,255,0));
sleep(2);
WriteConsole(ID, ' Oldurme: '+ GetPiece(Database[Row], #9, 2) + ' kez', RGB(173,255,47));
sleep(2);
WriteConsole(ID, ' Oldurulme: '+ GetPiece(Database[Row], #9, 3) + ' kez', RGB(173,255,47));
sleep(2);
//WriteConsole(ID, ' Sonuc: '+ Rnd(FloatToStr(StrToFloat(GetPiece(Database[Row], #9, 2))/StrToFloat(GetPiece(Database[Row], #9, 3)))) + ' (1=Regular, 1.5=Bom, 2+=Excelente)', RGB(255,248,80));
//sleep(2);
WriteConsole(ID, '   ', RGB(220,220,220));

//WriteConsole(ID,' ---------------------',RGB(114,248,80));
end;
end;

end;

///////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////    COMANDOS                                 /////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
function OnCommand(ID: Byte; Text: string): boolean;
begin
if lowercase(Text) = '/backup' then begin
writeConsole(ID, 'Yedekleme başarılı',RGB(132,112,255));
Backup;
end;
if lowercase(Text) = '/organizar' then begin
writeConsole(ID, 'Classificando players',RGB(255,165,0));
Sortowanie(Database,0,ArrayHigh(Database));
end;

end;

///////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// MAP                                         /////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
procedure OnMapChange(NewMap: String);
begin
addscorehns();
//Backup;
sleep(2);
Sortowanie(Database,0,ArrayHigh(Database));
sleep(2);
writeConsole(0, 'Yedekleme başarılı', RGB(132,112,255));
end;

procedure AppOnIdle(Ticks: integer);
begin
if (Ticks mod (60 * 140) = 0) then begin
//writeConsole(0, 'Sıralama icin !stats ve !top yazın', RGB(255,255,0));
_SnapDatabase();
end;
if (Ticks mod (3600 * 120) = 0) then begin
Backup;
end;
////
//if Ticks mod (60 * 10) = 0 then begin //cada 10 segundos
// GiveBonus(ID, 1); // modo pred
// end;
end;
« Last Edit: June 08, 2013, 10:53:55 am by MrHamsTR »
Is there anybody can write script?
Good, go and play soldat ^^