Author Topic: Server Visit  (Read 2156 times)

0 Members and 1 Guest are viewing this topic.

Offline soldat-game

  • Camper
  • ***
  • Posts: 402
Server Visit
« on: June 25, 2017, 05:09:07 am »
Script Name: Server Visit
Script Creator: dominikk26
Script Core: III
Version: 1.0.0
Download: Click Me!
Description:
In contrast to this version https://forums.soldat.pl/index.php?topic=35003
Me version server visits using script core 3 and:
FIX BUG: Cannot Import VARTYPE
FIX BUG: This Week Display, which counted a week since the server started. Now correctly shows from the whole week.
Code:
Code: [Select]
unit ServerVisit;

interface

implementation
const
Patch = 'database.db';
DisplayTime = 1; //Valute in miniutes
var
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 Dominik
var 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;

initialization
begin
ScriptDecl();
ScriptRecompile();
end;

finalization;
end.
« Last Edit: February 06, 2022, 02:14:37 pm by soldat-game »

Offline soldat-game

  • Camper
  • ***
  • Posts: 402
Re: Server Visit
« Reply #1 on: February 06, 2022, 02:14:04 pm »
Script Name: Server Visit
Script Creator: dominikk26
Script Core: III
Version: 1.0.1
Download: Click Me!
Description:
In contrast to this version https://forums.soldat.pl/index.php?topic=35003

Changelog 1.0.1:
- Strong optimizations
- Rewrite the code to make him quit the legacy mode
- Set : Display_Time to seconds
- Add: Base_Color
- Add: Color_Mixer
- Add: Display "This month" and "This year"


Code:
Code: [Select]
unit ServerVisit;

interface

implementation
const
Path = '\data\database.db';
Display_Time = 83; //Valute in seconds
Base_Color = $F48FB1; //Default $23DBDB;
Color_Mixer = 25; //Default 25

var
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 Dominik
var 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;

initialization
begin
Game.OnJoin := @JoinGame;
Game.OnClockTick := @Timers;
LoadDatabase();
end;

finalization;
end.
« Last Edit: February 06, 2022, 02:16:17 pm by soldat-game »

Offline Ratman

  • Major(1)
  • Posts: 34
Re: Server Visit
« Reply #2 on: November 22, 2022, 11:46:09 pm »
Thanks for the script! Would be great if we could show previous months/years visits for comparison.

Offline soldat-game

  • Camper
  • ***
  • Posts: 402
Re: Server Visit
« Reply #3 on: November 24, 2022, 08:05:51 am »
Sketch how exactly this would look like.
You can check my version from the server where I added the !lastvisitors command.

Offline Ratman

  • Major(1)
  • Posts: 34
Re: Server Visit
« Reply #4 on: December 01, 2022, 07:01:44 pm »
This is what I was thinking of. It can be a single table like this or 2 separate tables initiated by command. I personally think the server visits should ONLY be showed on command, like !visits !lastvisits