Leveling system, saving current exp

After having a lovely night of scripting and such I have near completed my Leveling exp system :smiley:

Only two things remain slight errors:

1: You lose your current EXP progression when you go offline (setting a client.var would set this straight but I can't seem to get my head around how to go about setting it)

2: The system currently keeps all existing EXP after you level and continues from where the last exp counter was (EG when 50/60 to level you level and then it stays at 60/100 Ect…) This second one really isn't much of an issue since I can just up the amount needed Till next level.

Any advice would be helpful I will add the code in now, Sorry about the mess its in ^^'

[code]// NPC made by Hashi
if (playerenters) {toweapons EXPSYS;
}

if (playerenters&&!sysexp) {

insertstring client.exp,0,50; //till next level

insertstring client.exp,1,0; //current exp

insertstring client.level,0,1; //players level

insertstring client.level,1,10; //players max level

insertstring client.perkill,0,0; //exp per kill

set sysexp;
timeout = 0.05;
}

if (isweapon || timeout) {

showtext 300,32,32,Arial,Saved:(#I(client.exp,2));
showtext 301,32,34,Arial,EXP:(#I(client.exp,1)/#I(client.exp,0));
showtext 302,32,36,Arial,LVL:(#I(client.level,0));
showtext 303,32,38,Arial,MAXLVL:(#I(client.level,1));

timeout = 0.05;
}
if (strequals(#I(client.level,0),#I(client.level,0))) {
client.nextlvl = strtofloat(#I(client.level,0))+1;
}
client.curlvl =strtofloat(#I(client.level,0));
client.curexp =strtofloat(#I(client.exp,1));
client.tnlexp =strtofloat(#I(client.exp,0));
client.getexp =strtofloat(#I(client.exp,0))+50;

if (client.curexp>client.tnlexp){
replacestring client.level,0,#v(client.nextlvl);
setplayerprop #c,congrats! you are now level #v(client.curlvl+1);
replacestring client.exp,0,#v(client.getexp+strtofloat(#I(client.exp,0)));
}

// Save exp
//if (strequals(#I(client.exp,1),#I(client.exp,1))) {
//
//}

//Stop player going over Maxlevel
if (strequals(#I(client.level,1),#I(client.level,0))) {
insertstring client.exp,0,-1;
insertstring client.exp,1,-2;
showtext 301,32,34,Arial,EXP:(-/-);[/code]

You can see what I was thinking when I started to add the save exp part but kind of realised it would reset everytime you got more exp… which obviously brings a problem if it keeps resetting.

This part of the code is on the NPC enemy and it triggers the exp gain from the NPC you kill :

client.ep += 25; // how much exp this npc gives when killed replacestring client.exp,1,#v(strtofloat(#I(client.perkill,0))+client.ep);

its obviously built into his death function

Thanks for any help that I get in advance! <3 sleep time now :3

Re: Leveling system, saving current exp

Seems to work good when I try it. To the first issue, the server doesn’t save “client.vars” only client.strings. So the vars will be reset next when they log off. Easy fix would just be converting them back and forth between strings.

To the second issue, you could just replacestring the exp back to 0 when you hit a levelup. And if you get a problem with it cutting off the remaining that way, just have it subtract the exptolevel amount from the current exp and setting the current exp to that number.

Though I like the way you keep adding the total exp, kinda cool.

Edit: Noticed a slight bug, it works perfect to level 9. But when it hits lvl 10(max level) it jumps you to level 20, and allows you to keep leveling.

Re: Leveling system, saving current exp

Thats one hell of a bug haha I'll test it right now it should technically just set the exp till next level to -1 and current to -2… and I'll see what I can do about the strings when I'm done with it I'll post it up for people to use if they want it.

-Edit- Yeah I see whats happening “if (client.curexp>client.tnlexp)” no matter how much exp you get it will be always above -2 which then keeps counting the levels upward hahaha hmm…[br][br]Double Posted on: April 02, 2008, 02:42:34 AM_________________________________________________[br]And almost done! fixed the going over maxlevel and saving the exp when enterlevel or offline, its not the best most efficient script and if anyone could think of ways to improve it go ahead!

Make an empty npc and add this:

[code]// NPC made by Hashi
if (playerenters) {toweapons EXPSYS;
}

if (playerenters&&!sysexp) {

insertstring client.exp,0,50; //till next level

insertstring client.exp,1,0; //current exp

insertstring client.level,0,0; //players level

insertstring client.level,1,20; //players max level

insertstring client.perkill,0,0; //exp per kill

set sysexp;
timeout = 0.05;
}

if (isweapon || timeout) {

//debugging text
showtext 301,32,34,Arial,EXP:(#I(client.exp,1)/#I(client.exp,0));
showtext 302,32,36,Arial,LVL:(#I(client.level,0));
showtext 303,32,38,Arial,MAXLVL:(#I(client.level,1));
showtext 304,playerx,playery+3,Arial,Lv:#I(client.level,0);

timeout = 0.05;
}

//setting +1 for new level
if (strequals(#I(client.level,0),#I(client.level,0))) {
client.nextlvl = strtofloat(#I(client.level,0))+1;
}

//setting client.vars for strings
client.maxlvl =strtofloat(#I(client.level,1));
client.curlvl =strtofloat(#I(client.level,0));
client.curexp =strtofloat(#I(client.exp,1));
client.tnlexp =strtofloat(#I(client.exp,0));
client.getexp =strtofloat(#I(client.exp,0))+50;

//Level up!
if (client.curexp>client.tnlexp){
replacestring client.level,0,#v(client.nextlvl);
replacestring client.exp,0,#v(client.getexp+strtofloat(#I(client.exp,0)));
replacestring client.exp,1,0;
timeout = 0.05;
}

//Stop player going over Maxlevel
if (client.curlvl==client.maxlvl || client.curlvl>client.maxlvl) {
client.curexp =0;
replacestring client.exp,0,-1;
replacestring client.exp,1,-2;
replacestring client.level,0,#v(strtofloat(#I(client.level,1))); //players level

showtext 301,32,34,Arial,EXP:(-/-);
timeout = 0.05;
}[/code]

Then add this to any NPC you want to get exp from (in their death function, also you could have this in a putnpc txt file to be called OR its own txt file to be joined with an NPC script)

client.ep +=5; replacestring client.exp,1,#v(strtofloat(#I(client.exp,1))+client.ep);

Enjoy the script and if you need help just PM me or leave me a message on my RC ^^