SRL Archive - OSR Help

Total Exp gained


Bobzilla69

2011-01-12 06:51:23

Ok, so for my script i am working on getting Total Exp gained.

what i thought of doing was getting all Exp amounts at the start after a player is logged in then when i do a progress report i would simply get the current level and take away the starting level.

should work fine i think

but my next problem is how to have it send that data to the Stats server.

should this only be done when the player is false? or will the large integer break the system?

any ideas would be appreciated

bugger0001

2011-01-12 07:12:55

Tbh, I don't think checking XP when you start and checking it again when you end one player's turn is a good idea…Why not just do it once and have a variable for each players to hold the previous xp value. It would work like this:
let's say two players.

1.First player logs in checks current XP and saves it to tmpXP[0], does its thing and nextplayer
2.Second player does the same, but instad tmpXP[0] it writes to tmpXP[1]
3.First player logs in checks Current XP and does simple math(Current-tmp) and send that to stats. After doing so you rewrite tmpXP[0]
4.Second player does the same with tmpXP[1]

No large integers and not too much extra coding to be done ;)

BraK

2011-01-12 07:23:18

I would just get the get a general Idea of what gives what estimate of exp. then create a procedure that handles all the EXP set's. From what I understand you do a lot of different things in your scripts. I'll give you an example here in a second.

~BraK

Bobzilla69

2011-01-12 07:23:32

ok well thats kinda what i had in mind. thanks.

what i have at the moment for the Report is

Check Exp once logged in, only once.
Procedure ExpOnce;
var
i:integer;
begin
if (not Players[CurrentPlayer].Booleans[5] )then
begin
Write('Grabing all Skill Exp amounts');
Players[CurrentPlayer].Arrays[1]:= [R_GetSkillExperience(Skill_Attack),
R_GetSkillExperience(Skill_Strength), R_GetSkillExperience(Skill_Defence),
R_GetSkillExperience(Skill_Magic), R_GetSkillExperience(Skill_Range), R_GetSkillExperience(Skill_Prayer), R_GetSkillExperience(SKILL_HITPOINTS)]; //store players current exp per skill

{for i:=0 to high(Players[CurrentPlayer].Arrays[1]) do
begin //debug to make sure its working right
write(inttostr(Players[CurrentPlayer].Arrays[1][i]));
end;}

Players[CurrentPlayer].Booleans[5]:= True;
end;
end;

then in the report i have this to get TotalExp

for I := 0 to HowManyPlayers - 1 do
begin
Players[I].Integers[13] := 0; //Clear the variable
TotalRat:= TotalRat + Players[I].Integers[0]; //rats attacked
TotalDeathWalk:= TotalDeathWalk + Players[I].Integers[1]; //deathwalks
TotalBones:= TotalBones + Players[I].Integers[12];
for B:=0 to high(Players[I].Arrays[1]) do
begin
TotalExp:= TotalExp + (Players[I].Arrays[2][B] - Players[I].Arrays[1][B])
Players[I].Integers[13] := Players[I].Integers[13] + (Players[I].Arrays[2][B] - Players[I].Arrays[1][B])
end;
end;

but i still think it will end up with large numbers for the Exp earned, for example you set your player up to level to attack:= 30, defence := 20 strength :=1 if your character starts at the stats or attack:= 20, defence:= 1 and keep training till its been reached that would be quite big wouldnt it?

but i can do what you suggested except i would have it once its finished its loads/work for time send the TotalExp then we he logs back in check exp again.

hope this made sense

Edit:

yes i do Brak, which is why i am worried about large numbers.

Capricorn

2011-01-12 07:46:21

I grab the number from the EXP counter.

bugger0001

2011-01-12 08:00:08

From: bobzilla69

yes i do Brak, which is why i am worried about large numbers.


Don't worry, LongInt should be more than capable of handling XP changes :p

Bobzilla69

2011-01-12 08:09:05

From: Capricorn
I grab the number from the EXP counter.


thats not the problem, the problem is making sure it wont crash or not send the stats due to a large number.

and how to handle sending the exp number to the stats system

From: bugger0001
Don't worry, LongInt should be more than capable of handling XP changes :p


