formula help for a weapon special needed

The place to post your WML questions and answers.

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.
User avatar
Adamant14
Posts: 934
Joined: April 24th, 2010, 1:14 pm

formula help for a weapon special needed

Post by Adamant14 »

In my campaign, I would need a weapon special that, like a reflection, completely throws the damage caused by the attacker back to the attacker self.
[heal_on_hit] with a negative value works fine, but It would be cool, and really like a reflection, if the attacker gets harmed by exact the damage he deals. But I have no idea how to get that damage. Is that possible using a formula?

Code: Select all

    [heal_on_hit]
        id=TEST_reflect
        name= _ "reflect"
        description= _ "When this attack hits it harms the caster."
        apply_to=attacker
        value=-(how can I get the damage the attacker does to add it here as the right value?)
    [/heal_on_hit]
Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR
User avatar
Lord-Knightmare
Discord Moderator
Posts: 1308
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: formula help for a weapon special needed

Post by Lord-Knightmare »

Yes, and yes.
Take an attacker_hits event. Store the $damage_inflicted in a variable. Use [harm_unit][/harm_unit] on the attacker (x,y=$x1,$y1).

Code: Select all

    [event]
        name=attacker hits
        first_time_only=no
        [filter]
            special_id=reflect_special
        [/filter]

        {VARIABLE reflected_dmg $damage_inflicted}
        [harm_unit]
            [filter]
                x,y=$x1,$y1
            [/filter]
            fire_event=yes
            animate=yes
            amount=$reflected_dmg
            # damage_type=cold
        [/harm_unit]
    [/event]
I didn't test the aforementioned code but it should be working.
User avatar
Adamant14
Posts: 934
Joined: April 24th, 2010, 1:14 pm

Re: formula help for a weapon special needed

Post by Adamant14 »

Thank you for your solution Lord-Knightmare. I am sure that it can be done with events, I was just wondering whether there is a way to do it without using any events?
Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR
Zatiranyk
Posts: 13
Joined: May 4th, 2018, 8:00 pm

Re: formula help for a weapon special needed

Post by Zatiranyk »

I don’t think there is a solution without events. If you want to cancel the initial damages that harms the defender, you should keep the initial damage in the [variables] of the unit and set the damage to 0. Finally, use it in the [harm_unit] tag.

Here is an example that creates an Elvish archer at 10,15 and add the self-harm special to his bow.

Code: Select all

[event]
    name= "start"
    
    [unit]
        type= "Elvish Archer"
        x = 10
        y = 15
        [modifications]
            [object]
                [effect]
                    apply_to= attack
                    name= bow
                    set_damage=0
                    [set_specials]
                        [self_harm]
                            id= self_harm
                            name= "Self-harm"
                            description= "The unit will harm himself !"
                        [/self_harm]
                    [/set_specials]
                [/effect]
            [/object]
        [/modifications]
        
        [variables]
            bow_damage = 5
        [/variables]
        
    [/unit]
[/event]

[event]
    name= "attacker hits"
    first_time_only= no
    
    [filter]
        [has_attack]
            special_id= self_harm
        [/has_attack]
    [/filter]
    
    [harm_unit]
        [filter]
            id= $unit.id
        [/filter]
        amount= $unit.variables.bow_damage
    [/harm_unit]
    
[/event]
Last edited by Zatiranyk on January 9th, 2021, 6:30 pm, edited 1 time in total.
User avatar
Lord-Knightmare
Discord Moderator
Posts: 1308
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: formula help for a weapon special needed

Post by Lord-Knightmare »

@Adamant14: without the utilisation of events? I am not sure but maybe:

Code: Select all

    [heal_on_hit]
        id=TEST_reflect
        name= _ "reflect"
        description= _ "When this attack hits it harms the caster."
        apply_to=attacker
        value=-($damage_inflicted)
    [/heal_on_hit]
The code hasn't been tested so I am not certain if this will work or not.
User avatar
Adamant14
Posts: 934
Joined: April 24th, 2010, 1:14 pm

Re: formula help for a weapon special needed

Post by Adamant14 »

