Leadership value based on resistance?
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.
Leadership value based on resistance?
I tried to make an ability that inhibits opponents' attacks based on how succeptible they are to arcane damage.
I tried both
and
and neither of them does anything. I tested the rest of the ability by putting a constant instead (-35) and that worked, so I am pretty sure it is because of the value formula, but I can't determine what is wrong.
I tried both
Code: Select all
value=-$other.resistance.arcane
Code: Select all
value=-other.resistance.arcane
- Celtic_Minstrel
- Developer
- Posts: 2207
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Leadership value based on resistance?
You're mixing up Wesnoth Formula Language and variable substitution. You don't need to use
Your second formula doesn't work because
Additionally,
What that actually does is return the resistance the unit should have to arcane when attacking from its current location. If you change the 1 to a 0, it yields the resistance it would have if defending from an enemy attack. This calculation takes into effect all abilities, including buffs from adjacent units (similar to leadership). The value is as shown in the UI, not the multiplier stored in the raw data.
$
when it's a formula. So, that's why your first example doesn't work.Your second formula doesn't work because
resistance
isn't what you appear to think it is. It doesn't contain resistance values like what's shown in the UI. It contains a percentage that all damage of that type is multiplied by. So, for example, if the secondary unit has 20% arcane resistance, then other.resistance.arcane
evaluates to 80 – all arcane damage is multiplied by 80% (0.. Or if the secondary unit has 10% arcane vulnerability, then other.resistance.arcane
evaluates to 110 – all arcane damage is multiplied by 110% (1.1). So if you want the resistance value as shown in the UI, you need to subtract from 100: 100 - other.resistance.arcane
.Additionally,
other.resistance.arcane
is not the unit's actual resistance. It's the base resistance, which can then be modified by abilities (for example, the dwarven steadfast ability). If you want to use the real resistance value, then you need to use a function call:Code: Select all
value="resistance_on(other, other.loc, 'arcane', 1)"
- beetlenaut
- Developer
- Posts: 2825
- Joined: December 8th, 2007, 3:21 am
- Location: Washington State
- Contact:
Re: Leadership value based on resistance?
Never mind. Celtic_Minstrel's answer is more complete.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
Re: Leadership value based on resistance?
Code: Select all
value="resistance_on(other, other.loc, 'arcane', 1)"
I know what [resistance] tag does and I do want it to work how I wrote it. That is, a unit with 100% resistance (arcane=0) would not be affected, while a unit with 0 (arcane=100) or lower resistance would deal 0 damage. I even wrote that it is supposed to be based on succeptible they are.Celtic_Minstrel wrote: ↑March 15th, 2023, 6:01 pm Your second formula doesn't work becauseresistance
isn't what you appear to think it is. It doesn't contain resistance values like what's shown in the UI. It contains a percentage that all damage of that type is multiplied by. So, for example, if the secondary unit has 20% arcane resistance, thenother.resistance.arcane
evaluates to 80 – all arcane damage is multiplied by 80% (0.. Or if the secondary unit has 10% arcane vulnerability, thenother.resistance.arcane
evaluates to 110 – all arcane damage is multiplied by 110% (1.1). So if you want the resistance value as shown in the UI, you need to subtract from 100:100 - other.resistance.arcane
.
I do think it should be affected by such effects as steadfast, which indeed the way I wrote would not do.Celtic_Minstrel wrote: ↑March 15th, 2023, 6:01 pm Additionally,other.resistance.arcane
is not the unit's actual resistance. It's the base resistance, which can then be modified by abilities (for example, the dwarven steadfast ability). If you want to use the real resistance value, then you need to use a function call:
- Celtic_Minstrel
- Developer
- Posts: 2207
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Leadership value based on resistance?
I think the issue here is that I forgot an extra set of parentheses is needed to signal to the engine that it should be interpreted as a formula instead of a number. Try this:Mathel wrote: ↑March 15th, 2023, 7:52 pmalso does nothing. I just tested that.Code: Select all
value="resistance_on(other, other.loc, 'arcane', 1)"
Code: Select all
value="(100 - resistance_on(other, other.loc, 'arcane', 1))"
Re: Leadership value based on resistance?
Why are you using
value="formula"
instead of value="$(formula)"
? value=
supports formula directly on abilities?Re: Leadership value based on resistance?
A formula can be used if it's in parentheses (see the previous comment).
From the wiki:
https://wiki.wesnoth.org/AbilitiesWML#Common_keys_and_tags_for_every_ability wrote:All keys inside any ability that expects a numeric value will also accept formulas using Wesnoth Formula Language. In order to use a formula in these keys, you must enclose it in parentheses. However, do not precede those parentheses with a dollar sign like $(...), since that will erase the self variable.
Re: Leadership value based on resistance?
As it turns out, paretheses were the problem with my writing as well, though I will use your format, since it takes current circumstances into account.Celtic_Minstrel wrote: ↑March 16th, 2023, 12:15 amI think the issue here is that I forgot an extra set of parentheses is needed to signal to the engine that it should be interpreted as a formula instead of a number. Try this:Mathel wrote: ↑March 15th, 2023, 7:52 pmalso does nothing. I just tested that.Code: Select all
value="resistance_on(other, other.loc, 'arcane', 1)"
That also transforms the resistance value back to the format used in the tag, like you wanted, by subtracting it from 100.Code: Select all
value="(100 - resistance_on(other, other.loc, 'arcane', 1))"
Also, as it turns out,
Code: Select all
-other.resistance.arcane
Anyway, once I got it to do something, getting it to do the correct thing was pretty easy. The final formula is
Code: Select all
value="(- 100 + resistance_on(other, other.loc, 'arcane', 0))"
So, thank you for your help.