HP in Pixie's CombatLib

I know this forum has seen a lot of posts on health, but I haven't seen anything that addresses my specific concern. I've read that the built-in health system is very inflexible, and I should make my own. This is something I've seen tutorials on and feel like I can do... HOWEVER... I've implemented Pixie's Combat Library, and I don't want to break anything that's already working. Right now combat is working as intended. I can damage enemies and kill them, they can damage me and kill me, but I'm stuck with a health system that displays a percentage (undesireable), and does not seem to update during combat. I'm worried that turning off health and making my own HP system will cause the CombatLib's functionality to break. Does anyone have any insight on this?


I believe displaying a percentage is just a problem with the display code, and not something with the underlying code. Take what I say with a grain of salt, though.


I was never able to find the code under the hood that’s running the health system. I don’t see where an integer is assigned for the player’s health. Which means, when a monster hits for 15 damage, I don’t know if they are doing 15% damage, or 15 points from a life total attribute hidden somewhere. Very confusing.


For anyone who might have this issue in the future, the answer is to simply create an attribute for your player object called hitpoints and assign an integer. Then, in that attribute, assign a change script with the following...

if (player.hitpoints <= 0) {
  msg ("You have died! ")
  finish
}

I snagged that code from a different post Pixie made. Apparently, CombatLib is already set up for the hitpoint attribute, as enemy attacks subtract HP from my hitpoint total without me having to do any additional programming. Then for my status panel, I created a Status Attribute, labeled it hitpoints, and then set the value to "hitpoints:!/40".

Now I just need to figure out how to cap the HP stat at 40 when introducing healing potions, and how to change the max value of the hitpoints attribute when the player levels up.


Now I just need to figure out how to cap the HP stat at 40 when introducing healing potions

Often, this is done using the same changescript. So it looks like:

if (this.hitpoints <= 0) {
  msg ("You have died!")
  finish
}
else if (this.hitpoints > 40) {
  this.hitpoints = 40
}

When something adds to the HP, if it goes over the maximum, this will set it back to 40 again.


and how to change the max value of the hitpoints attribute

If you create a separate attribute for the maximum, something like maxhitpoints then you can use that instead.

So the changescript for hitpoints would be:

if (this.hitpoints <= 0) {
  msg ("You have died!")
  finish
}
else if (this.hitpoints > this.maxhitpoints) {
  this.hitpoints = this.maxhitpoints
}

and the changescript for maxhitpoints would be:

dictionary remove (this.statusattributes, "hitpoints")
dictionary add (this.statusattributes, "hitpoints", "hitpoints: !/"+this.maxhitpoints)

so that it changes the maximum displayed in the status pane (although this would also have the effect of moving the hitpoints to the bottom of the status attributes pane; if you don't want that to happen, you might need to do something a little more complex.


Excellent info! Thank you. That is what I was going to try. Glad to know my thinking is not faulty. Now I'm having a different problem that seems related and is basically the same problem, but I haven't been lucky enough to figure out the solution. I'm trying to display the armour value under the HP in the Status panel. From the research I've done, I can see that the function GetArmour is supposed to add all armor bonuses together and return a value, but I can't figure out how to add this output to the status panel as a status attribute. I tried creating an armour:! value for the Armour attribute, but that is not working. Do I need to add an Armour attribute to the player? And if so, how do I get that to tie into the Wearables protection/armour system?


Status attributes basically just show the attributes of the player. So in order for something to show up on there, it needs to be an attribute.

I think that armour values normally come from the player's equipment, rather than the player themself. So to make it appear as a status attribute, you would need to calculate it and add it as an attribute every time the player's armour changes.

This could be as simple as having a turnscript which does something like:

player.armour = GetArmour()

I'd suggest simply putting that in a turnscript, so it updates the status attributes every turn


Oh… and the changedmaxhitpoints thing rewritten in a way that doesn't change the order of the status attributes:

newstatusattributes = NewStringDictionary()
foreach (attr, this.statusattributes) {
  if (attr = "hitpoints") {
    value = "hitpoints: !/"+this.maxhitpoints
  }
  else {
    value = DictionaryItem (this.statusattributes, attr)
  }
  dictionary add (newstatusattributes, attr, value)
}
this.statusattributes = newstatusattributes

This basically copies the entire dictionary of status attributes, changing the value if it is hitpoints.


Thanks for all your help! Super helpful. The GetArmour function doesn't seem to be updating player.Armour, but perhaps I don't have that attribute set up correctly either. I've got it set up to be an integer (set to 0), but perhaps it should be set to something else? I was able to goose the system by adding scripts on the wearables tab for when it's put on or taken off. Like so:

player.Armour = player.Armour + 1

But I know this is sloppy because I have to add this code to every wearable with an armour value, and then I'll have to add that script to all the verbs associated with shields rather than relying on an automated function like GetArmour. Either way, even if I do get this to display the armour bonus properly, do you know of any way to confirm that the armour bonus is actually being applied? Any way to see the math behind the scenes while running the game?


But I know this is sloppy because I have to add this code to every wearable with an armour value, and then I'll have to add that script to all the verbs associated with shields rather than relying on an automated function like GetArmour.

That's why it's easier to use something like the code I suggested.
I know some people have done stuff like this with wearables that modify a stat when they are added or removed; but this usually ends up being a lot of effort. Different ways to do the same job.

Either way, even if I do get this to display the armour bonus properly, do you know of any way to confirm that the armour bonus is actually being applied?

I assume that if your armour increases this attribute when it is put on, and reduces the attribute when it's removed, you can simply look at the attribute every time you need to know the current armour value. So you could change your GetArmour function to be simply:

return (player.Armour)

and it uses the number that's being displayed.

Alternatively, you could change your combat function so that it uses player.Armour whenever it needs the current value.

Any way to see the math behind the scenes while running the game?

The usual way to see what's going on behind the scenes is to use "breadcrumbs". Basically, you go into the function you want to examine, and add extra lines reporting on what's going on. You might add lines like:

msg ("Calculating attack by " + attacker + " against " + target)
msg ("Roll is: " + roll)
msg ("Damage is " + damage)

and basically put lines all through the function, printing out the values of all the temporary variables. Then you can test the game, look at those values, and you can see that they are all sane.

(I haven't used CombatLib, so I don't know what variables it uses. But the method is basically the same for any code. Add lines printing out all the temporary values; try it and make sure those values are what you think they should be; and then remove those lines again before you release the game to the public)

An alternative way of using breadcrumbs, which I now use more often, is to do it in the console.

This looks more like:

JS.console.log("Calculating attack by " + attacker + " against " + target)
JS.console.log("Roll is: " + roll)
JS.console.log("Damage is " + damage)

This means that the game plays normally, and the extra information appears in the Javascript console. In the web player, you can access this by pressing Ctrl+Shift+J while playing (may be different for other browsers); I believe in the desktop player it's available on a menu somewhere, but I'm not sure.

The JS console is useful, because it means if you forget to remove one of the breadcrumbs, the player is unlikely to see it. And if you're testing the game and something weird and unexpected happens, it's easier to find out what was going on.

There's also a "dev mode" in later versions of Quest, which gives you a new way to check some of these things - but I still haven't got used to using that yet.


Log in to post a reply.

Support

Forums