@Zatiranyk :
Thank you for your solution, but Lord-Knightmare's second solution comes closer to what I have in mind.

@Lord-Knightmare:
It seems to work. I would not have thought that the variable $damage_inflicted would be recognized here.

Part on seems to work, the second part remains.

The attacker gets his own damage, but also the defender. With a correct reflection, only the attacker should be harmed and the defender should remain unharmed.
Last edited by Adamant14 on January 9th, 2021, 8:21 pm, edited 1 time in total.
Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR
Zatiranyk
Posts: 13
Joined: May 4th, 2018, 8:00 pm

Re: formula help for a weapon special needed

Post by Zatiranyk »

But can you explain shortly why do you want a weapon’s special for this ? If you really want a "reflection effect", for me, it’s not in the special weapon of the attacker. It would be better to define an new ability "reflection" for this, don’t you think ?
Adamant14 wrote: January 9th, 2021, 7:01 pm The attacker gets his own damage, but also the defender. With a correct reflection, only the attacker should be harmed and the defender should remain unharmed.
As I said, a possible solution would be to set damage to 0 but it will result in the attack’s description displaying "0" and it’s kind of ugly.
User avatar
Adamant14
Posts: 934
Joined: April 24th, 2010, 1:14 pm

Re: formula help for a weapon special needed

Post by Adamant14 »

Zatiranyk wrote: January 9th, 2021, 7:07 pm But can you explain shortly why do you want a weapon’s special for this ? If you really want a "reflection effect", for me, it’s not in the special weapon of the attacker.
Of course not, it is a special for the defender, a boss who can only be defeated under certain circumstances, but otherwise he is invincible.
Zatiranyk wrote: January 9th, 2021, 7:07 pm As I said, a possible solution would be to set damage to 0 but it will result in the attack’s description displaying "0" and it’s kind of ugly.
A displayed "0" is indeed ugly, and I hope to find a better way.
Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR
User avatar
Lord-Knightmare
Discord Moderator
Posts: 1308
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: formula help for a weapon special needed

Post by Lord-Knightmare »

The attacker gets his own damage, but also the defender. With a correct reflection, only the attacker should be harmed and the defender should remain unharmed.
For the second part, I would recommend using an event...but we can just heal the defender for whatever the $damage_inflicted was.

Code: Select all


#define WEAPON_SPECIAL_REFLECT
    [heal_on_hit]
        id=TEST_reflect_part1
        name= _ "reflect"
        description= _ "When this attack hits it harms the caster."
        apply_to=attacker
        value=-($damage_inflicted)
    [/heal_on_hit]
    [heal_on_hit]
        id=TEST_reflect_part2
       # no name and description as we want this to stay invisible to players
        apply_to=defender
        value=($damage_inflicted)
    [/heal_on_hit]
#enddef

User avatar
Adamant14
Posts: 934
Joined: April 24th, 2010, 1:14 pm

Re: formula help for a weapon special needed

Post by Adamant14 »

Lord-Knightmare wrote: January 9th, 2021, 7:27 pm For the second part, I would recommend using an event...but we can just heal the defender for whatever the $damage_inflicted was.

Code: Select all


#define WEAPON_SPECIAL_REFLECT
    [heal_on_hit]
        id=TEST_reflect_part1
        name= _ "reflect"
        description= _ "When this attack hits it harms the caster."
        apply_to=attacker
        value=-($damage_inflicted)
    [/heal_on_hit]
    [heal_on_hit]
        id=TEST_reflect_part2
       # no name and description as we want this to stay invisible to players
        apply_to=defender
        value=($damage_inflicted)
    [/heal_on_hit]
#enddef

