Damage Summing Script

Posted by Iterator on Sun 12 Feb 2012 08:56 PM — 2 posts, 16,230 views.

#0
Hi everyone. I'm new to MUSH scripting (and scripting in general) but do have a background in Java.

I'm currently playing a mud where a certain ability rages you and you can't see your HP. I'm wanting to have a script that I can call from triggers and have it tally how much damage I've taken.

I've figured out an average of which hit takes how much: very hard, extremely, pulverized, etc. So these triggers would call the script and the script would add this value to the total and some how display this to the user.. or possibly deduct it from that characters total hp and return that.

Is this possible, and if so could someone point me in the right direction?

Thanks!

/iterator
#1
don't know if you're still wanting an answer.


var rageTracker = {
   hp: 0,
   veryHard: 5,//don't know avg damages so I'm making them up
   extremely: 10,
   pulverized: 20,
   etc: 40,
   init: function(currentHp) {
      this.hp = currentHp;
   }
   //this function treats its argument as a string.
   hpMod: function(gotHit) {
      //replace any white space with no space
      //then make it lower case.
      var hitSeverity = gotHit.replace(" ","").toLowerCase();
      //if passed veryhard then hitSeverity is equal to 5 and etc.
      hitSeverity = this[hitSeverity];
      //hp is modified and then noted in the world
      this.hp = this.hp - hitSeverity;
      world.Note(this.hp);
   }
}


When you log in you'd set your hp with an alias with the code:
rageTracker.init(80)

or what ever your current hp is. then in your triggers...if the message is something like: "you get hit very hard" you'd send to script:
rageTracker.hpMod("very hard");

then you'd get a note saying 75 (80 - 5 = 75)