Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:19 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.