ok yeh i will use longint, i just hope the stats system wont kill itself

i will have to check with Wizzup? that it accepts large numbers.

bugger0001

2011-01-12 08:17:00

btw…For Simba Integers can cover the same range of numbers as LongInts do(More than 4 billion I guess for range, and 2 billion for positive numbers). Thus it shouldn't be a problem ;)

Bobzilla69

2011-01-12 08:37:31

ok so this is how i am going to do it.

Player 1 logs in and we get Exp for skills
Player 1 works for amount told to and is about to got for a break, this is where we get end exp levels and do maths (new amount - old amount = gained amount)
after player 1 finished break and logs back in we start from step 1, and get exp levels

i will store the exp levels individually per player

this should work fine shouldnt it?

BraK

2011-01-12 08:58:17

Totally not what I meant their bobzilla. How often do you send reports? How do you calculate all the number your sending? All you need to do is make a function such as what I'm about to show you.


This function handled all my Progress and XP across my whole script. Here's the Function.
Function HandleProgress(const What :String; const Amount :Integer): Boolean; begin   case What of     'unf': begin              IncEx(Players[CurrentPlayer].Integers[SRL_UNF], Amount);              IncEx(Stats_CustomVars[SRL_UNF], Amount);            end;     'pot': begin              IncEx(Players[CurrentPlayer].Integers[SRL_POT], Amount);              IncEx(Stats_CustomVars[SRL_POT], Amount);              Players[CurrentPlayer].Extendeds[SRL_XP] := (Players[CurrentPlayer].Extendeds[SRL_XP] + (Second[Players[CurrentPlayer].Integers[SRL_SEC]].XP * Amount));              IncEx(Stats_CustomVars[SRL_XP], Round(Second[Players[CurrentPlayer].Integers[SRL_SEC]].XP * Amount));            end;      'herb': Begin               IncEx(Players[CurrentPlayer].Integers[SRL_Cleaned], Amount);               IncEx(Stats_CustomVars[SRL_cleaned], Amount);               Players[CurrentPlayer].Extendeds[SRL_XP] := (Players[CurrentPlayer].Extendeds[SRL_XP] + (Amount * Herb[Players[CurrentPlayer].Integers[SRL_Herb]].XP));               IncEx(Stats_CustomVars[SRL_XP], Round(Amount * Herb[Players[CurrentPlayer].Integers[SRL_Herb]].XP))             end;    end;   result := true; end; 

Here's How I used it:

