Steadfast-like ability - but for defense
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.
Steadfast-like ability - but for defense
Steadfast uses the [resistance] tag along with a built-in option: active_on. However, the [defense] tag does not have this optional parameter, therefore it is not possible to make an ability which boosts defense rate while being attacked.
So I tried to adapt the FORCE_CHANCE_TO_HIT mainline macro to have that effect. Problem is, when the unit type with the ability attacks, it also suffers the defined hit% penalty.
Let's say Thief will have this new "dodge" ability; when thieves are attacked, opponents have a -20 penalty to hit them. When thieves attack, however, opponents have regular chance to hit.
The code, adapted from FCTH macro:
Now, when something attacks a Thief unit, the bonus kick in, that works fine. However, when a Thief unit attacks, it also suffers the 20 penalty hit. That can be easier verified by adding the tag below on any of the Thief attacks, then using this attack on a Wose standing on flat terrain:
The combination makes the attack a 100% hit rate - but the thief will miss some of them against the wose. The event converts the hit to 60%, so it's easy to verify.
I believe the [filter_second] tag doesn't work as I always thought it would (filtering the second actor - in an "attack" event, that would be the guy defending); instead, if any unit (attacker of defender) is a Thief type, the event triggers for the attacker.
So, any ideas how to filter the event the right way?
BTW, I'm using wesnoth 1.12; not sure if the behavior occurs on 1.13
So I tried to adapt the FORCE_CHANCE_TO_HIT mainline macro to have that effect. Problem is, when the unit type with the ability attacks, it also suffers the defined hit% penalty.
Let's say Thief will have this new "dodge" ability; when thieves are attacked, opponents have a -20 penalty to hit them. When thieves attack, however, opponents have regular chance to hit.
The code, adapted from FCTH macro:
Code: Select all
[event]
name=attack
first_time_only=no
[filter_second]
[variable]
name=second_unit.type
equals=Thief
[/variable]
[/filter_second]
[if]
[then]
{FOREACH unit.attack i}
[if]
#This is to mute a warning message about retrieving a member of non-existant wml container.
[variable]
name=unit.attack[$i].specials.length
greater_than=0
[/variable]
[variable]
name=unit.attack[$i].specials.chance_to_hit.length
greater_than=0
[/variable]
[then]
[set_variables]
name=unit.attack[$i].specials.original_chance_to_hit
to_variable=unit.attack[$i].specials.chance_to_hit
[/set_variables]
{CLEAR_VARIABLE unit.attack[$i].specials.chance_to_hit}
[/then]
[/if]
[set_variables]
name=unit.attack[$i].specials.chance_to_hit
[value]
id=forced_cth
sub=20
cumulative=yes
[/value]
[/set_variables]
{NEXT i}
[unstore_unit]
variable=unit
find_vacant=no
[/unstore_unit]
[event]
name=attack end
delayed_variable_substitution=yes
{FOREACH unit.attack i}
{CLEAR_VARIABLE unit.attack[$i].specials.chance_to_hit}
[set_variables]
name=unit.attack[$i].specials.chance_to_hit
to_variable=unit.attack[$i].specials.original_chance_to_hit
[/set_variables]
{CLEAR_VARIABLE unit.attack[$i].specials.original_chance_to_hit}
{NEXT i}
[unstore_unit]
variable=unit
find_vacant=no
[/unstore_unit]
[/event]
[/then]
[/if]
[/event]
Code: Select all
[specials]
[chance_to_hit]
add=20
cumulative=yes
[/chance_to_hit]
[/specials]
I believe the [filter_second] tag doesn't work as I always thought it would (filtering the second actor - in an "attack" event, that would be the guy defending); instead, if any unit (attacker of defender) is a Thief type, the event triggers for the attacker.
So, any ideas how to filter the event the right way?
BTW, I'm using wesnoth 1.12; not sure if the behavior occurs on 1.13
- skeptical_troll
- Posts: 500
- Joined: August 31st, 2015, 11:06 pm
Re: Steadfast-like ability - but for defense
[filter_second] is a unit filter, you are using it as a [filter_condition]
Either change the first to the latter, or use just
There's also an [if] block without condition, not sure what is for.
Either change the first to the latter, or use just
type=Thief
instead of that [variable] block.There's also an [if] block without condition, not sure what is for.
Re: Steadfast-like ability - but for defense
Oh. It was simpler than I thought. Thanks, pal.
Forgot to remove the if block without conditions - on FCTH macro is used with the last argument. I removed the argument, but forgot the block.
Forgot to remove the if block without conditions - on FCTH macro is used with the last argument. I removed the argument, but forgot the block.
- Celtic_Minstrel
- Developer
- Posts: 2222
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Steadfast-like ability - but for defense
The
By the way, there's also a
active_on
key should work in any ability as far as I know. However I don't think [defense]
is a known ability, so that would be why it's not working for you.By the way, there's also a
parry
key in [attack]
which does basically what you want. It even works in 1.12 (and probably earlier too).