0 Members and 1 Guest are viewing this topic.
unit ServerVisit;interfaceimplementationconst Patch = 'database.db'; DisplayTime = 1; //Valute in miniutesvar Today, Week: string; database: TStringList;procedure LoadDatabase();begin if (File.Exists(Patch)) then database := File.CreateStringListFromFile(Patch) else begin database := File.CreateStringList(); database.Append('Today 0'); database.Append('Week '+Week+' 0'); database.Append('Total 0'); database.SaveToFile(Patch); end;end;procedure OnDateCheck();var CurrTim: TDateTime;begin CurrTim := date(); if (Today <> FormatDateTime('dddd',CurrTim)) then begin database[0] := 'Today 0'; Today := FormatDateTime('dddd',CurrTim); if (Today = GetPiece(GetPiece(database[1],' ', 1),' ', 0)) then database[1] := 'Week '+Week+' 0'; database.SaveToFile(Patch); end;end;function FillWith(const Filler: char; Amount: integer): string;var i: integer;begin for i:= 1 to Amount do Result:= Result + Filler;end;procedure CreateBox(const Headline: string; const BorderStyleX, BorderStyleY, CornerStyle: char; const Content: array of string; BorderColor: longint); //By Dominikvar i, MaxSize, len_Headline: integer;begin len_Headline:= length(Headline); MaxSize := len_HeadLine; for i:= 0 to ArrayHigh(Content) do if (length(Content[i]) > MaxSize) then MaxSize:= length(Content[i]); if ((MaxSize - len_Headline) mod 2 = 1) then MaxSize := MaxSize+1; Players.WriteConsole(CornerStyle + FillWith(BorderStyleX, (MaxSize - len_Headline) div 2) + Headline + FillWith(BorderStyleX, (MaxSize - len_Headline) div 2) + CornerStyle, BorderColor); for i:= 0 to GetArrayLength(Content) - 1 do Players.WriteConsole(BorderStyleY + Content[i] + FillWith(' ', MaxSize - length(Content[i])) + BorderStyleY, BorderColor - ((i + 1) * 25)); Players.WriteConsole(CornerStyle + FillWith(BorderStyleX, MaxSize) + CornerStyle, BorderColor - ((i + 1) * 25));end;procedure Timers(Ticks: integer);var Visits: array [0..2] of string;begin if (Ticks mod (3600 * DisplayTime) = 0) then begin OnDateCheck(); Visits[0]:= 'Today : '+GetPiece(database[0],' ', 1); Visits[1]:= 'This week: '+GetPiece(database[1],' ', 2); Visits[2]:= 'Over-all : '+GetPiece(database[2],' ', 1); CreateBox('_ Server Visits _', '_', '|', '.', Visits, $23DBDB) end;end;procedure JoinGame(Player: TActivePlayer; Team: TTeam);begin database[0] := 'Today '+inttostr(strtoint(GetPiece(database[0],' ',1))+1); database[1] := 'Week '+Week+' '+inttostr(strtoint(GetPiece(database[1],' ',2))+1); database[2] := 'Total '+inttostr(strtoint(GetPiece(database[2],' ',1))+1); database.SaveToFile(Patch);end;procedure ScriptDecl();begin Game.OnJoin := @JoinGame; Game.OnClockTick := @Timers;end;procedure ScriptRecompile();var CurrTim: TDateTime;begin Week := FormatDateTime('dddd',42911); LoadDatabase(); CurrTim:=date(); Today := FormatDateTime('dddd',CurrTim);end;initializationbegin ScriptDecl(); ScriptRecompile();end;finalization;end.
unit ServerVisit;interfaceimplementationconst Path = '\data\database.db'; Display_Time = 83; //Valute in seconds Base_Color = $F48FB1; //Default $23DBDB; Color_Mixer = 25; //Default 25var database: TStringList;procedure LoadDatabase();begin if File.Exists(Script.Dir+Path) then database := File.CreateStringListFromFile(Script.Dir+Path) else begin database := File.CreateStringList(); database.Append(FormatDateTime('dddd',42911)); database.Append(FormatDateTime('yyyy',date())); database.Append(FormatDateTime('mmmm',date())); database.Append(FormatDateTime('dddd',date())); database.Append('0'); //Today index 4 database.Append('0'); //This week database.Append('0'); //This month database.Append('0'); //This year database.Append('0'); //Total database.SaveToFile(Script.Dir+Path); end;end;procedure OnDateCheck();var New_Data: string;begin New_Data := FormatDateTime('dddd', date()); if database[3] <> New_Data then begin database[3] := New_Data; database[4] := '0'; if database[0] = New_Data then database[5] := '0'; New_Data := FormatDateTime('mmmm', date()); if database[2] <> New_Data then begin database[2] := New_Data; database[6] := '0'; New_Data := FormatDateTime('yyyy', date()); if database[1] <> New_Data then begin database[1] := New_Data; database[7] := '0'; end; end; database.SaveToFile(Script.Dir+Path); end;end;function FillWith(const Filler: char; Amount: integer): string;var i: integer;begin for i:= 1 to Amount do Result:= Result + Filler;end;procedure CreateBox(const Headline: string; const BorderStyleX, BorderStyleY, CornerStyle: char; const Content: TStringList; BorderColor: longint); //By Dominikvar i, MaxSize, len_Headline, Temp_Len: integer;begin len_Headline:= length(Headline); MaxSize := len_HeadLine; for i := 4 to 8 do case i of 0: begin Temp_Len := length('Today : '+Content[i+4]); if Temp_Len > MaxSize then MaxSize:= Temp_Len; end; 1: begin Temp_Len := length('This week : '+Content[i+4]); if Temp_Len > MaxSize then MaxSize:= Temp_Len; end; 2: begin Temp_Len := length('This month: '+Content[i+4]); if Temp_Len > MaxSize then MaxSize:= Temp_Len; end; 3: begin Temp_Len := length('This year : '+Content[i+4]); if Temp_Len > MaxSize then MaxSize:= Temp_Len; end; 4: begin Temp_Len := length('Over-all : '+Content[i+4]); if Temp_Len > MaxSize then MaxSize:= Temp_Len; end; end; if (MaxSize - len_Headline) mod 2 = 1 then inc(MaxSize, 1); Players.WriteConsole(CornerStyle + FillWith(BorderStyleX, (MaxSize - len_Headline) div 2) + Headline + FillWith(BorderStyleX, (MaxSize - len_Headline) div 2) + CornerStyle, BorderColor); for i := 0 to 4 do begin Temp_Len := i + 4; case i of 0: Players.WriteConsole(BorderStyleY + 'Today : ' + Content[Temp_Len] + FillWith(' ', MaxSize - length('Today : ' + Content[Temp_Len])) + BorderStyleY, BorderColor - ((i + 1) * Color_Mixer)); 1: Players.WriteConsole(BorderStyleY + 'This week : ' + Content[Temp_Len] + FillWith(' ', MaxSize - length('This week : ' + Content[Temp_Len])) + BorderStyleY, BorderColor - ((i + 1) * Color_Mixer)); 2: Players.WriteConsole(BorderStyleY + 'This month: ' + Content[Temp_Len] + FillWith(' ', MaxSize - length('This month: ' + Content[Temp_Len])) + BorderStyleY, BorderColor - ((i + 1) * Color_Mixer)); 3: Players.WriteConsole(BorderStyleY + 'This year : ' + Content[Temp_Len] + FillWith(' ', MaxSize - length('This year : ' + Content[Temp_Len])) + BorderStyleY, BorderColor - ((i + 1) * Color_Mixer)); 4: Players.WriteConsole(BorderStyleY + 'Over-all : ' + Content[Temp_Len] + FillWith(' ', MaxSize - length('Over-all : ' + Content[Temp_Len])) + BorderStyleY, BorderColor - ((i + 1) * Color_Mixer)); end; end; Players.WriteConsole(CornerStyle + FillWith(BorderStyleX, MaxSize) + CornerStyle, BorderColor - (6 * Color_Mixer));end;procedure Timers(Ticks: integer);begin if Ticks mod (60 * Display_Time) = 0 then begin OnDateCheck(); CreateBox('_ Server Visits _', '_', '|', '.', database, Base_Color); end;end;procedure JoinGame(Player: TActivePlayer; Team: TTeam);begin database[4] := inttostr(strtoint(database[4])+1); database[5] := inttostr(strtoint(database[5])+1); database[6] := inttostr(strtoint(database[6])+1); database[7] := inttostr(strtoint(database[7])+1); database[8] := inttostr(strtoint(database[8])+1); database.SaveToFile(Script.Dir+Path);end;initializationbegin Game.OnJoin := @JoinGame; Game.OnClockTick := @Timers; LoadDatabase();end;finalization;end.