{******************************************************************************* function Clean() : boolean; By: Brak Description: Checks and cleans herbs if needed. returns true if clean. *******************************************************************************} function Clean() : Boolean; var   CC : TIntegerArray;   C, I, D :integer; begin   Debug('Starting to Clean');   result := False;   C := (GetTimeRunning + 30000);   while GetTimeRunning < C do   begin     Players[CurrentPlayer].Status := 'Cleaning Herbs';     if Players[CurrentPlayer].Integers[SRL_MAK] = 0 then     begin       case Random(10) of         0 : CC := [1,2,3,4,8,7,6,5,9,10,11,12,16,15,14,13,17,18,19,20,24,23,22,21,25,26,27,28];         1 : CC := [1,5,9,13,17,21,25,26,22,18,14,10,6,2,3,7,11,15,19,23,27,28,24,20,16,12,8,4];         2 : CC := [1,2,3,4,8,12,16,20,24,28,27,26,25,21,17,13,9,5,6,7,11,15,19,23,22,18,14,10];         3 : CC := [1,2,6,5,9,10,14,13,17,18,22,21,25,26,27,28,24,23,19,20,16,15,11,12,8,7,3,4];         4 : CC := [1,5,9,13,17,21,25,26,22,18,14,10,6,2,3,4,8,7,11,12,16,15,19,20,24,23,27,28];         5 : CC := [1,2,6,5,9,10,14,13,17,18,22,21,25,26,27,28,24,20,16,12,8,4,3,7,11,15,19,23];         6 : CC := [1,5,9,13,17,21,25,26,27,23,22,18,19,15,14,10,11,7,6,2,3,4,8,12,16,20,24,28];         7 : CC := [1,2,3,4,8,12,16,20,24,28,27,26,25,21,22,23,19,18,17,13,14,15,11,10,9,5,6,7];         8 : CC := [1,2,3,7,6,5,9,10,11,15,14,13,17,18,19,23,22,21,25,26,27,28,24,20,16,12,8,4];         9 : CC := [1,2,3,4,8,7,6,5,9,10,11,12,16,20,24,28,27,26,25,21,17,13,14,15,19,23,22,18];         10 : CC := [1,5,9,13,17,21,25,26,27,28,24,20,19,23,22,18,14,15,16,12,8,4,3,2,6,10,11,7];       end;     end else     begin       case Random(24) of         0..2 : CC := [1, 2, 3, 4, 8, 12, 11, 10, 14, 13, 9, 5, 6, 7];         3..5 : CC := [1, 2, 6, 5, 9, 13, 14, 10, 11, 12, 8, 7, 3, 4];         6..8 : CC := [1, 2, 6, 7, 3, 4, 8, 12, 11, 10, 14, 13, 9, 5];         9..11 : CC := [1, 2, 6, 5, 9, 13, 14, 10, 11, 12, 8, 4, 3, 7];         12..14 : CC := [1, 2, 3, 4, 8, 12, 11, 7, 6, 5, 9, 13, 14, 10];         15..17 : CC := [1, 5, 9, 13, 14, 10, 11, 12, 8, 4, 3, 7, 6, 2];         18..20 : CC := [1, 5, 9, 13, 14, 10, 6, 2, 3, 7, 11, 12, 8, 4];         21..23 : CC := [1, 5, 9, 13, 14, 10, 6, 2, 3, 4, 8, 7, 11, 12];       end;     end;     InvMouse(1,3);     Wait(RandomRange(700,1000));     if WaitUpTextMulti(['Clea', 'lean', 'lea', 'ean'],500) and IsClean(1) then     begin       result := True;       Debug('using Clean Herbs');       exit;     end else     begin       Debug('Cleaning Herbs.');       for I := 0 to High(CC) do       begin         InvMouse(CC[I],1);         wait(200 + Random(200));         HandleLvl;       end;       CCI := CC[High(CC)];       while not(IsUpTextMultiCustom(['Clean', 'lean'])) do       begin         wait(RandomRange(200, 300));         Inc(D);         if D = 20 then         begin           result := false;           NextPlayer(false);           exit;         end;       end;       Debug('Finished Cleaning Herbs');       Players[CurrentPlayer].Integers[SRL_STS] := 1;       [B]result := HandleProgress('herb', 14);[/B]       exit;     end;   end; end; 

Note: This is old code as I'm not on my home computer and haven't commited to the SVN. But it's very easy to update it.

From here all you have to do is use the information in your progress report and hit the stats_commit. If you wanted to make stats commit every 10 minute instead. Just make a global Integer to used as a Time keeper. Make a function using Timing Procs to check the time and send with reset of the timer afterwards. then just put it into your primary loop.

If you need more explainations/Demonstrations I'll be Off in a few hours and can get on MSN/IRC to assist you.


~BraK

E: Crap code didn't transfer clean. Your gonna have you wait a little bit or decifer it. You can also find the same code in my Herblore script in the members section. You'll have to visit the SVN.

Bobzilla69

2011-01-12 09:06:36

Yes i know its not what you meant.

My stats commit every 5 min, i use a timer, and when they have completed there target levels they will also do ProgressReport that will commit but thats only for Kills, Walks and Bones.

For the Exp i am planning on only doing when they break and when they finish all the target skill levels.

i have looked through your script with that in and i dont know if it would work well because it doesn't always kill the rats, so i cant rally use a static value, would be to inaccurate.

Edit:

this is how i calculate the total exp

Get stats at start
Procedure ExpOnce;
var
i:integer;
begin
if (not Players[CurrentPlayer].Booleans[5] )then
begin
Write('Grabing all Skill Exp amounts');
Players[CurrentPlayer].Arrays[1]:= [R_GetSkillExperience(Skill_Attack),
R_GetSkillExperience(Skill_Strength), R_GetSkillExperience(Skill_Defence),
R_GetSkillExperience(Skill_Magic), R_GetSkillExperience(Skill_Range), R_GetSkillExperience(Skill_Prayer), R_GetSkillExperience(SKILL_HITPOINTS)]; //store players current exp per skill

