In almost every game, you see:
usr<<"You killed [enemy], so you gain [number] overall experience!"
Keyword there: overall.
In games, you mainly see 3-4 bars. Health, Stamina, and Experience being the main three. You kill someone, the experience bar moves a little bit. What many developers fail to see is that BYOND is much more powerful than that: they can take it so far as to give each stat it's own experience. You can even make the same procedure handle the person "leveling up" as well. Here, I will walk you through it.
Let's start off by making a 'Level' procedure.
mob
proc
Level()
There we go. Now, let's define that procedure a little more with some named arguments.
mob
proc
Level(stat as text,mod as num,DisplayText=1,max=500,min=1)
Alright. With this, we now have some arguments for the procedure. Whenever we call the Level procedure, we will have to define these arguments.
stat as text:
This is going to be the stat we will be giving experience to. The as text part means just as it says. The value used here has to be in the form of text.
mod as num:
This is how much experience will be added to the stat. It has to be a number.
DisplayText=1:
This is here to make it optional to show whether the stat gained anything or not. This will be explained more later.
max=500,min=1:
All this does is limit the experience gained. This prevents any sort of cheating, such as someone who used a bug in the game to his/her advantage and got some Administrator verbs, one of which changes the world experience mod. So if the experience they gain is over 500, it is set to 500. And the min=1 prevents people from gaining negative experience. This could be taken out as well, and you could use this procedure to take experience away from players as punishment.
Alright. We have a procedure, and arguments for it. Now we need to make it do something.
mob
var
health=100
mhealth=100
healthexp=0
healthmexp=100
healthboost=10
var
expmod=1
mob
proc
Level(stat as text, mod as num,dispText=1,max=500,min=1)
if(!src.vars[stat]) return //If the stat speicified does not exist, cancel everything
mod*=expmod // Multiply the experience by the world's experience mod
if(mod>max) mod=max // These 2 lines limit the experience, as explained earlier
if(mod<min) mod=min
src.vars["[stat]exp"]+=mod // Now lets add the mod to the stat's experience
if(src.vars["[stat]exp"]>=src.vars["[stat]mexp"]) // Now we check if the stat "leveled up"...
src.vars["m[stat]"]+=src.vars["[stat]boost"] // Boost their max stat by the stat's boost value(This allows for more dynamic "level ups".)
src.vars["[stat]exp"]=0 // Set the stat's experience back to 0...
src.vars["[stat]mexp"]+=src.vars["[stat]boost"] // And boost the stat's max experience by the stat's boost as well.
if(DisplayText)
src<<"Your [stat] has improved!" //If the DisplayText value is set to 1, tell them that the stat improved.
And that is the whole procedure, simplified.
I really hope this helps those aspiring programmers out there, hope it opened their eyes to some of the power that BYOND has, that they never saw. I would love to see more games with this concept. It could really spice up the game-play.
Please take all questions, comments, and concerns here.