Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Needed Formula for Exp / Level Gain (https://forums.graalonline.com/forums/showthread.php?t=134264502)

Ohk4y 09-08-2011 01:27 AM

Needed Formula for Exp / Level Gain
 
Hey guys, i'm here with another question.
--------------------------------------------------------------------------
What would be a good formula to substitute for all of this repetition:
PHP Code:

    if (clientr.exp == 200) {
      
clientr.explevel 2;
      
clientr.exp 1;
      
clientr.expneeded 199;
    }
    if (
clientr.exp 400) {
      
clientr.explevel 3;
      
clientr.exp 1;
      
clientr.expneeded 399;
    }
    if (
clientr.exp 800) {
      
clientr.explevel 4;
      
clientr.exp 1;
      
clientr.expneeded 799;
    }
    if (
clientr.exp 1600) {
      
clientr.explevel 5;
      
clientr.exp 1;
      
clientr.expneeded 1599;
    }
    if (
clientr.exp 3200) {
      
clientr.explevel 6;
      
clientr.exp 1;
      
clientr.expneeded 3199;
    }
    if (
clientr.exp 6400) {
      
clientr.explevel 7;
      
clientr.exp 1;
      
clientr.expneeded 6399;
    }
    if (
clientr.exp 12800) {
      
clientr.explevel 8;
      
clientr.exp 1;
      
clientr.expneeded 12799;
    } 

Thanks in advance!

fowlplay4 09-08-2011 01:32 AM

temp.needed = (2 ^ clientr.explevel) * 100;

Ohk4y 09-08-2011 01:36 AM

Quote:

Originally Posted by fowlplay4 (Post 1667386)
temp.needed = (2 ^ clientr.explevel) * 100;

How would I implent that?

fowlplay4 09-08-2011 01:43 AM

If you are using my EXP Barebones then all you need to do is replace the temp.needed line in the getEXPNeeded function.

Link: http://forums.graalonline.com/forums...58&postcount=3

scriptless 09-08-2011 01:44 AM

Quote:

Originally Posted by Ohk4y (Post 1667388)
How would I implent that?

PHP Code:

if ( clientr.exp => temp.needed ) {
  
// stuff


I would imagine.

Ohk4y 09-08-2011 01:47 AM

Okay, I replaced it and it is working now, thanks again fowlplay4!

Ohk4y 09-08-2011 02:00 AM

>_<
 
Wait, Nevermind. It just about killed my hud that displays all of the information..
>_<
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) * 100;
  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(); 


weapon : -System/LevelUp
PHP Code:


function onActionServerSide(cmd) {
  if (
cmd == "LevelUp") {
    if (
clientr.exp == null) {
      
clientr.exp 1;
    }
    if (
clientr.explevel == null) {
      
clientr.explevel 1;
    }
    if (
clientr.expneeded == null) {
      
clientr.expneeded 199;    
    }
    if ( 
clientr.exp => temp.needed ) { 
      
temp.needed = (clientr.explevel) * 100;
    }  
  }
}

//#CLIENTSIDE
function onCreated() onTimeOut();
function 
onTimeOut() {
triggerserver("gui"name"LevelUp");
setTimer(.05);



fowlplay4 09-08-2011 02:08 AM

You don't need that system at all, and all your system is doing is spamming the server with triggers for no reason...

Everything is taken care of in the player-joined expfunctions class.

All you have to do in other systems is call the player's addEXP function.

Show me what script you have in your onActionPlayerOnline function in your Control-NPC, because I have a feeling you might not even be using it correctly.

Ohk4y 09-08-2011 02:11 AM

PHP Code:

function onActionPlayerOnline() {
  
//list of other weapons I had but chose not to include in this post :p
  
player.join("expfunctions"); 

    
showStats(0x400+0x200+0x100);
  
EnableFeatures(AllFeatures 4);    
  echo(
"Esteria (Server): "@player.communityname@" has logged in!");
  }

 
/* if (this.accounts.index(player.account)==-1) 
  {
    this.accounts.add(player.account);
    sendtorc("/reset "@ player.account);
  } */ 


cbk1994 09-08-2011 02:22 AM

showStats and enableFeatures are both clientside-only, they shouldn't be in onActionPlayerOnline.

Ohk4y 09-08-2011 02:24 AM

Quote:

Originally Posted by cbk1994 (Post 1667398)
showStats and enableFeatures are both clientside-only, they shouldn't be in onActionPlayerOnline.

I didn't add them there, though I will remove them, thank you.

fowlplay4 09-08-2011 02:27 AM

Alright now in other scripts you just have to call:

player.addEXP(100); or findplayer("Ohk4y").addEXP(100);

To add experience to yourself, expfunctions then internally checks to see if you gained enough EXP to level up. The class is flexible enough so you don't have to reset EXP if you change your EXP Needed formula.

It also initializes the player to level 1 if they haven't logged in before (or if their level is 0).

You can also call:

player.levelUp(); if you just want to directly level yourself.


All times are GMT +2. The time now is 05:42 AM.

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