Author Topic: Number of Visits  (Read 4107 times)

0 Members and 1 Guest are viewing this topic.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Number of Visits
« on: August 17, 2007, 08:42:41 pm »
Script Name: Number of Visits
Script Description: This script welcomes everybody who joins, and says to everybody how many times he has visited the server.
Original Author: Curt (DorkeyDear)
Core Version: 2.6.2
Code:
Code: [Select]
const
  Color = $FFFFFFFF;

var
  Visits: tstringarray;

function Split(const Source: string; const Delimiter: string): tstringarray;
var
  i,x,d: integer;
  s: string;
begin
  d := Length(Delimiter);
  x := 0;
  i := 1;
  SetArrayLength(Result,1);
  while i <= Length(source) do begin
    s := Copy(Source,i,d);
    if s = Delimiter then begin
      Inc(i,d);
      Inc(x,1);
      SetArrayLength(result,x + 1);
    end else begin
      Result[x] := Result[x] + Copy(s,1,1);
      Inc(i,1);
    end;
  end;
end;

procedure ActivateServer();
begin
  Visits := Split(ReadFile('Visits.txt'),Chr(13) + Chr(10));
end;

procedure OnMapChange(NewMap: string);
var
  i: integer;
  File: string;
begin
  for i := 0 to GetArrayLength(Visits) - 1 do if i = 0 then File := Visits[i] else File := File + Chr(13) + Chr(10) + Visits[i];
  WriteFile('Visits.txt',File);
end;

procedure OnJoinGame(ID, Team: byte);
var
  Found: boolean;
  i: integer;
  Temp: string;
begin
  for i := 0 to GetArrayLength(Visits) - 1 do if GetPiece(Visits[i],Chr(1),0) = GetPlayerStat(ID,'IP') then begin
    Temp := GetPlayerStat(ID,'IP') + Chr(1) + InttoStr(StrtoInt(GetPiece(Visits[i],Chr(1),1)) + 1);
    Visits[i] := Temp;
    Found := true;
    WriteConsole(ID,'Welcome back to ' + ServerName + ' (' + ServerIP + ':' + InttoStr(ServerPort) + '), ' + GetPlayerStat(ID,'Name') + '!',Color);
    WriteConsole(0,GetPlayerStat(ID,'Name') + ' has been recognized here ' + GetPiece(Visits[i],Chr(1),1) + ' times.',Color);
    Break;
  end;
  if Found = false then begin
    SetArrayLength(Visits,GetArrayLength(Visits) + 1);
    Visits[GetArrayLength(Visits) - 1] := GetPlayerStat(ID,'IP') + Chr(1) + '1';
    WriteConsole(ID,'Welcome to ' + ServerName + ' (' + ServerIP + ':' + InttoStr(ServerPort) + '), ' + GetPlayerStat(ID,'Name') + '!',Color);
    WriteConsole(0,'This is ' + GetPlayerStat(ID,'Name') + '''s first visit here.',Color);
  end;
end;
« Last Edit: August 18, 2007, 10:36:20 am by DorkeyDear »

Offline Ttil_Np.csWoW

  • Major
  • *
  • Posts: 55
  • The Berserkers Are Coming....
Re: Number of Visits
« Reply #1 on: August 17, 2007, 08:56:10 pm »
intresting script , well done :)
I will be back to play soldat, just not now , but i will....... some day.

Offline Leo

  • Soldat Beta Team
  • Veteran
  • ******
  • Posts: 1011
Re: Number of Visits
« Reply #2 on: August 18, 2007, 02:11:34 am »
You test your scripts before releasing them ?
"[09:07:16] 
  • Compiling Visits -> Visits.pas...
[09:07:16] 
  • Visits -> [Error] (10:13): Unknown identifier 'Split'"

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Number of Visits
« Reply #3 on: August 18, 2007, 10:34:39 am »
Lol, my bad. Before I had Split in a separate file but its hard to find the location of the bug when the line numbers are corresponding with all files combined. I added the XSplit function (Named as Split) by Keydon.
« Last Edit: August 18, 2007, 10:37:41 am by DorkeyDear »

Offline Freedom

  • Major
  • *
  • Posts: 97
  • Veritas Vincit
Re: Number of Visits
« Reply #4 on: August 18, 2007, 02:45:28 pm »
Good script ;P
I see him on LEO INF ;P
And it's really cool xd
Cum pare contendere anceps est, cum superiore furiosum, cum inferiore sordidum.

Offline Will

  • Flagrunner
  • ****
  • Posts: 910
Re: Number of Visits
« Reply #5 on: August 18, 2007, 02:50:06 pm »
Could you make it display total amount of visits (of all people) on that day or something like that?

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Number of Visits
« Reply #6 on: August 18, 2007, 07:19:47 pm »
there is no way to detect when the end of the day is without the help of an external program or GetURL or something

lol i typed that on a phone! took me like 5 minutes.
I can make it check total users ever, but if you want total users per day, you would need to GetURL some site that said the time of where the computer is located, or an external program writing to a file the current time every so often, or TCP sockets to whatever, you get my point. You would need to turn off savemode if you want this, plus GetURL (easiest to make in my mind) may lag the server a little..
« Last Edit: August 18, 2007, 07:41:40 pm by DorkeyDear »

Offline Toumaz

  • Veteran
  • *****
  • Posts: 1906
Re: Number of Visits
« Reply #7 on: August 19, 2007, 01:05:04 am »
there is no way to detect when the end of the day is without the help of an external program or GetURL or something

lol i typed that on a phone! took me like 5 minutes.
I can make it check total users ever, but if you want total users per day, you would need to GetURL some site that said the time of where the computer is located, or an external program writing to a file the current time every so often, or TCP sockets to whatever, you get my point. You would need to turn off savemode if you want this, plus GetURL (easiest to make in my mind) may lag the server a little..

Incorrent, there's a built in function for that. Use FormatDate.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Number of Visits
« Reply #8 on: August 19, 2007, 09:52:48 am »
I realized that when I woke up this morning. :)
I forgot about it sense I tried using it like a long time ago and had issues. Probably was using it wrong.

Offline Will

  • Flagrunner
  • ****
  • Posts: 910
Re: Number of Visits
« Reply #9 on: August 19, 2007, 10:16:16 am »
I just asked for the possibilites. I think that scripts deserve far more attention then they are getting now. I host only private and small servers for just a couple of my friend, so I have no use of them but they deserve it notheless

Offline BombSki

  • Flagrunner
  • ****
  • Posts: 927
    • Climbing-soldiers.net
Re: Number of Visits
« Reply #10 on: August 22, 2007, 02:46:54 pm »
daily/weekly user statistics would be nice to see on join..
'123 visits today/ 12314 this week'