Killing weapon special doesn't work

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.
Post Reply
Beer
Posts: 5
Joined: March 21st, 2019, 6:00 pm

Killing weapon special doesn't work

Post by Beer »

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

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 :D
Thanks already.
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Killing weapon special doesn't work

Post by Ravana »

[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.
Beer
Posts: 5
Joined: March 21st, 2019, 6:00 pm

Re: Killing weapon special doesn't work

Post by Beer »

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:

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
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Killing weapon special doesn't work

Post by Ravana »

You might want to use add= for adding xp, and equals= for checking level.
Beer
Posts: 5
Joined: March 21st, 2019, 6:00 pm

Re: Killing weapon special doesn't work

Post by Beer »

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.
Beer
Posts: 5
Joined: March 21st, 2019, 6:00 pm

Re: Killing weapon special doesn't work

Post by Beer »

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.
User avatar
josteph
Inactive Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: Killing weapon special doesn't work

Post by josteph »

Beer wrote: March 22nd, 2019, 7:44 am

Code: Select all

                [have_unit]
                    x,y=$x2,$y2
                    level=0
                    [or]
                          level=1
                    [/or]
                    [not]
                        side=$side_number
                    [/not]
                [/have_unit]
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.
User avatar
Celtic_Minstrel
Developer
Posts: 2207
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Killing weapon special doesn't work

Post by Celtic_Minstrel »

Ravana wrote: March 21st, 2019, 9:46 pm You might want to use add= for adding xp, and equals= for checking level.
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).
josteph wrote: March 22nd, 2019, 11:54 am
Beer wrote: March 22nd, 2019, 7:44 am

Code: Select all

                [have_unit]
                    x,y=$x2,$y2
                    level=0
                    [or]
                          level=1
                    [/or]
                    [not]
                        side=$side_number
                    [/not]
                [/have_unit]
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.
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:

((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.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Beer
Posts: 5
Joined: March 21st, 2019, 6:00 pm

Re: Killing weapon special doesn't work

Post by Beer »

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 :whistle:
Post Reply