{for i:=0 to high(Players[CurrentPlayer].Arrays[1]) do
begin //debug to make sure its working right
write(inttostr(Players[CurrentPlayer].Arrays[1][i]));
end;}

Players[CurrentPlayer].Booleans[5]:= True;
end;
end;

get stats at end and set amount of exp gained
Procedure EndExp;   //get end exp when palyer goes inactive
var
PlayerExp:LongInt;
I:Integer;
begin
Players[CurrentPlayer].Arrays[2]:= [R_GetSkillExperience(Skill_Attack),
R_GetSkillExperience(Skill_Strength), R_GetSkillExperience(Skill_Defence),
R_GetSkillExperience(Skill_Magic), R_GetSkillExperience(Skill_Range), R_GetSkillExperience(Skill_Prayer), R_GetSkillExperience(SKILL_HITPOINTS)]; //store players current exp per skill

for I:=0 to high(Players[CurrentPlayer].Arrays[1]) do
begin
PlayerExp:= (Players[CurrentPlayer].Arrays[2][I] - Players[CurrentPlayer].Arrays[1][I])
end;
Stats_IncVariable('Total EXP Gained', PlayerExp);
end;

BraK

2011-01-12 11:24:58

Here's the Code I tried to post earlier.

My handle Progress function.. Yours would have to have a lot more added to it. Well then again I have a huge record full of data used in this process.

Function HandleProgress(const What :String; const Amount :Integer): Boolean;
begin
case What of
'unf': begin
IncEx(Players[CurrentPlayer].Integers[SRL_UNF], Amount);
stats_IncVariable('Unf. Potions Made', Amount);
end;
'pot': begin
IncEx(Players[CurrentPlayer].Integers[SRL_POT], Amount);
stats_IncVariable('Potions Made', Amount);
Players[CurrentPlayer].Extendeds[SRL_XP] := (Players[CurrentPlayer].Extendeds[SRL_XP] + (Second[Players[CurrentPlayer].Integers[SRL_SEC]].XP * Amount));
stats_IncVariable('Total EXP Gained', Round(Second[Players[CurrentPlayer].Integers[SRL_SEC]].XP * Amount));
end;

'herb': Begin
IncEx(Players[CurrentPlayer].Integers[SRL_Cleaned], Amount);
stats_IncVariable('Herbs Cleaned', Amount);
Players[CurrentPlayer].Extendeds[SRL_XP] := (Players[CurrentPlayer].Extendeds[SRL_XP] + (Amount * Herb[Players[CurrentPlayer].Integers[SRL_Herb]].XP));
stats_IncVariable('Total EXP Gained', Round(Amount * Herb[Players[CurrentPlayer].Integers[SRL_Herb]].XP))
end;

end;
result := true;
end;

