Weapon filter not working

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.
Gibimbius
Posts: 14
Joined: June 3rd, 2018, 11:27 am

Weapon filter not working

Post by Gibimbius »

I'm trying make a weapon special that multiplies the weapon damage by 3x whenever it defends against an attacker using the charge special on its own weapon:

Code: Select all

#define WEAPON_SPECIAL_SPEARWALL

	[damage]
		id=spearwall
		name= _ "spearwall"
		description= _ "This counter attack causes 3x damage against charging attackers"
		name_inactive = "spearwall"
		description_inactive = "This counter attack causes 3x damage against charging attackers"
		multiply=3
		active_on=defense
		[filter_opponent]
		    [has_attack]
		        special_id_active=charge
		   [/has_attack]
	        [/filter_attacker]		
	[/damage]
		
#enddef
It's not working, it's behaving in erratic manner against attacks that have nothing to do with the "charge" special. What is wrong with the code? Can you show me the right code?
User avatar
Ravana
Forum Moderator
Posts: 2948
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Weapon filter not working

Post by Ravana »

Use [filter_weapon] not [has_attack]. And in my experience special_id_active is not completely reliable, so try without _active too.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Weapon filter not working

Post by gfgtdf »

Ravana wrote: March 30th, 2020, 10:24 am Use [filter_weapon] not [has_attack].
Hmm but has_attack should also work, right? I'm quite sure that I have used code like this my addon before.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Ravana
Forum Moderator
Posts: 2948
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Weapon filter not working

Post by Ravana »

filter_weapon checks weapon used in current attack.
Gibimbius
Posts: 14
Joined: June 3rd, 2018, 11:27 am

Re: Weapon filter not working

Post by Gibimbius »

Code: Select all

#define WEAPON_SPECIAL_SPEARWALL

	[damage]
		id=spearwall
		name= _ "spearwall"
		description= _ "Defender causes 3X the damage against charging attackers"
		name_inactive = "spearwall"
		description_inactive = "Defender causes 3X the damage charging attackers"
		multiply=3
		active_on=defense
		[filter_attacker]
		    [filter_weapon]
		        special_id=charge
		   [/filter_weapon]
	        [/filter_attacker]		
	[/damage]
		
#enddef

Still not working. It always just multiplies the weapon damage on defense by 3 against any attackers. As if it had no filter at all.
newfrenchy83
Code Contributor
Posts: 165
Joined: October 6th, 2017, 12:57 pm

Re: Weapon filter not working

Post by newfrenchy83 »

Have you used 1.14 or 1.15.2 or1.15.3? Because special_id or special_type were implemented in oct 2019 in devellopement branch and no in 1.14 stable branch. If you not used 1.15.2 or 1.15.3 you must replace special_id by old special.
Gibimbius
Posts: 14
Joined: June 3rd, 2018, 11:27 am

Re: Weapon filter not working

Post by Gibimbius »

you must replace special_id by old special.
Thanks, that did the job :doh:

Code: Select all

#define WEAPON_SPECIAL_SPEARWALL

	[damage]
		id=spearwall
		name= _ "spearwall"
		description= _ "Defender causes 2X the damage against charging opponents"
		name_inactive = "spearwall"
		description_inactive = "Defender causes 2X the damage charging opponents"
		multiply=2
		active_on=defense
		[filter_attacker]
		    [filter_weapon]
		        special=charge
		   [/filter_weapon]
	        [/filter_attacker]		
	[/damage]
		
#enddef
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Weapon filter not working

Post by Celtic_Minstrel »

gfgtdf wrote: March 30th, 2020, 12:16 pm
Ravana wrote: March 30th, 2020, 10:24 am Use [filter_weapon] not [has_attack].
Hmm but has_attack should also work, right? I'm quite sure that I have used code like this my addon before.
They both work, but do different things.
  • Putting [has_attack] in the [filter_opponent] means it'll match for any enemy that has an attack matching the weapon filter, regardless of whether they're using that weapon in this particular fight.
  • Using [filter_weapon] in the [filter_opponent] means it'll match only if the attack currently being used by the enemy matches the filter. This is not part of the standard unit filter - it's a special thing used by the weapon special code.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Gibimbius
