SRL Archive - SRL Archives

ConvertLvlToExp() returns exp based on what you supply as the Level.


Ron

2007-01-02 15:26:23

ConvertLvlToExp() returns exp based on what you supply as the Level.

This is based off the ConvertXpToLvl function.

Function code:

function ConvertLvlToXp(Level : Integer) : longint;
var
i, exp : integer;
begin
for i := 1 to Level do
begin
exp := exp + Trunc(i + 300 * Pow(2, i / 7));
end;
result := exp/4;
end;

Test code:

program New;

var
i : integer;

{*******************************************************************************
function ConvertLvlToXp(Xp: Integer): Integer;
By: Ron
Description: Returns exp based on level
*******************************************************************************}
function ConvertLvlToXp(Level : Integer) : longint;
var
i, exp : integer;
begin
for i := 1 to Level do
begin
exp := exp + Trunc(i + 300 * Pow(2, i / 7));
end;
result := exp/4;
end;

begin
ClearDebug;
for i := 1 to 100 do
begin
WriteLn('Level '+IntToStr(i)+': '+IntToStr(ConvertLvlToXp(i)));
end;
end.

~Ron

Cheesehunk

2007-01-02 16:21:09

Finally solved it, eh? Bebe told you all had to do was reverse the equation. Good job. :)

Ron

2007-01-02 16:58:10

Ya but any brain dead monkey could have told me that. lol, but I already knew of the function and I knew there was a way. I spent 15 min last time trying to figure it out, and today I just looked at it differently and solved it. :)

fyi, it didn't help my program, turns out using my explode function and the really long string was faster. I tried it this way, and it added about 70 msc for the script to compile.

Thanks though. Possibility of adding it to SRL? ;)

Boreas

2007-01-02 17:02:22

Isn't this inside another function in gametab?

Ron

2007-01-02 17:03:56

idk, it wasn't in the same file as the ConvertExpToLvl .scar file, so I didn't bother looking in any other.

Cheesehunk

2007-01-02 17:41:26

From: Boreas
Isn't this inside another function in gametab?


{*******************************************************************************
function NextLevelAt(Skill: String): Integer;
By: phantombmx / formula by Brak, Flyboy
Description: Returns total xp the next level is at for a skill.
*******************************************************************************}

function NextLevelAt(Skill: string): Integer;
var
level, p, dif, xp: Integer;
begin
p := GetSkillLevel(Skill);
for level := 1 to p do
begin
dif := Trunc(level + 300 * Pow(2, level / 7));
xp := xp + dif
end;
Result := (xp / 4)
end;


Forgot about that function.. Yours could still be useful though, it is a bit different. Doesn't actually require getting the skill level, could use a skill level stored in SRL. Added a shorter version to SkillCalculators.scar

Ron

2007-01-02 19:58:20

Cool, also Cheesehunk, I noticed something about Flyboy's and Brak's ConvertXpToLvl equation, and you don't need that diff variable. So it speeds the function up a little bit.

Here is the code:

function ConvertXpToLvl(xp: Integer): Integer;
var
level, exp: Integer;
begin
for level := 1 to 99 do
begin
exp := exp + Trunc(level + 300 * Pow(2, level / 7));
if ((exp / 4) > xp) then
begin
Result := level;
Exit;
end;
end;
Result := 99;
end;

Cheesehunk

2007-01-02 20:43:59

From: Ron
Cool, also Cheesehunk, I noticed something about Flyboy's and Brak's ConvertLvlToXp equation, and you don't need that diff variable. So it speeds the function up a little bit.

Here is the code:

function ConvertXpToLvl(xp: Integer): Integer;
var
level, exp: Integer;
begin
for level := 1 to 99 do
begin
exp := exp + Trunc(level + 300 * Pow(2, level / 7));
if ((exp / 4) > xp) then
begin
Result := level;
Exit;
end;
end;
Result := 99;
end;

Yes, I already changed the NextLevelAt function because that is useless, but never thought of looking at Flyboys and Brak's function. :p Thanks.

Ron

2007-01-02 23:54:28

Hey no problem Cheesehunk, that's what us smart guys do. Make stuff better. :)