Good idea, but for some reason it wont work.
log wrote: Invalid WML found: Formula error in ability or weapon special: Unrecognized token at formula:1) (3)
Invalid WML found: Formula error in ability or weapon special: Unrecognized token at formula:1) (2)
Invalid WML found: Formula error in ability or weapon special: Unrecognized token at formula:1) (2)
Invalid WML found: Formula error in ability or weapon special: Unrecognized token at formula:1) (2)
Invalid WML found: Formula error in ability or weapon special: Unrecognized token at formula:1) (2)
Invalid WML found: Formula error in ability or weapon special: Unrecognized token at formula:1) (2)
Invalid WML found: Formula error in ability or weapon special: Unrecognized token at formula:1) (2)
Invalid WML found: Formula error in ability or weapon special: Unrecognized token at formula:1) (2)
Invalid WML found: Formula error in ability or weapon special: Unrecognized token at formula:1) (2)
Part 1 alone, without part 2 seems to work, but part 1+2 not?
Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR
User avatar
WhiteWolf
Forum Moderator
Posts: 739
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: formula help for a weapon special needed

Post by WhiteWolf »

I think the issue is that damage_inflicted is a WML variable, not a WFL one.
When you wrote value=-($damage_inflicted), because the minus was before the parentheses, I don't think it's evaluated as a formula anymore, that's why it worked - it just substituted the wml variable.
I think you don't need formulas here - just get rid of the parentheses in both cases and it should work. (I could be wrong).
Author of the Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now for 1.14, with new bugs!
User avatar
Adamant14
Posts: 934
Joined: April 24th, 2010, 1:14 pm

Re: formula help for a weapon special needed

Post by Adamant14 »

WhiteWolf wrote: January 9th, 2021, 7:45 pm ... just get rid of the parentheses in both cases and it should work. (I could be wrong).
After removing the parentheses the error messages are gone. But sadly the second part [heal_on_hit] wont work as hoped.
Even the first part [heal_on_hit] only works if the attacker just has only one strike. If the attacker has two or more strikes, then $ damage_inflicted is only subtracted with the first hit. :augh: Each following hit remains uncounted.
It probably only works with events.
Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR
newfrenchy83
Code Contributor
Posts: 95
Joined: October 6th, 2017, 12:57 pm

Re: formula help for a weapon special needed

Post by newfrenchy83 »

why not use

Code: Select all

   [drains]
        id=TEST_reflect
        name= _ "reflect"
        description= _ "When this attack hits it harms the caster."
        value=-100
        apply_to=attacker
    [/drains]
       [drains]
        id=TEST_reflect2
        value=-100
        apply_to=defender
    [/drains]
    
instead, value=100 is 100% of damage inflicted drained, and -100 100% damage inflicted reflected.
newfrenchy83
Code Contributor
Posts: 95
Joined: October 6th, 2017, 12:57 pm

Re: formula help for a weapon special needed

Post by newfrenchy83 »

if you use apply_to=attacker and apply_to=defender, then attacker AND defender will see the damage inflicted to their opponent reflected, if attacker is owner of special then, he AND him opponent will be affected by weapon specials effect, but will be same if opponent to owner is attacker. Is the effect expected or not?
User avatar
Adamant14
Posts: 934
Joined: April 24th, 2010, 1:14 pm

Re: formula help for a weapon special needed

Post by Adamant14 »

newfrenchy83 wrote: January 11th, 2021, 4:19 pm why not use

Code: Select all

   [drains]
        id=TEST_reflect
        name= _ "reflect"
        description= _ "When this attack hits it harms the caster."
        value=-100
        apply_to=attacker
    [/drains]
       [drains]
        id=TEST_reflect2
        value=-100
        apply_to=defender
    [/drains]
    
instead, value=100 is 100% of damage inflicted drained, and -100 100% damage inflicted reflected.
That sounds perfectly logical, but it doesn't work for me. I've tried all sorts of constellations, but it just doesn't work. Either both take damage, the attacker and the defender, or only the defender takes damage. But no constellation does what I want it to do.

newfrenchy83 wrote: January 11th, 2021, 4:35 pm if you use apply_to=attacker and apply_to=defender, then attacker AND defender will see the damage inflicted to their opponent reflected, if attacker is owner of special then, he AND him opponent will be affected by weapon specials effect, but will be same if opponent to owner is attacker. Is the effect expected or not?
I am not a native English speaker, so I am not sure if I understand you correctly.
How the special should work:
The defender owns the special.
The attacker attacks the defender.
The defender reflects the attack.
The defender has no damage at all, instead the attacker alone has all the damage.
Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR
Post Reply