SRL Archive - MSI Suggestions

Stats.scar


Coh3n

2010-04-14 17:52:18

I figured we may as well start planning this. I'd like to get it going asap, but it's not really priority. This is more to discuss the 20 custom variables we're going to include. The actual stats code is the same for any script so…

We also need to talk about how to add to the stats. RM suggested to add to the stats at the same time everything's added to the progress report, which seems to be the best idea in my opinion. :) I'm assuming we'll just edit this procedure accordingly.

This probably seems obvious, but we should register for stats as MSI Phoenix. I think we should register MSI and one script, seeing and technically that's what it is, but we can register multiple scripts if we wanted.

{******************************************************************************}
{ procedure MSI_AddToProggy(item, quantity, which: Integer); }
{ By: The MSI Team }
{ Description: Adds specified element to the progress report - if parameter }
{ is unused, set to -1 }
{******************************************************************************}
const //we should probably add these to globals.scar
ADD_EXP = 0;
ADD_ITEMS = 1;
ADD_LOADS = 2;
procedure MSI_AddToProggy(item, quantity, which: Integer);
begin
if (quantity = 0) then
Exit;

case which of
ADD_EXP: IncEx(ProgressReportArray[CurrentPlayer].SkillInfo[CurrentSkill].TotalEXP, quantity);
ADD_ITEMS: IncEx(ProgressReportArray[CurrentPlayer].SkillInfo[CurrentSkill].ObjQuants[item], quantity);
ADD_LOADS: Inc(ProgressReportArray[CurrentPlayer].SkillInfo[CurrentSkill].TotalLoads);
end;
end;

Stats.scar:

//these will go in Globals.scar
const
Stats_Link = 'http://scriptmanager.freehostia.com/submit.php';

var
Stats_UserID, Stats_Password, Stats_ScriptID: string;
Stats_LastTime: Integer;
Stats_CustomVars: array [1..20] of Integer;

STATS_LOGS = 0;
STATS_BANKS = 1;
STATS_LOADS = 2;
STATS_ORES = 3;
STATS_RANDOMS = 4;
STATS_LOGINS = 5;


{==============================================================================\
| MSI Group Scripting Include |
| Stats.scar |
|==============================================================================|
| All Banking related routines. |
| |
| * procedure Stats_CheckOutput(); * by nielsie95 |
| * procedure Stats_GetScriptInfo(); * by nielsie95 |
| * procedure Stats_SendReport(); * by nielsie95 |
| * procedure Stats_SendAccountInfo(); * by nielsie95 |
| * procedure Stats_ManageAccounts(); * by nielsie95 |
| * procedure MSI_SendStats; * by Coh3n |
| |
\_____________________________________________________________________________}

