formula help for a weapon special needed
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.
formula help for a weapon special needed
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
- Lord-Knightmare
- Discord Moderator
- Posts: 2364
- 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
Yes, and yes.
Take an
I didn't test the aforementioned code but it should be working.
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]
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Re: formula help for a weapon special needed
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
Re: formula help for a weapon special needed
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
Here is an example that creates an Elvish archer at 10,15 and add the self-harm special to his bow.
[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.
- Lord-Knightmare
- Discord Moderator
- Posts: 2364
- 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
@Adamant14: without the utilisation of events? I am not sure but maybe:
The code hasn't been tested so I am not certain if this will work or not.
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]
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Re: formula help for a weapon special needed
@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.
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
Re: formula help for a weapon special needed
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 ?
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.
Re: formula help for a weapon special needed
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.
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
- Lord-Knightmare
- Discord Moderator
- Posts: 2364
- 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
For the second part, I would recommend using an event...but we can just heal the defender for whatever theThe 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.
$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
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Re: formula help for a weapon special needed
Good idea, but for some reason it wont work.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
Part 1 alone, without part 2 seems to work, but part 1+2 not?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)
Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR
Re: formula help for a weapon special needed
I think the issue is that damage_inflicted is a WML variable, not a WFL one.
When you wrote
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).
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).
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: 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
Old UMC works: 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
Re: formula help for a weapon special needed
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. 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
-
- Code Contributor
- Posts: 172
- Joined: October 6th, 2017, 12:57 pm
Re: formula help for a weapon special needed
why not use
instead, value=100 is 100% of damage inflicted drained, and -100 100% damage inflicted reflected.
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]
-
- Code Contributor
- Posts: 172
- Joined: October 6th, 2017, 12:57 pm
Re: formula help for a weapon special needed
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?
Re: formula help for a weapon special needed
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:19 pm why not useinstead, value=100 is 100% of damage inflicted drained, and -100 100% damage inflicted reflected.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]
I am not a native English speaker, so I am not sure if I understand you correctly.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?
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