Killing weapon special doesn't work
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.
Killing weapon special doesn't work
I wanted to make a weapon special in wesnoth called assasination wich, when in backstab, kills the ennemie unit if it is of level 0 or 1. I am a real beginner in wml but after some research I made this code
The problem is that the defender AND the attacker die and I don't know how to fix it . I think the problem is in the filter in the store_unit but I can't find any solution. I am also not sure if xp is given when it works so if you can tell me how to do that to
Thanks already.
Code: Select all
#define WEAPON_SPECIAL_ASSASINATION
# Canned definition of the assasination ability to be included in a
# [specials] clause.
[damage]
id=assasination
name= _ "assasination"
description= _ "When used offensively, this attack kills the enemy unit if it is of level 0 or 1 and if there is an enemy of the target on the opposite side of the target, and that unit is not incapacitated (turned to stone or otherwise paralyzed)."
backstab=yes
apply_to=opponent
[/damage]
[/specials]
defence_weight=0
[/attack]
[event]
name=attacker_hits
first_time_only=no
[filter_attack]
special=assasination
[/filter_attack]
[store_unit]
[filter]
level=0,1
[filter_defender]
[/filter_defender]
[/filter]
kill=yes
variable=unit
[/store_unit]
[unstore_unit]
variable=unit
find_vacant=no
text="assasination"
{COLOR_HARM}
[/unstore_unit]
{CLEAR_VARIABLE unit}
[/event]
[+attack]
[+specials]
#enddef
The problem is that the defender AND the attacker die and I don't know how to fix it . I think the problem is in the filter in the store_unit but I can't find any solution. I am also not sure if xp is given when it works so if you can tell me how to do that to
Thanks already.
Re: Killing weapon special doesn't work
[filter_defender] is not used in standard unit filter. Empty [filter_defender] [/filter_defender] would not do anything. No xp is given, since nothing is killed. You store all level 1-0 units, and then unstore attacker
You can compare to https://github.com/ProditorMagnus/Agele ... strike.cfg
Consider giving this attack +99 or so damage inside [damage], then it would be more predictable from damage calculation.
You can compare to https://github.com/ProditorMagnus/Agele ... strike.cfg
Consider giving this attack +99 or so damage inside [damage], then it would be more predictable from damage calculation.
Re: Killing weapon special doesn't work
Thanks a lot now it works perfectly!!!
It didn't give xp after the kill but I made a little code. It only works with level 0 and 1 though . Here is the final code:
It didn't give xp after the kill but I made a little code. It only works with level 0 and 1 though . Here is the final code:
Code: Select all
#define WEAPON_SPECIAL_ASSASINATION
# Canned definition of the assasination ability to be included in a
# [specials] clause.
[damage]
id=assasination
name= _ "assasination"
description= _ "When used offensively, this attack kills the enemy unit if it is of level 0 or 1 and if there is an enemy of the target on the opposite side of the target, and that unit is not incapacitated (turned to stone or otherwise paralyzed)."
backstab=yes
apply_to=opponent
[/damage]
[/specials]
defence_weight=0
[/attack]
[event]
name=attacker_hits
first_time_only=no
[filter_attack]
special=assasination
[/filter_attack]
[if]
[have_unit]
x,y=$x2,$y2
level=0,1
[not]
side=$side_number
[/not]
[/have_unit]
[then]
[unstore_unit]
variable=second_unit
find_vacant=no
text="assasination"
{COLOR_HARM}
[/unstore_unit]
[if]
[variable]
name=second_unit.level
value=0
[/variable]
[then]
[set_variable]
name=unit.experience
value=4
[/set_variable]
[/then]
[/if]
[if]
[variable]
name=second_unit.level
value=1
[/variable]
[then]
[set_variable]
name=unit.experience
value=7
[/set_variable]
[/then]
[/if]
[unstore_unit]
variable=unit
[/unstore_unit]
[kill]
x,y=$x2,$y2
animate=yes
[/kill]
[/then]
[/if]
[/event]
[+attack]
[+specials]
#enddef
Re: Killing weapon special doesn't work
You might want to use add= for adding xp, and equals= for checking level.
Re: Killing weapon special doesn't work
Done! The level=0,1 also didn't work so I put an [or]...
Last edited by Beer on March 22nd, 2019, 7:46 am, edited 1 time in total.
Re: Killing weapon special doesn't work
Here is the final code
Code: Select all
#define WEAPON_SPECIAL_ASSASINATION
# Canned definition of the assasination ability to be included in a
# [specials] clause.
[damage]
id=assasination
name= _ "assasination"
description= _ "When used offensively, this attack kills the enemy unit if it is of level 0 or 1 and if there is an enemy of the target on the opposite side of the target, and that unit is not incapacitated (turned to stone or otherwise paralyzed)."
backstab=yes
apply_to=opponent
[/damage]
[/specials]
defence_weight=0
[/attack]
[event]
name=attacker_hits
first_time_only=no
[filter_attack]
special=assasination
[/filter_attack]
[if]
[have_unit]
x,y=$x2,$y2
level=0
[not]
side=$side_number
[/not]
[/have_unit]
[or]
[have_unit]
x,y=$x2,$y2
level=1
[not]
side=$side_number
[/not]
[/have_unit]
[/or]
[then]
[unstore_unit]
variable=second_unit
find_vacant=no
text="assasination"
{COLOR_HARM}
[/unstore_unit]
[if]
[variable]
name=second_unit.level
equals=0
[/variable]
[then]
[set_variable]
name=unit.experience
add=4
[/set_variable]
[/then]
[/if]
[if]
[variable]
name=second_unit.level
equals=1
[/variable]
[then]
[set_variable]
name=unit.experience
add=7
[/set_variable]
[/then]
[/if]
[unstore_unit]
variable=unit
[/unstore_unit]
[kill]
x,y=$x2,$y2
animate=yes
[/kill]
[/then]
[/if]
[/event]
[+attack]
[+specials]
#enddef
[code]
Last edited by Beer on March 22nd, 2019, 4:46 pm, edited 1 time in total.
Re: Killing weapon special doesn't work
Are you sure this part does what you want it to? If I'm not mistaken, the [not] block only applies to level 0 units but not to level 1 units.Beer wrote: ↑March 22nd, 2019, 7:44 amCode: Select all
[have_unit] x,y=$x2,$y2 level=0 [or] level=1 [/or] [not] side=$side_number [/not] [/have_unit]
- Celtic_Minstrel
- Developer
- Posts: 2207
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Killing weapon special doesn't work
It would be better to use numerical_equals= for level (assuming we're talking about the
[variable]
tag, I only skimmed the rest of the thread).It likely doesn't do what he intends; I'm not sure exactly how the game handles the mix of "or" and "and" (a "not" is really "and not") in that example. I doubt it uses standard precedence rules. Anyway... my guess would be that it translates to the following boolean expression:josteph wrote: ↑March 22nd, 2019, 11:54 amAre you sure this part does what you want it to? If I'm not mistaken, the [not] block only applies to level 0 units but not to level 1 units.Beer wrote: ↑March 22nd, 2019, 7:44 amCode: Select all
[have_unit] x,y=$x2,$y2 level=0 [or] level=1 [/or] [not] side=$side_number [/not] [/have_unit]
((x,y=$x2,$y2 and level=0) or (level=1)) and not (side=$side_number)
Note in particular that it will thus match level 1 units anywhere on the map, but level 0 units only on that one location.
Re: Killing weapon special doesn't work
Yeah I saw the level thing didn't work very well so I just put a second [have_unit].(I didn't see your messages at first so I changed it directly in my post