Thread: Leveling System
View Single Post
  #1  
Old 11-26-2006, 12:57 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Leveling System

PHP Code:
/*
  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(expTypeamountAdding)
{
  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!"), thistemp.AmountAddingtemp.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.amountAddingtemp.expTypetemp.curExpAmounttemp.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.)!"), thistemp.expTypetemp.AmountAddingthis.clientr.("level_" temp.expType)));

    
this.chat format(_("Gained a level in %s! I am now level %d!"), temp.expTypemakevar("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.
__________________

Last edited by Skyld; 11-26-2006 at 03:56 PM.. Reason: Use PHP tags >:(
Reply With Quote