PDA

View Full Version : Leveling System


xAndrewx
11-26-2006, 12:57 PM
/*
player.addExperience(leveltype, amount)
Will add some experience for the player

player.findEXPNeeded(leveltype)
Will return how much EXP is needed to gain a level
*/
function onCreated()
{
this.levelTypes = {"Physical", "Magic"};
}

public function findEXPNeeded(levelType)
{
if (this.levelTypes.index(temp.levelType) < 0)
{
return false;
}
temp.neededEXP = this.findSolution(makevar("this.clientr.level_" @ temp.levelType));
temp.currentEXP = makevar("this.clientr.exp_" @ temp.levelType);

this.chat = format(_("I need to gain %f more experience!"), (temp.neededEXP - temp.currentEXP));
}

function findSolution(playerLevel)
{
temp.expNeeded = (((temp.playerLevel * 100) * 1000) / 50);
return temp.expNeeded;
}

public function addExperience(expType, amountAdding)
{
if (this.levelTypes.index(temp.expType) < 0)
{
return false;
}
if (temp.amountAdding == NULL)
{
return false;
}
temp.amountAdding = int(temp.amountAdding);

this.clientr.("exp_" @ temp.expType) += temp.amountAdding;
savelog2("ExpLog.txt", format(_("+%s added %f to %s!"), this, temp.AmountAdding, temp.expType));

temp.curExpAmount = makevar("this.clientr.exp_" @ temp.expType);
temp.neededEXP = this.findSolution(makevar("this.clientr.level_" @ temp.expType));

this.chat = format(_("Gained %d in %s! (%d / %d)"), temp.amountAdding, temp.expType, temp.curExpAmount, temp.neededEXP);

if (temp.curExpAmount => temp.neededEXP)
{
this.clientr.("level_" @ temp.expType) += 1;
savelog2("LevelLog.txt", format(_("+%s gained a level in %s. (Exp Gained: %f. Current Level: %i.)!"), this, temp.expType, temp.AmountAdding, this.clientr.("level_" @ temp.expType)));

this.chat = format(_("Gained a level in %s! I am now level %d!"), temp.expType, makevar("this.clientr.level_" @ temp.expType));
}
}

It's a player class, so you'll need to join it to the player (player.join("expsystem");).
It explains how to add experience to the player and also return how much EXP is needed for a certain level type.
To create your own level types, just edit the 'this.levelTypes' array.

Twinny
11-26-2006, 11:14 PM
I do mine differently. I use clientr.mud(job type) = {currentexp, exp for that level to pass, current level};
Only need 1 function now ^-^.

Also i use a exp table instead of making the new exp needed.

Chompy
11-26-2006, 11:26 PM
Weird algorithm :o

At level 5, 10000 exp needed, level 6: 12000, level 7: 14000, level 8: 16000, hmm? could of just had done like, + 2000 :p

Level 1, 2000 exp needed, hmm if you had a better algorithm it would been better :D btw, nice script :D

edit: That script looks like it would been good on a medevil server or something, magic and stuff :)
It gave me an idea :p

Samposse
11-29-2009, 05:56 AM
Hi , im Trying to get it to work :P but is it an thing Important i need to get it to work ? or only that it Join the player on login and its a class called expsystem ?

it wont work ... and btw , whats the Flags i use for it ? like clientr.level=60 or clientr.exp_cur and clientr.exp_max ? or is it even any flags i uyse for this to work :P

fowlplay4
11-29-2009, 06:37 AM
This script is pretty outdated, and the use of a single log is ultimately useless, but you just call the function (assuming you joined the class to the player on login) that it provides to you like so:


function onCreated() {
player.addExperience("Physical", 1000);
}

Samposse
11-29-2009, 10:53 AM
ok shoud i use that in an weapon to the playerr for testing the Script ? and when i level upp ,will it show ? or player say's "LEVEL UP , Curnt levle in" SPC Level "

?

may you Post all the Command i will hawe use for in this Levling System plz

Samposse
11-29-2009, 10:58 AM
i did added

function onCreated() {
player.addExperience("Physical", 1000);
}

and added the Weapon to the player and reconnect adn then Updated that Weaoon like 5 - 7 times and still nothing -.- is it working ?

fowlplay4
11-29-2009, 08:22 PM
The code I provided will not work in a weapon script like that and was just an example of the proper usage, you need to specify the player object.


function onCreated() {
findplayer("Samposse").addExperience("Physical", 1000);
}

Samposse
12-08-2009, 01:55 PM
Dos it work ?

Kyranki
12-08-2009, 08:28 PM
Dos it work ?

Yes. :asleep: