Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Basic leveling system (https://forums.graalonline.com/forums/showthread.php?t=78586)

Chompy 02-03-2008 02:47 PM

Basic leveling system
 
PHP Code:

function onActionServerside() {
  switch(
params[0]) {
    case 
"levelup":
      
// Add leveling up code here
    
break;
    case 
"report":
      
makevar(params[4]) = params[2]; // Resets level to old level
      
sendtorc("[LEVELING ABUSE]: "params[1] @" leveled from "params[2] @" to "params[3] @"!");
    break;
  }
}
//#CLIENTSIDE
function onCreated() {
  
/* Change this to your level variable being used,
     for example: "clientr.level" */
  
this.levelvar "clientr.level";
  
  
/* Change this to your exp variables being used,
     for example: {"clientr.exp", "clientr.maxexp"} */
  
this.exp = {"clientr.exp""clientr.maxexp"};
  
  
  
// Don't change anything below, unless you want to change
  // the timeout or edit the anti-abuse yourself :)
  
this.leveling false;
  
this.lvl makevar(this.levelvar);
  
setTimer(1);
}
function 
onTimeout() {
  if (!
this.leveling) {
    if (
makevar(this.exp[0]) >= makevar(this.exp[1])) {
      
this.leveling true;
      
triggerserver("gui"this.name"levelup"player.account);
    }
  }else if (
this.lvl makevar(this.levelvar)) {
    if ((
makevar(this.levelvar)-this.lvl) == 1) {
      
this.leveling false;
      
this.lvl makevar(this.levelvar);
      
    }else if ((
makevar(this.levelvar)-this.lvl) > 1) {
      
player.triggerserver("gui"this.name"report"player.accountthis.lvlmakevar(this.levelvar), this.levelvar);
      
sleep(0.5);
      
serverwarp("login2");
    }
  }
  
setTimer(1);


Well, a basic leveling system with a little anti-abuse system. Basicly, with this system you can't level up 2 levels at once. If your level changes by 2 or above from your old level it will register by echo'ing at rc that the person got his levels up by 2 or above, reset his level and then serverwarp him to login2.

It might look kinda messy, but that's because I added support so you could modify it by only changing two vars listed in the onCreated() event (this.levelvar and this.exp).

If you want to add more logging, simple edit the switch case labeled reset with code you want in. I have not added any leveling up code, that you have to make yourself, so it will fit your server's leveling up plans etc.

Any questions, suggestions to improve it etc are welcome.

And.. uhm.. enjoy?

cbk1994 02-03-2008 03:44 PM

JEEZ MAN. Calm down! lol

You're posting like two things in a day in the code gallery.

Great script as always! ^^

Chompy 02-03-2008 03:47 PM

Quote:

Originally Posted by cbkbud (Post 1373447)
JEEZ MAN. Calm down! lol

You're posting like two things in a day in the code gallery.

Great script as always! ^^

Thanks Chris :D Yeah, I feel in a mood to release stuff :P

Planning on releasing some of my old stuff, maybe some old mudlib I've done :o

Anyways, thanks again :)

kodster200 07-08-2008 04:05 AM

k newb question i know but

1. can i possibly use this on my friends server?

2. does it just go into like a weapon type script oooor is it much more advanced xD i r nub

xXziroXx 07-08-2008 12:16 PM

Sorry Chompy, but I don't like it. Any half decent leveling system would be controlled entirely on serverside, and definitely not in a timeout. All checks should be in a level up function, that ONLY an add exp function would trigger (ever).


Quote:

Originally Posted by kodster200 (Post 1401447)
k newb question i know but

1. can i possibly use this on my friends server?

2. does it just go into like a weapon type script oooor is it much more advanced xD i r nub

1. You may use all codes in the Code Gallery anywhere you want to.

2. Yes, in a Weapon NPC.

_Z3phyr_ 08-02-2008 05:30 PM

basic? i'll show you a basic levelup script:

PHP Code:

if (exp>needed) {
  
levelup();
}
function 
levelup() {
  
level++;
  
//levelup code here



Chompy 08-04-2008 09:17 PM

Hmm, just noticed that this thread was bumped..

Ziro, the code is old though ;o I'll see if I get time to update the code though..

Edit: Made this up fast

PHP Code:

public function onCheckExp(obj) {
  if (
obj.clientr.exp >= obj.clientr.maxexp) {
    
onLevelUp();
  }
}

function 
onLevelUp() {
  
// leveling up code here


Basically where you add exp to the player, you would trigger the function onCheckExp(obj), obj being the object of the player.

For example if you put this script in a wnpc named LevelingSystem, you would do this where you add exp:

PHP Code:

// 'temp.pl' being the player object

LevelingSystem.trigger("CheckExp"temp.pl);

// or

LevelingSystem.onCheckExp(temp.pl); 

Could probably improve it later, just don't have the time right now

xXziroXx 08-04-2008 11:11 PM

I'd do it with this structure:

PHP Code:

function AddMoreExp()
{
  
currentexperience ++;
  if (
currentexperience >= maxexperience) {
    
LevelUp();
  }
}

function 
LevelUp()
{
  if (
currentexperience maxexperience) {
    echo(
"AHMAGAWD CORRUPT STAFF SLASH HACKER ALERT!!!");
    return;
  }

  
currentexperience -= maxexperience;

  
// Level up!


Rough draft, but you get the idea.

Chompy 08-04-2008 11:21 PM

Hmm, that code wouldn't do well though, as it would return all the time :O

But, yeah, I would of made the levelup() function public or an addexp() function.. but yeah, get the 'draft' ;p

xXziroXx 08-04-2008 11:26 PM

Quote:

Originally Posted by Chompy (Post 1411407)
Hmm, that code wouldn't do well though, as it would return all the time :O

I fixed that while you were typing, forgot to change >= to < after I copied it from AddMoreExp() ^^

Chompy 08-04-2008 11:29 PM

Quote:

Originally Posted by xXziroXx (Post 1411408)
I fixed that while you were typing, forgot to change >= to < after I copied it from AddMoreExp() ^^

:] Yeah, I was wondering if you did it fast :o

xfazex 02-26-2009 09:13 PM

Does this just go as a server wnpc and add it to myself for testing? Did that and didn't see anything at all.

I r noob.

Chompy 02-28-2009 03:09 PM

Quote:

Originally Posted by xfazex (Post 1469763)
Does this just go as a server wnpc and add it to myself for testing? Did that and didn't see anything at all.

I r noob.

Depends on which code you used.

The latest ones, (the ones without a timeout) are more of an 'utility' code, which you use after adding experience to the player.

The script is quite old (based on when I made it), and now a days I would of done it another way :)

PS: This script is dependent that you script the leveling up formula and the actions the script will do when the player actually levels up :p

xfazex 02-28-2009 06:34 PM

Only if I was better at GS2...


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

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