{******************************************************************************}
{ procedure Stats_CheckOutput(s: string); }
{ By: nielsie95 }
{ Description: }
{******************************************************************************}
procedure Stats_CheckOutput(s: string);
var
i: Integer;
sa: TStringArray;
begin
sa := Explode(#10, s);
for i := 0 to High(sa) do
if (Trim(sa[i]) <> '') then
if StartsWith('ERROR(1)', sa[i]) then
begin
WriteLn('STATS: "' + sa[i] + '"');
Stats_UserID := '';
Stats_Password := '';
end
else if StartsWith('ERROR(2)', sa[i]) then
begin
WriteLn('STATS: "' + sa[i] + '"');
Stats_ScriptID := '';
end
else
WriteLn('STATS: "' + sa[i] + '"');
end;

{******************************************************************************}
{ procedure Stats_GetScriptInfo( ... ); }
{ By: nielsie95 }
{ Description: }
{******************************************************************************}
function Stats_GetScriptInfo(out Version, News, Link: string;
out OutDated: Boolean; out LastUpdate_HoursAgo: Integer): Boolean;
var
Client: Integer;
s: string;
sa: TStringArray;
begin
Result := False;
if (Stats_ScriptID = '') then
Exit;

Client := InitializeHTTPClient(False, False);
ClearPostData(Client);
AddPostVariable(Client, 'do', 'getinfo');
AddPostVariable (Client, 'sID', Stats_ScriptID);

s := PostHTTPPageEx(Client, STATS_LINK);
sa := Explode(#10'GLUE'#10, s);
if (Length(sa) = 5) then
begin
Result := True;
Version := sa[0];
News := sa[1];
Link := sa[2];
OutDated := sa[3] = '1';
LastUpdate_HoursAgo := StrToIntDef(sa[4], -1);
end
else
Stats_CheckOutput(s);

FreeHTTPClient(Client );
end;

{******************************************************************************}
{ procedure Stats_SendReport; }
{ By: nielsie95 }
{ Description: }
{******************************************************************************}
var
Stats_GlobalVars: array[1..24] of Integer;

procedure Stats_SendReport;
var
i, Client, Time: Integer;
s: string;
begin
if (Stats_UserID = '') and (Stats_Password = '') and (Stats_ScriptID = '') then
Exit;

Client := InitializeHTTPClient(False, False);
ClearPostData(Client);
AddPostVariable(Client, 'do', 'submit');

Time := (GetTimeRunning - Stats_LastTime) div 1000 div 60;
if (Time < 5) then
Time := 0
else
Stats_LastTime := GetTimeRunning;
AddPostVariable(Client, 'sTime', IntToStr(Time));

if (Stats_UserID <> '') and (Stats_Password <> '') then
begin
AddPostVariable(Client, 'uID', Stats_UserID);
AddPostVariable(Client, 'uPass', Stats_Password);
end
else
begin
AddPostVariable(Client, 'uID', '-1');
AddPostVariable(Client, 'uPass', '');
end;

if (Stats_ScriptID <> '') then
begin
AddPostVariable (Client, 'sID', Stats_ScriptID);

for i := Low(Stats_CustomVars) to High(Stats_CustomVars) do
begin
AddPostVariable(Client, 'rndCustom' + IntToStr(i),
IntToStr(Stats_CustomVars[i]));
Stats_CustomVars[i] := 0;
end;
end
else
begin
AddPostVariable (Client, 'sID', '-1');
end;

for i := Low(Stats_GlobalVars) to High(Stats_GlobalVars) do
begin
case i of
1: s := IntToStr(SRL_Logs - Stats_GlobalVars[i]);
2: s := IntToStr(Banks - Stats_GlobalVars[i]);
3: s := IntToStr(RandSolved[rand_Death] - Stats_GlobalVars[i]);
else if ((i - 3) < Length(RandSolved) - 1) then
s := IntToStr(RandSolved[i - 3] - Stats_GlobalVars[i]);
end;
AddPostVariable(Client, 'rndGlobal' + IntToStr(i), s);
Stats_GlobalVars[i] := Stats_GlobalVars[i] + StrToInt(s);
end;

s := PostHTTPPageEx(Client, STATS_LINK);
Stats_CheckOutput(s);
FreeHTTPClient(Client);

if (SRL_Procs[srl_OnSendStats] <> nil) then
SRL_Procs[srl_OnSendStats]();
end;

{******************************************************************************}
{ procedure Stats_SendAccountInfo; }
{ By: nielsie95 }
{ Description: }
{******************************************************************************}
procedure Stats_SendAccountInfo;
var
i, Client: Integer;
Accounts: TStringArray;
begin
if (Stats_UserID = '') and (Stats_Password = '') then
Exit;

Client := InitializeHTTPClient(False, False);
ClearPostData(Client);
AddPostVariable(Client, 'do', 'setaccounts');
AddPostVariable(Client, 'uID', Stats_UserID);
AddPostVariable(Client, 'uPass', Stats_Password);
if (Stats_ScriptID <> '') then
AddPostVariable (Client, 'sID', Stats_ScriptID)
else
AddPostVariable (Client, 'sID', '-1');

SetLength(Accounts, HowManyPlayers);
for i := 0 to HowManyPlayers - 1 do
Accounts[i] := Implode('.|&#8364;stat&#8364;|.', [Players[i].Name, Players[i].Loc,
IntToStr(Integer(Players[i].Active))]);

AddPostVariable(Client, 'accInfo', Implode(#10'ACC'#10, Accounts));
Stats_CheckOutput(PostHTTPPageEx(Client, STATS_LINK));
FreeHTTPClient(Client);
end;

{******************************************************************************}
{ procedure Stats_ManageAccounts; }
{ By: nielsie95 }
{ Description: }
{******************************************************************************}
procedure Stats_ManageAccounts;
var
i, ii, Client: Integer;
s: string;
Accounts, Stats: TStringArray;
begin
if (Stats_UserID = '') and (Stats_Password = '') then
Exit;

Client := InitializeHTTPClient(False, False);
ClearPostData(Client);
AddPostVariable(Client, 'do', 'getaccounts');
AddPostVariable(Client, 'uPass', Stats_Password);
AddPostVariable(Client, 'uID', Stats_UserID);

s := PostHTTPPageEx(Client, STATS_LINK);
Accounts := Explode(#10'ACC'#10, s);
for i := 0 to High(Accounts) do
begin
Stats := Explode('.|&#8364;stat&#8364;|.', Accounts[i]);
if (Length(Stats) = 3) then
begin
for ii := 0 to HowManyPlayers - 1 do
if (LowerCase(Players[ii].Name) = LowerCase(Stats[0])) then
begin
Players[ii].Loc := Stats[1];
Players[ii].Active := Stats[2] = '1';
Break;
end;
end
else
begin
Stats_CheckOutput(s);
Break;
end;
end;

FreeHTTPClient(Client);
stats_SendAccountInfo;
end;

{******************************************************************************}
{ procedure MSI_SendStats; }
{ By: Coh3n }
{ Description: }
{******************************************************************************}
procedure MSI_SendStats;
begin
Stats_SendReport;
Stats_ManageAccounts;
end;

Coh3n

2010-04-15 14:18:58

Updated it a little.

Coh3n

2010-04-20 23:29:31

Done! :)

cloow

2010-08-07 01:46:18

Failed when compiling
Line 10: [Error] (22261:13): colon (':') expected in script C:\Program Files\SCAR 3.23 Beta\includes\SRL\SRL\Misc\Stats.scar


getting this error when i copy and paste and make a file. any ideas?

i luffs yeww

2010-08-07 02:26:59

You can't run includes, if that's what you're trying to do.

cloow

2010-08-07 02:34:37

From: i luffs yeww
You can't run includes, if that's what you're trying to do.


idk its for rcrb script. There was no stats.scar script. So i thought i could make it… idk what to do now

Sir R. M8gic1an

2010-08-07 06:12:21

From: cloow
Failed when compiling
Line 10: [Error] (22261:13): colon (':') expected in script C:\Program Files\SCAR 3.23 Beta\includes\SRL\SRL\Misc\Stats.scar


getting this error when i copy and paste and make a file. any ideas?


You're in the wrong place. That is Stats.scar from your /SRL/ folder. This one is about the /MSI/ folder.


~RM

cloow

2010-08-07 14:23:31

From: Rasta Magician
You're in the wrong place. That is Stats.scar from your /SRL/ folder. This one is about the /MSI/ folder.


~RM


yeah right before bed i figured that out. Screw it. I got simba running. Love simba :)