Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-05-2011, 06:17 PM
Ohk4y Ohk4y is offline
Registered User
Ohk4y's Avatar
Join Date: Jun 2011
Posts: 43
Ohk4y is an unknown quantity at this point
Send a message via AIM to Ohk4y
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.
__________________
Reply With Quote
  #2  
Old 09-05-2011, 06:32 PM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
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.
__________________
Testbed user: I figured since I can never find any scripters it was time to take desperate measures...and...TEACH MYSELF 0.0
Reply With Quote
  #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
  #4  
Old 09-05-2011, 06:38 PM
gaben gaben is offline
uhh no
gaben's Avatar
Join Date: Aug 2011
Posts: 47
gaben is an unknown quantity at this point
Is 'random' (0,100) the range of numbers from 0-100? I can't find any documentation on this!
__________________
Quote:
Originally Posted by iBeatz View Post
Who came up with this Cheat Engine? The more I read about, the more ingenious the whole thing sounds.
Quote:
Originally Posted by Unixmad
This forums is going worst each day.
Quote:
Originally Posted by ff7chocoboknight View Post
You sure are taking your time leaving, furry.
Quote:
Originally Posted by [email protected] View Post
are u old enough 2 even play Graal little girl???
Reply With Quote
  #5  
Old 09-05-2011, 06:42 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
Quote:
Originally Posted by gaben View Post
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.
__________________
Quote:
Reply With Quote
  #6  
Old 09-05-2011, 06:46 PM
Ohk4y Ohk4y is offline
Registered User
Ohk4y's Avatar
Join Date: Jun 2011
Posts: 43
Ohk4y is an unknown quantity at this point
Send a message via AIM to Ohk4y
Okay, Thanks guys for the help! All is working now.
__________________
Reply With Quote
Reply


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 01:33 PM.


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