Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Problem with exp gain and leveling up (https://forums.graalonline.com/forums/showthread.php?t=134264485)

Ohk4y 09-05-2011 06:17 PM

Problem with exp gain and leveling up
 
I have an issue with leveling up in my script. When you kill a player it adds exp to you account with a script:
PHP Code:

findplayer(player.account).clientr.exp += int(random(511)); 

I'm trying to get it to level a player up depending on the amount of exp they have. For example;
Level 1 = 0 exp - 199 exp
Level 2 = 200 exp - 399 exp
Level 3 = 400 exp - 799 exp

How could I get it to change the level of the player, which is stored as clientr.level, when the player has anywhere between two numbers with out listing everything out like
PHP Code:

this.level1 = {1,2,3,4,5,6,7,8,9,10}; 

Thanks.

DrakilorP2P 09-05-2011 06:32 PM

Something like this?
PHP Code:

public function addExperience(temp.amount)
{
  
temp.experienceTable = {
    
0,   //Level 1
    
100//Level 2
    
300//Level 3
    
600//Level 4
    
1000 //Level 5
  
};
  
  
this.clientr.rpg_experience += temp.amount;
  
  
temp.newLevel = -1;
  for (
temp.temp.experienceTable.size() - 1temp.>= 0; --temp.i)
  {
    if (
temp.experienceTable[temp.i] <= this.clientr.rpg_experience)
    {
      
temp.newLevel temp.1;
      break;
    }
  }
  
  
assert(temp.newLevel != -1);
  
  if (
temp.newLevel != this.clientr.rpg_level)
  {
    
this.clientr.rpg_level temp.newLevel;
    
this.trigger("onLevelUp");
  }


Sorry for just posting code; I'm not sure how to describe it in English.

fowlplay4 09-05-2011 06:36 PM

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.

gaben 09-05-2011 06:38 PM

Is 'random' (0,100) the range of numbers from 0-100? I can't find any documentation on this!

fowlplay4 09-05-2011 06:42 PM

Quote:

Originally Posted by gaben (Post 1667159)
Is 'random' (0,100) the range of numbers from 0-100? I can't find any documentation on this!

Yes, it will never equal the maximum though.

int(random(0,100)) - int 'floors' the value which means it will always return a number >= 0 and <= 99.

Ohk4y 09-05-2011 06:46 PM

Okay, Thanks guys for the help! All is working now.


All times are GMT +2. The time now is 11:12 PM.

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