View Single Post
  #3  
Old 09-05-2011, 06:36 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
This is a very common script.

Here's my bare-bones for an EXP system:

Class: expfunctions

PHP Code:
function onCreated() {
  
// Check if EXP Level is 0
  
if (clientr.explevel == 0) {
    
// Initialize Player EXP Level and EXP Needed
    
levelUp();
  }
}

public function 
addEXP(amount) {
  
// Increment EXP by Amount
  
clientr.exp += amount;
  
checkEXP();
}

function 
checkEXP() {
  
// Calculate EXP Needed
  
temp.needed getEXPNeeded();
  
// Check if EXP Needed Matches Clientr EXP Needed Flag
  
if (clientr.expneeded != temp.needed) {
    
// Update Clientr Flag
    
clientr.expneeded temp.needed;
  }
  
// Check if EXP is Greater than or Equal to EXP Needed
  
if (clientr.exp >= temp.needed) {
    
levelUp();
  }
}

function 
getEXPNeeded() {
  
// Calculate Amount of EXP Needed for Level
  
temp.needed = (clientr.explevel 200);
  return 
temp.needed;
}

public function 
levelUp() {
  
// Set EXP to 0
  
clientr.exp 0;
  
// Increase Level
  
clientr.explevel++;
  
// Update EXP Needed for New Level
  
clientr.expneeded getEXPNeeded();

In your onActionPlayerOnline() function in Control-NPC add:

PHP Code:
// other code...
function onActionPlayerOnline() {
  
// other code...
  
player.join("expfunctions");
  
// other code...
}
// other code... 
In your other scripts you can now add exp like this:

player.addEXP(int(random(0, 100)));

Then on the client-side you can use clientr.exp, clientr.explevel, and clientr.expneeded to display on your GUIs.

Also regarding your use of:

findplayer(player.account)

If you have access to the player's account like that just use:

player

instead.
__________________
Quote:
Reply With Quote