SRL Archive - Other Guides

The newbie guide to stats


grats

2015-02-25 14:12:22

Hello! Chances are you were linked here from a thread where you got confused on how to setup stats.

Every script is different! This is why we setup stats the way we do, so every script can use your stats and you the user only has to set it up once!
That's right, once!


Lets get started:
What is stats, why do we use it?
Stats is a system to keep track of everything we can think to keep track of.. exp made for everything, per script, per user, totals for example. Or even lobsters caught and cooked.
Here you can see a great example of a script with many variables, remember to click the variable names on the bottom to toggle on/off
http://stats.grats.pw/variable.php?sid=7

and here you can see a great example of a script with many users:
http://stats.grats.pw/script.php?sid=5

as a scripter it's nice to know your script gets used and how much
as a user it's nice to see all the scripts you use and compete for # 1 on a script

But how do I set it up!?!?
Well that's easy, most likely you've already gone here: http://stats.grats.pw/reg.php and registered
From this page we get:
email - what we use to login on the website and (assuming it's an actual email) what we use to recover password. You do not have to use an email for this field, however password recovery will not work if you don't. That's all.
Nickname - This is your public name on the stats website, it's what other people see you as and what you see yourself as in graphs etc.
Password - This is.. your password, used to commit to stats through a simba script AND used to login on the web page.
ID - This is used to commit via scripts, this will be given to you after your first login.

So now to the actual setup part, lets assume you've registered, now lets login! http://stats.grats.pw/login.php
After logging in you will be on the front, homepage. You should see something like this:
This tells you exactly what you need to know
Your ID!
Now some scripts have a nice GUI for you to input your ID and password in, however a lot do not. Lets manually set it up once so every script forever will be able to access your stats info and you won't have to put that in anymore:

Navigate to:
C:\Simba\Stats
In there should be an Info.txt
no? Lets make one, open up notepad!
It should look like this!

[General]
Stats_ID=YOUR ID #
Stats_Pass=YOUR PASS
You're done!

This info can be found here reiterated by @Flight; who also made the simba system to commit to stats, thanks Flight!




Post below if you have ANY questions and I will add more instruction.




Here's a speedy video.
This video ASSUMES you have registered already.. and logged in.
[video=youtube_share;MY9RcWNZ1MM]http://youtu.be/MY9RcWNZ1MM[/video]
http://youtu.be/MY9RcWNZ1MM
the video is made to be quick, if you want more info.. read!
there is 1080p on the video so everything is clear and easy to read.

davyraitt

2015-03-31 15:23:28

Thanks for this, handy to know.

spaderdabomb

2015-05-20 03:44:00

Is there a way to view user stats? I wanted to see how much xp I've gained from botting =D

dutchp0wner

2015-05-20 12:14:17

This is great, using it for most of the scripts.

goodgamescript

2015-06-15 19:53:02

well this helped alot but for it being a newbie guide it is missing a couple of things that i had to figure out.
1. stats_Setup('id'); add this after setupsrl() id = to the script id.
2. When you get set your variables on the website you use that number as well –> stats_IncVariable('140', NumToAddon)
[140] Potions (Made) is the variable so you use the 140.
3. You have to commit your stats by , stats_Commit();
4. To get this to work in non AeroLib script you add this to your script.

{-----grats' stats!-----}
{
=====
Stats
=====
}

Const
stats_Path = AppPath+'Stats\';
stats_File = 'Info.txt';

type
TStats_Vars = record
Name: string;
Value: integer;
end;

var
stats_Timer : integer;
stats_ID,stats_Pass,
stats_ScriptID : string;
stats_Vars : Array of TStats_Vars;


procedure stats_Setup(_ScriptID : String);
var
id,pass : String;
begin
if (not directoryExists(stats_Path)) then
begin
forceDirectories(stats_Path);
writeINI('General', 'Stats_ID', '', stats_Path+stats_File);
writeINI('General', 'Stats_Pass', '', stats_Path+stats_File);
end;

id := readINI('General', 'Stats_ID', stats_Path+stats_File);
pass := readINI('General', 'Stats_Pass', stats_Path+stats_File);

if id = '' then
begin
case MessageBox('No Stats ID found, would you like to register?','Stats',1) of
1: openWebPage('http://stats.grats.pw/reg.php');
end;
end;

stats_ID := id;
stats_Pass := pass;
stats_ScriptID := _ScriptID;
stats_Timer := getSystemTime();
end

procedure stats_InitVariable(VarName: String; InitValue: Integer);
var
len: Integer;
begin
len := Length(stats_Vars);
SetArrayLength(stats_Vars, len + 1);
stats_Vars[len].Name := LowerCase(VarName);
stats_Vars[len].Value := InitValue;
end;

procedure stats_SetVariable(VarName: string; NewValue: Integer);
var
i, h: Integer;
begin
h := High(stats_Vars);
VarName := LowerCase(VarName);

if (h >= 0) then
for i := h downto 0 do
if (VarName = stats_Vars[i].Name) then
begin
stats_Vars[i].Value := NewValue;
Exit;
end;

stats_InitVariable(VarName, NewValue);
end;

procedure stats_IncVariable(VarName: string; Value: integer);
var
i, h: Integer;
begin
h := High(stats_Vars);
VarName := LowerCase(VarName);

if (h >= 0) then
for i := h downto 0 do
if (VarName = stats_Vars[i].Name) then
begin
stats_Vars[i].Value := stats_Vars[i].Value + Value;
Exit;
end;

stats_InitVariable(VarName, Value);
end;

function stats_Commit(): Boolean;
var
S : String;
Client,i,Worked,
ExtraTime : integer;
begin
ExtraTime := getSystemTime() - stats_Timer;
Worked := ExtraTime div 60000;

if Worked < 5 then Exit;
ExtraTime := ExtraTime - (Worked*60000);

stats_Timer := GetSystemTime - ExtraTime;

Client := InitializeHTTPClient(False);
ClearPostData(Client);

if (stats_ID = '') then
begin
stats_ID := '5';
stats_Pass := 'anon1337';
end;

AddPostVariable(Client, 'user_id', STATS_ID);
AddPostVariable(Client, 'password', STATS_PASS);
AddPostVariable(Client, 'script_id', STATS_SCRIPTID);
AddPostVariable(Client, 'timeamount', toStr(Worked));

if (Length(stats_Vars) > 0) then
for i := high(stats_Vars) downto 0 do
with stats_Vars[i] do
begin
if (Value <= 0) then
Continue;

AddPostVariable(Client, Name, toStr(Min(Value, 30000))); //Capped at 30000
end;

// Get & translate the return code
S := PostHTTPPageEx(Client, 'http://stats.grats.pw/POST.php');
FreeHTTPClient(Client);

case StrToIntDef(ExtractFromStr(S, Numbers), -1) of
42 : Result := True;
// 666 : writeln('Stats: User ID/Password not setup.'); // Disabled because of the default name ID & pass given above
9001: writeln('Stats: Invalid user ID/Password.');
1337: writeln('Stats: Invalid Script ID.');
255,
496 : writeln('Stats: Committing too fast; shame on you!');
else
writeln('Stats: No POST return');
end;

if Result then
begin
if (Length(stats_Vars) > 0) then
for i := high(stats_Vars) downto 0 do
with stats_Vars[i] do
begin
if (Value <= 0) then
Continue;
Value := 0; //Clear for next commit
end;
end;
end;
{-----grats' stats-----}


Added all together in a progress report procedure.

procedure Report;
begin
//code that shows in the report.
stats_IncVariable('140', NumToAddon)
stats_Commit();
end;