prevent event if second unit lacks a weapon_special

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
User avatar
Gwledig
Posts: 539
Joined: March 30th, 2009, 5:10 pm
Location: UK

prevent event if second unit lacks a weapon_special

Post by Gwledig »

hi
I have some WML where an event needs to happen, but only if a secondary unit doesn't have a weapon special (notmovedproj)

Everything else expected is working, but the event still triggers even though I have added this filter -

Code: Select all

#Stop restore moves if the spawning unit doesn't have weapon special notmovedproj
		[filter_second]
		side=$side_number
		id=$unit.modifications.trait[0].id
		[not]
		[filter_attack]
		special=notmovedproj
		[/filter_attack]
		[/not]
		[/filter_second]
I have tried putting this in various places including nesting in the main unit filter, renaming filter_second to simply [filter], the $unit.modifications.trait[0].id refers to a trait containing the ID of the secondary unit I am trying to filter on, this works fine otherwise and matches the secondary unit elsewhere in the same macro...

the fuller version of the macro is:

Code: Select all

#if player moved new projectile to a location adjacent to unit which spawned it on an option menu, restore all mv points
[event]
name=moveto
first_time_only=no
	[modify_unit]
		[filter]
			[filter]
			role=projectile
			[or]
			role=rpg
			[/or]
			[or]
			role=grenade
			[/or]
			[/filter]
		side=$side_number
		x=$unit.x  
		y=$unit.y 
		
			[filter_adjacent]
			adjacent=n,ne,se,s,sw,nw
			is_enemy=false
			side=$side_number
			id=$unit.modifications.trait[0].id
			[/filter_adjacent]
	
		[/filter]
		
		#Stop restore moves if the spawning unit doesn't have weapon special notmovedproj
		[filter_second]
		side=$side_number
		id=$unit.modifications.trait[0].id
		[not]
		[filter_attack]
		special=notmovedproj
		[/filter_attack]
		[/not]
		[/filter_second]
			
	 moves=$unit.max_moves 
	[/modify_unit]
[/event]
#enddef
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)
User avatar
Ravana
Forum Moderator
Posts: 2481
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: prevent event if second unit lacks a weapon_special

Post by Ravana »

Try has_attack.
User avatar
Gwledig
Posts: 539
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: prevent event if second unit lacks a weapon_special

Post by Gwledig »

thanks Ravana, this seem to be the proper attribute in SUF, however I still can't get this to work, I can however definitely filter on the required unit with a variable, this is working elsewhere in the macro, I'm just not sure if the [has_attack] should be id= special= or name=, the documentation says 'special' but I'm dubious if this works for custom weapon_special, as the documentation only refers to core specials... I also wonder if [filter_second] is really working, or if it should be at a different level or even in the root level of event... i have tried dozens of combinations, such as putting it as a [filter] in event, but it's still ignored, I wonder if weapon_special cannot be filtered at all?

Code: Select all

#if player moved new projectile to a location adjacent to unit which spawned it on an option menu, restore all mv points
[event]
name=moveto
first_time_only=no

     
      [set_variable]
       [filter]
        side=$side_number
        x=$unit.x  
        y=$unit.y
        [/filter]
       name=tempspawnid
       value=$unit.modifications.trait[0].id
      [/set_variable]
     
	
	[modify_unit]
		[filter]
			[filter]
			role=projectile
			[or]
			role=rpg
			[/or]
			[or]
			role=grenade
			[/or]
			[/filter]
			side=$side_number
			x=$unit.x  
			y=$unit.y 
			[filter_adjacent]
			adjacent=n,ne,se,s,sw,nw
			is_enemy=false
			side=$side_number
			id=$tempspawnid
			[/filter_adjacent]
			
			
			#restore moves only if the spawning unit has weapon special notmovedproj
			[filter_second]
			side=$side_number
			id=$tempspawnid
			[has_attack]
			special=notmovedproj
			[/has_attack]
			[/filter_second]
		
		[/filter]
		

		
	 moves=$unit.max_moves 
	[/modify_unit]
	

		[clear_variable]
		name=tempspawnid
		[/clear_variable]

[/event]
#enddef
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)
User avatar
Gwledig
Posts: 539
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: prevent event if second unit lacks a weapon_special

Post by Gwledig »

Hm this is a bit offside but I wonder if has_weapon in SUF has really been deprecated in 114 vs the newer has_attack I'll give this a try later...
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)
User avatar
Ravana
Forum Moderator
Posts: 2481
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: prevent event if second unit lacks a weapon_special

Post by Ravana »

[set_variable][filter] does not make sense.

[filter][filter] does not make sense - otherwise there would be no issues about some tags asking for [filter] and some asking for its content.

[filter][filter_second] does not make sense.

Thus the used part of you code is

Code: Select all

[event]
name=moveto
first_time_only=no

     
      [set_variable]
       name=tempspawnid
       value=$unit.modifications.trait[0].id
      [/set_variable]
     
	
	[modify_unit]
		[filter]
			side=$side_number
			x=$unit.x  
			y=$unit.y 
			[filter_adjacent]
			adjacent=n,ne,se,s,sw,nw
			is_enemy=false
			side=$side_number
			id=$tempspawnid
			[/filter_adjacent]
		[/filter]
		

		
	 moves=$unit.max_moves 
	[/modify_unit]
	

		[clear_variable]
		name=tempspawnid
		[/clear_variable]

[/event]
User avatar
Gwledig
Posts: 539
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: prevent event if second unit lacks a weapon_special

Post by Gwledig »

Thanks Ravana I guess thats got rid of some unecessary stuff.. Will test later, I am going to try filter_second at the same level - ie not nested - as filter, and try

Code: Select all

 
[filter_second] 
side=$side_number
id=$tempspawnid
has_weapon=notmovedproj
[/filter_second]
Although I wonder if the id needs to be in [filter_wml]...
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)
User avatar
Gwledig
Posts: 539
Joined: March 30th, 2009, 5:10 pm
Location: UK

Re: prevent event if second unit lacks a weapon_special

Post by Gwledig »

Ok got this working to filter on weapon special by just adding -

Code: Select all

[has_attack]
special=notmovedproj
[/has_attack]
...to Ravena's revised version inside the filter_adjacent (I figured no need for another filter as was filtering on adjacent unit anyway)

the working WML is:

Code: Select all

#if spawning unit has weapon notmovedproj restore moves on projectile
[event]
name=moveto
first_time_only=no
      [set_variable]
       name=tempspawnid
       value=$unit.modifications.trait[0].id
      [/set_variable]
      
	[modify_unit]
		[filter]
			side=$side_number
			x=$unit.x  
			y=$unit.y 
			[filter_adjacent]
			adjacent=n,ne,se,s,sw,nw
			is_enemy=false
			side=$side_number
			id=$tempspawnid
			
			[has_attack]
			special=notmovedproj
			[/has_attack]
			
			[/filter_adjacent]
			
	
		[/filter]
		

		
	 moves=$unit.max_moves 
	[/modify_unit]
		[clear_variable]
		name=tempspawnid
		[/clear_variable]
[/event]
#enddef
Maintainer of Conquest (Original Gameplay), Conquest+, Conquest+ Space/Ranged, Chaoz Battle of the Wizards, Lazersquad (squad game), WesCraft (building MP game)
Post Reply