Posts: 14
Joined: June 3rd, 2018, 11:27 am

Re: Weapon filter not working

Post by Gibimbius »

New problem. I wish to make a weapon special that makes the owner harder to hit when he is adjacent to friendly units. Here is my attempt for one adjacent friend:

Code: Select all

#define WEAPON_SPECIAL_DFORMATION1
	[chance_to_hit]
	    id=dformation1
            name= _ ""
            description= _ "makes 5% harder to hit when next to a friend"
	    sub=5
	    apply_to=opponent
	    [filter_adjacent]
	        is_enemy=no
                count=1
	        adjacent= "n,ne,se,s,sw,nw" 
            [/filter_adjacent]
        [/chance_to_hit]
#endef
The filter is not being met for some reason and the special never does anything. What is wrong now?
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Weapon filter not working

Post by gfgtdf »

Celtic_Minstrel wrote: April 4th, 2020, 4:24 pm Putting [has_attack] in the [filter_opponent] means it'll match for any enemy that has an attack matching the weapon filter, regardless of whether they're using that weapon in this particular fight.

In the general case yes, but if you use special_active and that weapon special itself has a filter, then special_active will only return true for the weapon that is currently used in the combat.

In fact [has_attack] has to be used over [filter_attack] in events that handle wepopn specials, see https://github.com/wesnoth/wesnoth/issues/3317 (this is iirc because [filter_attack] is evalated on a _copy_ of the attack object that was used in combat that has the attack context not set correctly.)
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Ravana
Forum Moderator
Posts: 2948
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Weapon filter not working

Post by Ravana »

It just means that event-based specials must have all filtering inside event.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Weapon filter not working

Post by gfgtdf »

Ravana wrote: April 4th, 2020, 8:30 pm It just means that event-based specials must have all filtering inside event.
I dont see how it would mean that
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Ravana
Forum Moderator
Posts: 2948
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Weapon filter not working

Post by Ravana »

I understood your post that _active does not work. And I believe _active is only about conditions defined inside ability. So when all conditions are in event, then it does not matter that _active does not work properly.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Weapon filter not working

Post by gfgtdf »

Ravana wrote: April 4th, 2020, 11:06 pm I understood your post that _active does not work. And I believe _active is only about conditions defined inside ability. So when all conditions are in event, then it does not matter that _active does not work properly.
well technicially true, but this means that an ability cannot be used with filters, mainline weapon specials like poison can be used with any filter so that for example one unit only poisons unit with a lower level, and other units only poion drakes. puttins all filters in the wepon special implementation removes this flexibility. (and it will show the ability wrongly as active in the attack dialog)
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
newfrenchy83
Code Contributor
Posts: 165
Joined: October 6th, 2017, 12:57 pm

Re: Weapon filter not working

Post by newfrenchy83 »

Gibimbius wrote: April 4th, 2020, 6:37 pm New problem. I wish to make a weapon special that makes the owner harder to hit when he is adjacent to friendly units. Here is my attempt for one adjacent friend:

Code: Select all

#define WEAPON_SPECIAL_DFORMATION1
	[chance_to_hit]
	    id=dformation1
            name= _ ""
            description= _ "makes 5% harder to hit when next to a friend"
	    sub=5
	    apply_to=opponent
	    [filter_adjacent]
	        is_enemy=no
                count=1
	        adjacent= "n,ne,se,s,sw,nw" 
            [/filter_adjacent]
        [/chance_to_hit]
#endef
The filter is not being met for some reason and the special never does anything. What is wrong now?
try this

Code: Select all

	[chance_to_hit]
	    id=dformation1
            name= _ ""
            description= _ "makes 5% harder to hit when next to a friend"
	    sub=5
	    apply_to=opponent
	    [filter_self]
	     [filter_adjacent]
	        is_enemy=no
                count=1-5
            [/filter_adjacent]
            [/filter_self]
        [/chance_to_hit]
Post Reply