0 Favourites

Re: health regenerating code

  • Hi,

    I have been using construct 2 trial for a couple months now. Making small game examples as a hobby.

    I recently stumble on this problem and would appreciate it if someone could help me. Note, I do not have enough rep... so no capx.

    This is what i have.

    Global number Healing = 0

    Global number Hp = 0

    Global Number MaxHp = 5000

    ----------------------------------

    Mouse

    |left button is down|

    System Heal > 0

    Hp < Max Hp

               system| add 1 + 1 * int((MaxHp -HP/10) to HP

               system| Subtract 1 + 1 * int((MaxHp -HP/10) from Healing

    ------------------------------------

    Problem: Works fine if healing is same or more than Max.Hp, but it goes down to negative if healing is less than maxhp.

    Well, I am pretty sure that the problem is (1 * int((text.MaxHp -HP/10) to HP) as it just do a deduction base on the number it get from there.

    Any help or pointers would much be appreciated...

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • could you please try to explai what it is you are trying to do there?

    What is this line supposed to achieve?

    add 1 + 1 * int((text.MaxHp -HP/10) to HP

    text.maxHp, so MaxHp is an instance variable of the text?

    Why not use a global variable MaxHp?

    Why HP/10?

    If I understand what you are trying to do, it will probably be easier to see where you go wrong.

  • Ah, I am sorry. I forgot to explain...

    I want to make a healing ability with a speedup attribute while holding down the mouse button.

    example:

    1) Player with current hp 160 and max hp 5000, and a potion that can heals 1-99999 hp (depending on the charges on it)

    2) holding the mouse button down heals the player and at the same time use up the potion

    3) before the player hp reach 5000 hp, the number will slow down.

    the 1 * int((MaxHp - HP)/10) was an experiment for the speed up process.

    LittleStain

    1) sorry, a typo there. (earlier i had created an instant variable to test it out, works the same as a global tho...)

    2) hp/10 is to reduce the amount gain immediately.

    if

    1 * ((max hp - hp ) / 10)

    looks like this

    1* ((5000 - 0) / 10)

    without the /10 it will instantly heals the player.

    at the same time, the healing factor will start high up and go down.

    dropbox.com/s/ur14nlfbsx784fz/Hp%20Regen.capx

    ^^ capx is as above... just add the front part

  • is this what you are after ?

    capx

  • It is almost the same as what i have in mine

    is there a way to make it fully uses up the heal? yours is not complete yet as it have a leftover of 5.

  • I thought you wanted to just stop it going negative - anyway look at "lerp" as I think this is what you are after.

    another go

    basically this now takes 5% (look at global variable "gvPercentageToTakeFromReserve) of your remaining "Health left in bottle" (heal) and adds it to your hit points (Hp)

    This does allow hit points to go over max hit points but then corrects in line 5 but you have still drank 5% of your remaining potion.

    Another (better ?) way would be to say the bottle holds 10 gulps of potion and each gulp would heal half way between your health now and max health...

    so that would become something like

    if (gulps left in bottle) > 0

    (my health)=(my Health)+lerp ((my health),(max Health),50)

    reduce (gulps left in bottle) by 1

    start some timer to allow time for potion to work

    Good luck

  • Oh. This is wonderful.

    Thank you very much RamPackWobble

    ceil(lerp(0,heal,gvPercentageToTakeFromReserve))

    so... it does this? (from the capx)

    1) 0 to 10000(heal amount) takes 5% out.

    2) Change the gvAmount then deduct and add it from others

    nice! i gained a new achievement by learning lerp <img src="smileys/smiley10.gif" border="0" align="middle" />

  • and "Thank you" for thanking me, that's all I ask for - and maybe a pint of Guinness if you ever see me out, possibly a packet of crisps and if you ever win the lottery.... <img src="smileys/smiley1.gif" border="0" align="middle" />

    As I understand it:

    lerp (a,b,p)   takes the difference of a and b and then finds p of it

    so lerp (a,b,0.5) would find halfway between a and b

    lerp (5,9,0.5) would give 2

    now in your case you only want a set percentage as we are always going from 0 so you would probably be better with setting gvHealingAmount to be heal*0.5 (if you wanted to take half for example) (we dont need the lerp)

    but if you go with what I said above (one gulp heals half of your lost health) then lerp is ideal.

    ceil (X) just rounds up the the next whole number.

    yes - my version just take some of the health left in the bottle and add it to your players health.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)