how to regenerate(ability regenerate) by percentage with respect to hitpoints?

It's not easy creating an entire faction or era. Post your work and collaborate in this forum.

Moderator: Forum Moderators

ultimatux
Posts: 15
Joined: May 29th, 2012, 4:02 am

how to regenerate(ability regenerate) by percentage with respect to hitpoints?

Post by ultimatux »

hi comunity!!
i'am noob and sorry my english is bad haha... this is my code,

Code: Select all

#define ABILITY_REGENERACION_MENOR
    [regenerate]
        value=5%
        id=regeneracion menor
        name= _ "regeneracion menor"
        description=_"
La unidad se regenera 5% del HP por turno."
        affect_self=yes
       poison=slowed  
    [/regenerate]
#enddef
clarification: percentage of current hitpoints, not total of the unit

thanks
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: how to regenerate(ability regenerate) by percentage with respect to hitpoints?

Post by gfgtdf »

ultimatux wrote: July 21st, 2018, 7:43 pm hi comunity!!
i'am noob and sorry my english is bad haha... this is my code,

Code: Select all

#define ABILITY_REGENERACION_MENOR
    [regenerate]
        value=5%
        id=regeneracion menor
        name= _ "regeneracion menor"
        description=_"
La unidad se regenera 5% del HP por turno."
        affect_self=yes
       poison=slowed  
    [/regenerate]
#enddef
clarification: percentage of current hitpoints, not total of the unit

thanks
you have to use formula that is enables by putting backets around the value, like for example

Code: Select all

#define ABILITY_REGENERACION_MENOR
    [regenerate]
        value="(hitpoints * 0.05)"
        id=regeneracion_menor
        name= _ "regeneracion menor"
        description=_"
La unidad se regenera 5% del HP por turno."
        affect_self=yes
       poison=slowed  
    [/regenerate]
#enddef
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
ultimatux
Posts: 15
Joined: May 29th, 2012, 4:02 am

Re: how to regenerate(ability regenerate) by percentage with respect to hitpoints?

Post by ultimatux »

I'm sorry, the code does not work. I try without parenthesis and without quotes too, but nothing happens.
it only takes as value the first number, for example 10 * 0.5, in that case it only takes 10, in the case of (10 * 0.5) with parentheses, it does not take any value.
also does not take the word hitpoints as a variable.
I've been testing in many ways and nothing happens
ultimatux
Posts: 15
Joined: May 29th, 2012, 4:02 am

Re: how to regenerate(ability regenerate) by percentage with respect to hitpoints?

Post by ultimatux »

I'm sorry, the code does not work. I try without parenthesis and without quotes too, but nothing happens.
it only takes as value the first number, for example 10 * 0.5, in that case it only takes 10, in the case of (10 * 0.5) with parentheses, it does not take any value.
also does not take the word hitpoints as a variable.
I've been testing in many ways and nothing happens
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: how to regenerate(ability regenerate) by percentage with respect to hitpoints?

Post by gfgtdf »

no the code is correct asis. There must be something else that you are doing wrong. Maybe your unit does not have enough hp left, if you unit has less than 20hp then 5% of that will be less than one so this code will not heal units with less than 20hp.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
ultimatux
Posts: 15
Joined: May 29th, 2012, 4:02 am

Re: how to regenerate(ability regenerate) by percentage with respect to hitpoints?

Post by ultimatux »

lo cambie a 50% por las dudas .

Code: Select all

#define ABILITY_REGENERACION_MENOR
[regenerate]
      value="(hitpoints * 0.5)"
        id=regeneracion menor
        name= _ "regeneracion menor"
        description=_"
La unidad se regenera 50% por turno."
        affect_self=yes
       poison=slowed  
    [/regenerate]
#enddef


value="(hitpoints * 0.5)" try this way and nothing happens
value="(10 * 0.5)" try this way and nothing happens too
value="10*0.5" it only takes the value of 10
value="hitpoints" try this way and nothing happens


note that the unit has enough hp. The code does not work

I have version 1.12.5
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: how to regenerate(ability regenerate) by percentage with respect to hitpoints?

Post by gfgtdf »

oh ok i was assuming you were using the current stable wesnoth version which is wesnoth 1.14, what i said before won't work on wesnoth 1.12

In wesnoth 1.12 you ahve to implement it manually with [event]s
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
ultimatux
Posts: 15
Joined: May 29th, 2012, 4:02 am

Re: how to regenerate(ability regenerate) by percentage with respect to hitpoints?

Post by ultimatux »

Is this code also good? for version 1.14

I will download it



Code: Select all

#define ABILITY_REGENERACION_MENOR

    [regenerate]


        value="$( $ unit.hitpoints * 0.5)"
        id=regeneracion menor
        name= _ "regeneracion menor"
        description=_"
La unidad se regenera 50% por turno."
        affect_self=yes
       poison=slowed  
    [/regenerate]
#enddef
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: how to regenerate(ability regenerate) by percentage with respect to hitpoints?

Post by gfgtdf »

No that code won't work in 1.14, At least it won't behve the same way beause the usualy '$' substitution is not used when calculating abilitites.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
octalot
General Code Maintainer
Posts: 783
Joined: July 17th, 2010, 7:40 pm
Location: Austria

Re: how to regenerate(ability regenerate) by percentage with respect to hitpoints?

Post by octalot »

There's a 1.12-compatible event-based regen in SXC https://github.com/TeamSurvivalXtreme/S ... s.cfg#L236 (note that it needs everything down to line 312, and the in SXC the units often have 700 hp so if it accidentally regens 8 extra hp then we wouldn't notice).

However, if 1.14 now supports percentage-based regen then all of that code can be cleaned up, thanks gfgtdf.
User avatar
Pentarctagon
Project Manager
Posts: 5527
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: how to regenerate(ability regenerate) by percentage with respect to hitpoints?

Post by Pentarctagon »

The space between $ unit.hitpoints would also cause issues, I assume?
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
Ravana
Forum Moderator
Posts: 2949
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: how to regenerate(ability regenerate) by percentage with respect to hitpoints?

Post by Ravana »

You dont have wml variables access in that context, so using $ in the first place would be useless.
ultimatux
Posts: 15
Joined: May 29th, 2012, 4:02 am

Re: how to regenerate(ability regenerate) by percentage with respect to hitpoints?

Post by ultimatux »

thank you all, download and install version 1.14.3
ultimatux
Posts: 15
Joined: May 29th, 2012, 4:02 am

Re: how to regenerate(ability regenerate) by percentage with respect to hitpoints?

Post by ultimatux »

I do not know if it is okay to ask another question in the same thread, I already try the code in version 1.14 and it works, but since you work with a percentage I want that when you reach a certain amount of hp the percentage value changes to a fixed value.

for example

normally 50% is regenerated per shift

but if the unit reaches 20 hp that only regenerates 3hp per turn.

it happens that logically I would use conditions with "if" but I would not know how to write in the wml code ..

I hope you understand by my English
Post Reply