modify_unit and healing
Moderator: Forum Moderators
Forum rules
- Please use [code] BBCode tags in your posts for embedding WML snippets.
- To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
modify_unit and healing
Hello. I have a problem with Trading modification in WesGothic 7 (https://www.moddb.com/mods/wesgothic/do ... early-beta).
It's supposed to allow player to buy a healing potion and heal an unit, but it's not always working as intended - healing sometimes don't happen. Anyone know how can I fix it? The file responsible for trading is "macros/zzmod_trade.cfg".
It's supposed to allow player to buy a healing potion and heal an unit, but it's not always working as intended - healing sometimes don't happen. Anyone know how can I fix it? The file responsible for trading is "macros/zzmod_trade.cfg".
Code: Select all
#textdomain wesnoth-wesgothic7
[modification]
id=wesgothic7_trade
name= _ "WesGothic 7: Trade"
description= _ "This modification is adding trade in villages."
type=mp
require_modification=yes
allow_era=wesgothic7_v1
#define WG7_NO_GOLD
[else]
[message]
speaker=unit
side_for=$side_number
message= _ "I don't have that much gold."
[/message]
[/else]
#enddef
#define WG7_TRADE_ESSENCE_OF_HEALING
{VARIABLE wesgothic7_trade_stored_unit.moves 0}
{VARIABLE wesgothic7_trade_stored_unit.attacks_left 0}
[unstore_unit]
[filter]
x,y=$x1,$y1
[/filter]
variable=wesgothic7_trade_stored_unit
find_vacant=no
text= _ "Essence of Healing"
red,green,blue=0,0,255
[/unstore_unit]
[sound]
name=DRINK_POTION.ogg
[/sound]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[effect]
apply_to=hitpoints
increase=20%
[/effect]
[/modify_unit]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[effect]
apply_to=status
remove=wg7injured
[/effect]
[/modify_unit]
[remove_object]
x,y=$x1,$y1
object_id=wesgothic7_v1_injured_obj
[/remove_object]
#enddef
#define WG7_TRADE_EXTRACT_OF_HEALING
{VARIABLE wesgothic7_trade_stored_unit.moves 0}
{VARIABLE wesgothic7_trade_stored_unit.attacks_left 0}
[unstore_unit]
[filter]
x,y=$x1,$y1
[/filter]
variable=wesgothic7_trade_stored_unit
find_vacant=no
text= _ "Extract of Healing"
red,green,blue=0,0,255
[/unstore_unit]
[sound]
name=DRINK_POTION.ogg
[/sound]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[effect]
apply_to=hitpoints
increase=45%
[/effect]
[/modify_unit]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[effect]
apply_to=status
remove=wg7injured
[/effect]
[/modify_unit]
[remove_object]
x,y=$x1,$y1
object_id=wesgothic7_v1_injured_obj
[/remove_object]
#enddef
#define WG7_TRADE_ELIXIR_OF_HEALING
{VARIABLE wesgothic7_trade_stored_unit.moves 0}
{VARIABLE wesgothic7_trade_stored_unit.attacks_left 0}
[unstore_unit]
[filter]
x,y=$x1,$y1
[/filter]
variable=wesgothic7_trade_stored_unit
find_vacant=no
text= _ "Elixir of Healing"
red,green,blue=0,0,255
[/unstore_unit]
[sound]
name=DRINK_POTION.ogg
[/sound]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[effect]
apply_to=hitpoints
increase=100%
[/effect]
[/modify_unit]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[effect]
apply_to=status
remove=wg7injured
[/effect]
[/modify_unit]
[remove_object]
x,y=$x1,$y1
object_id=wesgothic7_v1_injured_obj
[/remove_object]
#enddef
#define WG7_TRADE_ELIXIR_OF_LIFE
{VARIABLE wesgothic7_trade_stored_unit.moves 0}
{VARIABLE wesgothic7_trade_stored_unit.attacks_left 0}
[unstore_unit]
[filter]
x,y=$x1,$y1
[/filter]
variable=wesgothic7_trade_stored_unit
find_vacant=no
text= _ "Elixir of Life"
red,green,blue=0,0,255
[/unstore_unit]
[sound]
name=DRINK_POTION.ogg
[/sound]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[effect]
apply_to=hitpoints
increase=100%
[/effect]
[/modify_unit]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[object]
id=wg7_elixir_of_life
duration=forever
take_only_once=no
[effect]
apply_to=hitpoints
increase_total=4
[/effect]
[/object]
[/modify_unit]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[effect]
apply_to=status
remove=wg7injured
[/effect]
[/modify_unit]
[remove_object]
x,y=$x1,$y1
object_id=wesgothic7_v1_injured_obj
[/remove_object]
#enddef
#define WG7_TRADE_ESSENCE_OF_MANA
{VARIABLE wesgothic7_trade_stored_unit.moves 0}
{VARIABLE wesgothic7_trade_stored_unit.attacks_left 0}
[unstore_unit]
[filter]
x,y=$x1,$y1
[/filter]
variable=wesgothic7_trade_stored_unit
find_vacant=no
text= _ "Essence of Mana"
red,green,blue=0,0,255
[/unstore_unit]
[sound]
name=DRINK_POTION.ogg
[/sound]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[object]
id=wg7_essence_of_mana
duration=forever
take_only_once=no
[effect]
apply_to=attack
name=fire_arrow,fireball,holy_ball,destroy_undead,storm,fire_rain,ice_arrow,death_arrow,breath_of_death,beliars_wrath,ice_lance,ice_block,ball_lightning
increase_damage=1
[/effect]
[/object]
[/modify_unit]
#enddef
#define WG7_TRADE_ESSENCE_OF_SPEED
{VARIABLE wesgothic7_trade_stored_unit.moves 0}
{VARIABLE wesgothic7_trade_stored_unit.attacks_left 0}
[unstore_unit]
[filter]
x,y=$x1,$y1
[/filter]
variable=wesgothic7_trade_stored_unit
find_vacant=no
text= _ "Essence of Speed"
red,green,blue=0,0,255
[/unstore_unit]
[sound]
name=DRINK_POTION.ogg
[/sound]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[object]
id=wg7_essence_of_speed
duration=forever
take_only_once=no
[effect]
apply_to=movement
increase=1
[/effect]
[/object]
[/modify_unit]
#enddef
#define WG7_TRADE_ESSENCE_OF_STRENGTH
{VARIABLE wesgothic7_trade_stored_unit.moves 0}
{VARIABLE wesgothic7_trade_stored_unit.attacks_left 0}
[unstore_unit]
[filter]
x,y=$x1,$y1
[/filter]
variable=wesgothic7_trade_stored_unit
find_vacant=no
text= _ "Essence of Strength"
red,green,blue=0,0,255
[/unstore_unit]
[sound]
name=DRINK_POTION.ogg
[/sound]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[object]
id=wg7_essence_of_strength
duration=forever
take_only_once=no
[effect]
apply_to=attack
range=wesgothicseven_melee
increase_damage=1
[/effect]
[/object]
[/modify_unit]
#enddef
#define WG7_TRADE_ESSENCE_OF_DEXTERITY
{VARIABLE wesgothic7_trade_stored_unit.moves 0}
{VARIABLE wesgothic7_trade_stored_unit.attacks_left 0}
[unstore_unit]
[filter]
x,y=$x1,$y1
[/filter]
variable=wesgothic7_trade_stored_unit
find_vacant=no
text= _ "Essence of Dexterity"
red,green,blue=0,0,255
[/unstore_unit]
[sound]
name=DRINK_POTION.ogg
[/sound]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[object]
id=wg7_essence_of_dexterity
duration=forever
take_only_once=no
[effect]
apply_to=attack
name=bow,crossbow,crossbow_fire,crossbow_antiundead
increase_damage=1
[/effect]
[/object]
[/modify_unit]
#enddef
#define WG7_TRADE_THE_BATTLE_OF_VARRANT
{VARIABLE wesgothic7_trade_stored_unit.moves 0}
{VARIABLE wesgothic7_trade_stored_unit.attacks_left 0}
[unstore_unit]
[filter]
x,y=$x1,$y1
[/filter]
variable=wesgothic7_trade_stored_unit
find_vacant=no
text= _ "The Battle of Varrant"
red,green,blue=0,0,255
[/unstore_unit]
[sound]
name=BOOK_TURNPAGE1.ogg
[/sound]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[object]
id=wg7_the_battle_of_varrant
duration=forever
take_only_once=no
[effect]
apply_to=new_ability
[abilities]
{ABILITY_WESGOTHIC7_V1_LEADERSHIP}
[/abilities]
[/effect]
[/object]
[/modify_unit]
#enddef
#define WG7_TRADE_THE_ART_OF_FIGHTING
{VARIABLE wesgothic7_trade_stored_unit.moves 0}
{VARIABLE wesgothic7_trade_stored_unit.attacks_left 0}
[unstore_unit]
[filter]
x,y=$x1,$y1
[/filter]
variable=wesgothic7_trade_stored_unit
find_vacant=no
text= _ "The Art of Fighting"
red,green,blue=0,0,255
[/unstore_unit]
[sound]
name=BOOK_TURNPAGE1.ogg
[/sound]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[effect]
apply_to=experience
increase=10
[/effect]
[/modify_unit]
#enddef
[event]
name=prestart
[set_menu_item]
id=wesgothic7_trade_menu_item
description= _ "Trade"
[show_if]
[have_unit]
x,y=$x1,$y1
side=$side_number
formula="self.moves > 0"
[filter_location]
terrain=*^V*
[/filter_location]
[filter_wml]
[not]
[status]
untalkable=yes
[/status]
[/not]
[/filter_wml]
[/have_unit]
[/show_if]
[command]
[store_unit]
[filter]
x,y=$x1,$y1
[/filter]
variable=wesgothic7_trade_stored_unit
[/store_unit]
[message]
speaker=unit
message= _ "Show me your wares."
[option]
message= _ "Category: Potions"
image="icons/trade/potions/essence_of_healing.png"
[command]
[message]
speaker=narrator
message= _ "Category: Potions"
[option]
message= <span size='large'> _ "Essence of Healing" </span> + " " + <span color='yellow'> _ "4 gold" </span> + "
" + <span color='grey'> _ "Stops bleeding." + " " + _ "+20% HP" </span>
image="icons/trade/potions/essence_of_healing.png"
[command]
[store_gold]
side=$side_number
[/store_gold]
[if]
[variable]
name=gold
greater_than_equal_to=4
[/variable]
[then]
[gold]
side=$side_number
amount=-4
[/gold]
{WG7_TRADE_ESSENCE_OF_HEALING}
[/then]
{WG7_NO_GOLD}
[/if]
[/command]
[/option]
[option]
message= <span size='large'> _ "Extract of Healing" </span> + " " + <span color='yellow'> _ "9 gold" </span> + "
" + <span color='grey'> _ "Stops bleeding." + " " + _ "+45% HP" </span>
image="icons/trade/potions/extract_of_healing.png"
[command]
[store_gold]
side=$side_number
[/store_gold]
[if]
[variable]
name=gold
greater_than_equal_to=9
[/variable]
[then]
[gold]
side=$side_number
amount=-9
[/gold]
{WG7_TRADE_EXTRACT_OF_HEALING}
[/then]
{WG7_NO_GOLD}
[/if]
[/command]
[/option]
[option]
message= <span size='large'> _ "Elixir of Healing" </span> + " " + <span color='yellow'> _ "20 gold" </span> + "
" + <span color='grey'> _ "Stops bleeding." + " " + _ "+100% HP" </span>
image="icons/trade/potions/elixir_of_healing.png"
[command]
[store_gold]
side=$side_number
[/store_gold]
[if]
[variable]
name=gold
greater_than_equal_to=20
[/variable]
[then]
[gold]
side=$side_number
amount=-20
[/gold]
{WG7_TRADE_ELIXIR_OF_HEALING}
[/then]
{WG7_NO_GOLD}
[/if]
[/command]
[/option]
[option]
message= <span size='large'> _ "Elixir of Life" </span> + " " + <span color='yellow'> _ "30 gold" </span> + "
" + <span color='grey'> _ "Stops bleeding." + " " + _ "+100% HP" + ", " + _ "+4 MAX HP" </span>
image="icons/trade/potions/elixir_of_life.png"
[command]
[store_gold]
side=$side_number
[/store_gold]
[if]
[variable]
name=gold
greater_than_equal_to=30
[/variable]
[then]
[gold]
side=$side_number
amount=-30
[/gold]
{WG7_TRADE_ELIXIR_OF_LIFE}
[/then]
{WG7_NO_GOLD}
[/if]
[/command]
[/option]
[option]
message= <span size='large'> _ "Essence of Mana" </span> + " " + <span color='yellow'> _ "12 gold" </span> + "
" + <span color='grey'> _ "+1 magic DMG" </span>
image="icons/trade/potions/essence_of_mana.png"
[command]
[store_gold]
side=$side_number
[/store_gold]
[if]
[variable]
name=gold
greater_than_equal_to=12
[/variable]
[then]
[gold]
side=$side_number
amount=-12
[/gold]
{WG7_TRADE_ESSENCE_OF_MANA}
[/then]
{WG7_NO_GOLD}
[/if]
[/command]
[/option]
[option]
message= <span size='large'> _ "Essence of Speed" </span> + " " + <span color='yellow'> _ "10 gold" </span> + "
" + <span color='grey'> _ "+1 MP" </span>
image="icons/trade/potions/essence_of_speed.png"
[command]
[store_gold]
side=$side_number
[/store_gold]
[if]
[variable]
name=gold
greater_than_equal_to=10
[/variable]
[then]
[gold]
side=$side_number
amount=-10
[/gold]
{WG7_TRADE_ESSENCE_OF_SPEED}
[/then]
{WG7_NO_GOLD}
[/if]
[/command]
[/option]
[option]
message= <span size='large'> _ "Essence of Strength" </span> + " " + <span color='yellow'> _ "8 gold" </span> + "
" + <span color='grey'> _ "+1 melee DMG" </span>
image="icons/trade/potions/essence_of_strength.png"
[command]
[store_gold]
side=$side_number
[/store_gold]
[if]
[variable]
name=gold
greater_than_equal_to=8
[/variable]
[then]
[gold]
side=$side_number
amount=-8
[/gold]
{WG7_TRADE_ESSENCE_OF_STRENGTH}
[/then]
{WG7_NO_GOLD}
[/if]
[/command]
[/option]
[option]
message= <span size='large'> _ "Essence of Dexterity" </span> + " " + <span color='yellow'> _ "8 gold" </span> + "
" + <span color='grey'> _ "+1 ranged DMG" </span>
image="icons/trade/potions/essence_of_dexterity.png"
[command]
[store_gold]
side=$side_number
[/store_gold]
[if]
[variable]
name=gold
greater_than_equal_to=8
[/variable]
[then]
[gold]
side=$side_number
amount=-8
[/gold]
{WG7_TRADE_ESSENCE_OF_DEXTERITY}
[/then]
{WG7_NO_GOLD}
[/if]
[/command]
[/option]
[option]
message= _ "Cancel"
[/option]
[/message]
[/command]
[/option]
[option]
message= _ "Category: Books"
image="icons/trade/books/the_battle_of_varrant.png"
[command]
[message]
speaker=narrator
message= _ "Category: Books"
[option]
message= <span size='large'> _ "The Battle of Varrant" </span> + " " + <span color='yellow'> _ "20 gold" </span> + "
" + <span color='grey'> _ "Leadership" </span>
image="icons/trade/books/the_battle_of_varrant.png"
[command]
[store_gold]
side=$side_number
[/store_gold]
[if]
[variable]
name=gold
greater_than_equal_to=20
[/variable]
[then]
[gold]
side=$side_number
amount=-20
[/gold]
{WG7_TRADE_THE_BATTLE_OF_VARRANT}
[/then]
{WG7_NO_GOLD}
[/if]
[/command]
[/option]
[option]
message= <span size='large'> _ "The Art of Fighting" </span> + " " + <span color='yellow'> _ "10 gold" </span> + "
" + <span color='grey'> _ "+10 XP" </span>
image="icons/trade/books/the_art_of_fighting.png"
[command]
[store_gold]
side=$side_number
[/store_gold]
[if]
[variable]
name=gold
greater_than_equal_to=10
[/variable]
[then]
[gold]
side=$side_number
amount=-10
[/gold]
{WG7_TRADE_THE_ART_OF_FIGHTING}
[/then]
{WG7_NO_GOLD}
[/if]
[/command]
[/option]
[option]
message= _ "Cancel"
[/option]
[/message]
[/command]
[/option]
[option]
message= _ "Cancel"
[/option]
[/message]
[/command]
[/set_menu_item]
[/event]
[/modification]
Re: modify_unit and healing
This is long enough example that I would not investigate further without some information for example line number of the tag which does not do what you expect.
Re: modify_unit and healing
This:
And more precisely this:
For some reason it is not always healing. I have no idea why.
I'm using Wesnoth 1.16.11
Code: Select all
#define WG7_TRADE_ESSENCE_OF_HEALING
{VARIABLE wesgothic7_trade_stored_unit.moves 0}
{VARIABLE wesgothic7_trade_stored_unit.attacks_left 0}
[unstore_unit]
[filter]
x,y=$x1,$y1
[/filter]
variable=wesgothic7_trade_stored_unit
find_vacant=no
text= _ "Essence of Healing"
red,green,blue=0,0,255
[/unstore_unit]
[sound]
name=DRINK_POTION.ogg
[/sound]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[effect]
apply_to=hitpoints
increase=20%
[/effect]
[/modify_unit]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[effect]
apply_to=status
remove=wg7injured
[/effect]
[/modify_unit]
[remove_object]
x,y=$x1,$y1
object_id=wesgothic7_v1_injured_obj
[/remove_object]
#enddef
Code: Select all
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[effect]
apply_to=hitpoints
increase=20%
[/effect]
[/modify_unit]
I'm using Wesnoth 1.16.11
Re: modify_unit and healing
Try
Code: Select all
[remove_object]
x,y=$x1,$y1
object_id=wesgothic7_v1_injured_obj
[/remove_object]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[effect]
apply_to=status
remove=wg7injured
[/effect]
[effect]
apply_to=hitpoints
increase=20%
[/effect]
[/modify_unit]
Re: modify_unit and healing
Now it works - and I'm not sure that it sometimes not worked. Maybe I have not noticed it working, because it sometimes heals by very small amount. Thanks. Does 20% mean 20% of the current HP or 20% of total/maximum HP?
Re: modify_unit and healing
[remove_object] works by unit rebuild. If there was no object to remove I expect rebuild was also skipped.
- lhybrideur
- Posts: 379
- Joined: July 9th, 2019, 1:46 pm
Re: modify_unit and healing
It is 20% of the current HP, which is a design error I would say.
Try replacing it with something like
Try replacing it with something like
increase="(0.2*max_hitpoints)"
Re: modify_unit and healing
I did:
Thanks.
Code: Select all
[set_variable]
name=trade_heal
formula="0.20 * $wesgothic7_trade_stored_unit.max_hitpoints"
[/set_variable]
[set_variable]
name=trade_heal
round=floor
[/set_variable]
[modify_unit]
[filter]
x,y=$x1,$y1
[/filter]
[effect]
apply_to=hitpoints
increase=$trade_heal
[/effect]
[/modify_unit]
Re: modify_unit and healing
formula="floor(0.20 * $wesgothic7_trade_stored_unit.max_hitpoints)" would skip one step.
Re: modify_unit and healing
I changed it. Thanks.