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.

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.