Adding the function to the end of a process that gains EXP.
{*******************************************************************************
function Clean() : boolean;
By: Brak
Description: Checks and cleans herbs if needed. returns true if clean.
*******************************************************************************}
function Clean() : Boolean;
var
CC : TIntegerArray;
C, I, D :integer;
begin
Debug('Starting to Clean');
result := False;
C := (GetTimeRunning + 30000);
while GetTimeRunning < C do
begin
Players[CurrentPlayer].Status := 'Cleaning Herbs';
if Players[CurrentPlayer].Integers[SRL_MAK] = 0 then
begin
case Random(10) of
0 : CC := [1,2,3,4,8,7,6,5,9,10,11,12,16,15,14,13,17,18,19,20,24,23,22,21,25,26,27,28];
1 : CC := [1,5,9,13,17,21,25,26,22,18,14,10,6,2,3,7,11,15,19,23,27,28,24,20,16,12,8,4];
2 : CC := [1,2,3,4,8,12,16,20,24,28,27,26,25,21,17,13,9,5,6,7,11,15,19,23,22,18,14,10];
3 : CC := [1,2,6,5,9,10,14,13,17,18,22,21,25,26,27,28,24,23,19,20,16,15,11,12,8,7,3,4];
4 : CC := [1,5,9,13,17,21,25,26,22,18,14,10,6,2,3,4,8,7,11,12,16,15,19,20,24,23,27,28];
5 : CC := [1,2,6,5,9,10,14,13,17,18,22,21,25,26,27,28,24,20,16,12,8,4,3,7,11,15,19,23];
6 : CC := [1,5,9,13,17,21,25,26,27,23,22,18,19,15,14,10,11,7,6,2,3,4,8,12,16,20,24,28];
7 : CC := [1,2,3,4,8,12,16,20,24,28,27,26,25,21,22,23,19,18,17,13,14,15,11,10,9,5,6,7];
8 : CC := [1,2,3,7,6,5,9,10,11,15,14,13,17,18,19,23,22,21,25,26,27,28,24,20,16,12,8,4];
9 : CC := [1,2,3,4,8,7,6,5,9,10,11,12,16,20,24,28,27,26,25,21,17,13,14,15,19,23,22,18];
10 : CC := [1,5,9,13,17,21,25,26,27,28,24,20,19,23,22,18,14,15,16,12,8,4,3,2,6,10,11,7];
end;
end else
begin
case Random(24) of
0..2 : CC := [1, 2, 3, 4, 8, 12, 11, 10, 14, 13, 9, 5, 6, 7];
3..5 : CC := [1, 2, 6, 5, 9, 13, 14, 10, 11, 12, 8, 7, 3, 4];
6..8 : CC := [1, 2, 6, 7, 3, 4, 8, 12, 11, 10, 14, 13, 9, 5];
9..11 : CC := [1, 2, 6, 5, 9, 13, 14, 10, 11, 12, 8, 4, 3, 7];
12..14 : CC := [1, 2, 3, 4, 8, 12, 11, 7, 6, 5, 9, 13, 14, 10];
15..17 : CC := [1, 5, 9, 13, 14, 10, 11, 12, 8, 4, 3, 7, 6, 2];
18..20 : CC := [1, 5, 9, 13, 14, 10, 6, 2, 3, 7, 11, 12, 8, 4];
21..23 : CC := [1, 5, 9, 13, 14, 10, 6, 2, 3, 4, 8, 7, 11, 12];
end;
end;
InvMouse(1,3);
Wait(RandomRange(700,1000));
if WaitUpTextMulti(['Clea', 'lean', 'lea', 'ean'],500) and IsClean(1) then
begin
result := True;
Debug('using Clean Herbs');
exit;
end else
begin
Debug('Cleaning Herbs.');
for I := 0 to High(CC) do
begin
InvMouse(CC[I],1);
wait(200 + Random(200));
HandleLvl;
end;
CCI := CC[High(CC)];
while not(IsUpTextMultiCustom(['Clean', 'lean'])) do
begin
wait(RandomRange(200, 300));
Inc(D);
if D = 20 then
begin
result := false;
NextPlayer(false);
exit;
end;
end;
Debug('Finished Cleaning Herbs');
Players[CurrentPlayer].Integers[SRL_STS] := 1;
result := HandleProgress('herb', 14);
exit;
end;
end;
end;


end;
Debug('Finished Cleaning Herbs');
Players[CurrentPlayer].Integers[SRL_STS] := 1;
result := HandleProgress('herb', 14);
exit;
end;[SIMBA]

This is what I was talking about.

~BraK

E: this is the new code with updates for the new stats.

Bobzilla69

2011-01-12 11:49:12

ok yeh i see whats going on.

i will see about doing something similar just have to work out all the exp gains, and stuff.

i still dont know how good it will be, because if i dont kill a rat (player died) the total exp gain will be inaccurate but i will have a look at it later.

bugger0001

2011-01-12 12:04:42

Uhm…If you're taking that path then why not simply do:
(rats attacked - walks) * xp from one rat?
EDIT: That way you know for sure that you have got AT LEAST that much which I suppose is better than 'I got MAX of 1000xp', but actually got 900xp :p


And one more thing. If you should take the path of checking XP both in the beginning of a players turn and in the end, then It'll start taking down efficiency and human-likeness for armies like the one I was running your script with.

Bobzilla69

2011-01-12 12:08:32

how will it take the efficiency down?

it takes a split second to grab all the data with reflection and i dont have to be on the tab

bugger0001

2011-01-12 12:24:29

Lol, thanks for clearing that up.
**Color n00b on the other end of the Internet**

BraK

2011-01-12 12:25:58

This is pretty accurate and fast. Truly this is one of the better ones I've used. It's shouldn't slow the script down at all. But you see what I meant about consolidating it all into one function. It handles everything and it comes out ready for progress reports and sending to Stats.

~BraK

E: forget what I wrote I misread didn't know bugger0001 posted that question. :p

Bobzilla69

2011-01-12 12:37:18

ok, i am still going to check out your way Brak but seeing as i have all the base code ready to go, as i am using it atm for progress report if i/we i change to your system.

here is how i have it atm in V1.70 of my script

run at the start of the script
Procedure ExpOnce;
var
i:integer;
begin
if (not Players[CurrentPlayer].Booleans[5] )then //means it will only be called once at start
begin
Write('Storing all Skill Exp Amounts');
Players[CurrentPlayer].Arrays[1]:= [R_GetSkillExperience(Skill_Attack),
R_GetSkillExperience(Skill_Strength), R_GetSkillExperience(Skill_Defence),
R_GetSkillExperience(Skill_Magic), R_GetSkillExperience(Skill_Range), R_GetSkillExperience(Skill_Prayer), R_GetSkillExperience(SKILL_HITPOINTS)]; //store players current exp per skill

{for i:=0 to high(Players[CurrentPlayer].Arrays[1]) do
begin //debug to make sure its working right
write(inttostr(Players[CurrentPlayer].Arrays[1][i]));
end;}

Players[CurrentPlayer].Booleans[5]:= True;
end else using this else so i dont have to duplicate this code for grabbing end exp levels
begin
Players[CurrentPlayer].Arrays[2]:= [R_GetSkillExperience(Skill_Attack),
R_GetSkillExperience(Skill_Strength), R_GetSkillExperience(Skill_Defence),
R_GetSkillExperience(Skill_Magic), R_GetSkillExperience(Skill_Range), R_GetSkillExperience(Skill_Prayer), R_GetSkillExperience(SKILL_HITPOINTS)]; //store players current exp per skill

end
end;

this is called when the player finished the loads, made it separate procedure to stop me sending the exp to often

Procedure EndExp;   //get end exp when palyer goes inactive
var
PlayerExp:LongInt;
I:Integer;
begin
PlayerExp:= 0;

ExpOnce;

for I:=0 to high(Players[CurrentPlayer].Arrays[1]) do
begin
PlayerExp:= PlayerExp + (Players[CurrentPlayer].Arrays[2][I] - Players[CurrentPlayer].Arrays[1][I])
end;
//Stats_IncVariable('Total EXP Gained', PlayerExp);
end;


where i post all stats to server, it will only post Exp if i call EndExp
procedure ProgressReport;
var
I, B, TotalRat, TotalDeathWalk, TotalBones, TotalExp:Integer;
begin
Writeln('');
TotalRat:= 0; //initilise them as clean variables
TotalDeathWalk:= 0;
TotalExp:= 0;
TotalBones:= 0; //stores values for reporting


ExpOnce; //will get end exp as its allready been called at start

