Can this be done? Explanation inside...

AvecPardon
23 Feb 2012, 03:02
Okay, so for the past week or so I've been kind of racking my brain over a script I've been trying to put together. The basics are I want to have the player character have a Health attribute and a Damage attribute that affect each other. If the player takes a certain amount of Health loss, in my case 50HP, he gains 1point of Damage. So in my head it works out to:

For every 50 or more HP lost, 1 point Damage added. If 100HP or more lost, 2 points Damage added. And so on.

I've tried several methods of spaghetti coding to get this to work, but so far it either doesn't work at all or it works far too well and the poor robot's taking on 2-5 points of damage for every 10HP that gets knocked off. I'm almost at my wit's end trying to figure this out.

Could anyone give me some pointers as to how this can be pulled off properly, if at all?

Edit:After some minor adjustments to label the attributes to match and alter my combat scripts, I've found that this function works beautifully. Thanks once again. Yes, it had slipped my mind to mention that this was going to be used via combat, so all is good.

sgreig
23 Feb 2012, 07:33
Almost anything can be done in Quest, it's just a matter of figuring out how to make it work. It doesn't sound like it would be too difficult to implement something like this, but you're a little light on the details. For example, is damage cumulative or fixed at 50hp every time the player is hit? Is this part of a combat mechanic? etc. However...

The easiest way I can think of to do this would be to have (in the case of cumulative damage) 3 attributes on the player object. One to keep track of the player's current HP (for example player.current_hp), the damage counter you want incremented (player.damage_counter) and a third stat that increments by however much damage there is and resets when it gets to 50, adding 1 point to the damage counter variable as well (call it player.hp_tally for sake of argument).

I would then write a function that would be called whenever the player takes damage, passing it the amount of damage taken. The function would probably look something like this (assuming the amount of damage being dealt is stored in the variable damage_amount):


<function name="damage_player" parameters="damage_amount"><![CDATA[
player.current_hp = player.current_hp - damage_amount
player.hp_tally = player.hp_tally + damage_amount
if (player.hp_tally >= 50) {
player.hp_tally = 0
player.damage_counter = player.damage_counter + 1
}
]]></function>


Obviously, the only issue with this function and cumulative damage is that it doesn't store the remainder if the hp_tally goes over 50, but this should give you a good starting point anyway. It's untested though, so apologies if it doesn't work at all.

Pertex
23 Feb 2012, 07:45
sgreig wrote:
Obviously, the only issue with this function and cumulative damage is that it doesn't store the remainder if the hp_tally goes over 50, but this should give you a good starting point anyway. It's untested though, so apologies if it doesn't work at all.


This shouldnt be the problem


<function name="damage_player" parameters="damage_amount"><![CDATA[
player.current_hp = player.current_hp - damage_amount
player.hp_tally = player.hp_tally + damage_amount
if (player.hp_tally >= 50) {
player.damage_counter = player.damage_counter + (player.hp_tally / 50)
player.hp_tally = 0
}
]]></function>

sgreig
23 Feb 2012, 07:53
Thanks Pertex. I know it could be done, I was just too lazy to change it, as I didn't think about it until after I'd written it all out. Good to know I got the rest of it right though. :D

AvecPardon
23 Feb 2012, 22:53
And here I was struggling to do it using only TWO attributes! XD Using a third never occurred to me. I had a feeling it was meant to be a function, but every time I wrote it, it just gave me errors. Thanks much for the help. I'll use this as a base and tweak it if needed, but it looks like it'll be perfect as it is. You guys are the best.

Cheers!

sgreig
24 Feb 2012, 05:26
NP. Glad I could help. :D