PDA

View Full Version : Basic leveling system


Chompy
02-03-2008, 02:47 PM
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.account, this.lvl, makevar(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
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, 05: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, 01: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).


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, 06:30 PM
basic? i'll show you a basic levelup script:


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

Chompy
08-04-2008, 10: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


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:


// '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-05-2008, 12:11 AM
I'd do it with this structure:


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-05-2008, 12:21 AM
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-05-2008, 12:26 AM
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-05-2008, 12:29 AM
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
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...