for I := 0 to HowManyPlayers - 1 do
begin
Players[I].Integers[13] := 0; //Clear the variable
TotalRat:= TotalRat + Players[I].Integers[0]; //rats attacked
TotalDeathWalk:= TotalDeathWalk + Players[I].Integers[1]; //deathwalks
TotalBones:= TotalBones + Players[I].Integers[12];
for B:=0 to high(Players[I].Arrays[1]) do
begin
TotalExp:= TotalExp + (Players[I].Arrays[2][B] - Players[I].Arrays[1][B])
Players[I].Integers[13] := Players[I].Integers[13] + (Players[I].Arrays[2][B] - Players[I].Arrays[1][B])
end;
end;
SRLProgressReport(ResultDebugBox, 'Ratinator', 'Bobzilla69', '1.70',
['TimeRunning', 'Active Players', 'Total Rats Attacked', 'Total DeathWalks', 'Total Bones Buried', 'Total Exp Gained'],
[MsToTime(TimeFromMark(RunTime), Time_Formal), PlayersActive , TotalRat, TotalDeathWalk, TotalBones, TotalExp]);
SRLPlayerReport( ResultDebugBox, 0, false, [False, False, False, False, False, True], ['Rats Attacked', 'Deathwalk Count', 'Bones Buried', 'Exp Gained'], [], [0, 1, 12, 13], [], [] );
SRLRandomsReport;
Write('');
Write('Please post bugs and report at [url]http://villavu.com/forum/showthread.php?t=60296[/url]');
Write('');
Stats_Commit;
SendSRLReport;
end;

Nava2

2011-01-12 14:39:42

For committing to SRL Stats, you want to only commit the xp gained SINCE the last commit. So, refresh the base value every time you increment the stats. Otherwise you will increment the stats by a larger and larger value, where as you actually want to increase it by approx the same value.

function getCurrentExperience(): TIntegerArray;
var
i: Integer;
Skills: TIntegerArray;
begin
Skills := [
SKILL_ATTACK, SKILL_STRENGTH, SKILL_DEFENCE, SKILL_MAGIC, SKIL_RANGE,
SKILL_HITPOINTS, SKILL_PRAYER
];
SetLength(Result, Length(Skills));

for i := High(Skills) downto 0 do
Result[i] := r_GetSkillExperience(Skills[i]);
end;


{
Stores the players last found XP into Players[i].Arrays[2]
}
procedure updateStatsXP();
var
i, ii: Integer;
tmpArray: TIntegerArray;
TotalXP: Itger;

begin
for i = HowManyPlayers-1 downto 0 do
begin
tmpArray := getCurrentExperience;

for ii := High(tmpArray) downto 0 do
TotalXP := TotalXP + tmpArray[ii] - Players[i].Arrays[2][ii];

Players[i].Arrays[2] := tmpArray;
end;

stats_IncVariable('XP STUFFFFF', TotalXP);
end;

For the Report, set the starting XP at the beginning into a different array then do the maths on those to get total xp per player. Mine will stop you from mass committing to stats. :P

BraK

2011-01-12 14:44:41

From: Nava2
For committing to SRL Stats, you want to only commit the xp gained SINCE the last commit. So, refresh the base value every time you increment the stats. Otherwise you will increment the stats by a larger and larger value, where as you actually want to increase it by approx the same value.



For the Report, set the starting XP at the beginning into a different array then do the maths on those to get total xp per player. Mine will stop you from mass committing to stats. :P


That's good information to Know thanks for sharing Nava. :)

~BraK

Bobzilla69

2011-01-12 14:56:27

yeh thanks for the info Nava2, i am taking a break from coding for a bit so will try implementing something like this and Brak's solution later

Wizzup?

2011-01-12 16:35:46

You could also just add exp like this: rats killed * 4 * rats_hp?
E: Wait, the *4 probably won't work, depending on what you're training. Anyway, do note that it is incremental.

bugger0001

2011-01-12 17:10:45

After a little research it is now clear to me that one of the most logical ways to commit exp to SRL stats and to increment it to total in your script would be by doing like this:
1. when player starts do the xp check and store it to a variable, let's say integer tmp
2. when the player is about to switch, check it again and
3. find the difference between current xp and tmp. then commit the diff to stats and increment it to your local total ;)

BraK

2011-01-13 02:50:25

From: Wizzup?
You could also just add exp like this: rats killed * 4 * rats_hp?
E: Wait, the *4 probably won't work, depending on what you're training. Anyway, do note that it is incremental.


^This is probably the best way it's what I do in my script. You can predetermine how much EXP you get from just about anything in the game and set it in records. Well the records aren't really neccesary but they help when you have huge amounts of data to go through. My herblore script is such a script with two records do to the massive amount of information I have to process.

~BraK