filter unit by killing the unit with set_menu_item

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
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

filter unit by killing the unit with set_menu_item

Post by LordAwsomeness »

Hello so I have been attempting to figure out how to filter a unit that is killed by set_menu_items. the initial filter to make sure the correct unit works; as I simply use x,y=$x1,$y1. however after the unit has been killed, I fire a custom event that is supposed to reward players for making the kill. yet as I have delved deeper into the whole ordeal, I realized that the custom event is firing, but not reading the unit on x,y=$x1,$y1 as the unit that I want it to store.

below are the multiple codes that I am using the custom event and the set_menu_item that kill the unit. (it might be a bit confusing for you as you do not have all of the code)


this code below is the custom event that is fired. not including the entire event as it is quite lengthy. however the code does not recognize a filter_second even when I specifically included it in the [fire_event] tag specifying the [primary_unit] and [secondary_unit].

Code: Select all

[event]
name=spoils_forced
first_time_only=no

	
#this event was created specifically for units dying to casting attacks.
	[store_unit]
		variable=victim
		[filter]
			x,y=$x1,$y1
		[/filter]
	[/store_unit]
below is the event that kills in the [set_menu_item]. so essentially the x,y=$x1,$y1 works for the initial right-click, however when I fire the custom event above it doesn't read the unit on x,y=$x1,$y1. since this isn't working I need some ideas how to fix the code so I can store the proper unit.

Code: Select all

		[if]
			[variable]
				name=unit.hitpoints
				less_than="$({AMOUNT}*$($unit.resistance.{DAMAGE_TYPE}/100))"
			[/variable]
			[then]
[sound]
name={SOUND}
[/sound]
				[harm_unit]
					[filter]
						x,y=$x1,$y1
					[/filter]
					amount="{AMOUNT}"
					damage_type={DAMAGE_TYPE}
					fire_event=yes
					experience=yes
					animate=yes
					kill=yes
				[/harm_unit]
				

                [fire_event]
                    name=spoils_forced
                    [primary_unit]
                        side=$side_number
			canrecruit=yes
                    [/primary_unit]
					[secondary_unit]
						x,y=$x1,$y1
					[/secondary_unit]
                [/fire_event]
			[/then]
			[else]
[sound]
name={SOUND}
[/sound]
				[harm_unit]
					[filter]
						x,y=$x1,$y1
					[/filter]
					amount="{AMOUNT}"
					damage_type={DAMAGE_TYPE}
					fire_event=yes
					experience=no
					animate=no
					kill=no
				[/harm_unit]
			[/else]
		[/if]
the only alternative I can currently think of is having the custom event fire before the unit is killed. I would prefer not to do this however as that would look very weird to players when the unit kill reward animations are going off before the unit has even taken damage
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
User avatar
Pentarctagon
Project Manager
Posts: 5539
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: filter unit by killing the unit with set_menu_item

Post by Pentarctagon »

If you're passing $x1,$y1 as the [secondary_unit], then in your custom event those coordinates would be in $x2,$y2, wouldn't they?
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
LordAwsomeness
Posts: 203
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Re: filter unit by killing the unit with set_menu_item

Post by LordAwsomeness »

Pentarctagon wrote: February 22nd, 2020, 1:43 am If you're passing $x1,$y1 as the [secondary_unit], then in your custom event those coordinates would be in $x2,$y2, wouldn't they?
I actually tried that as well, but it doesn't recognize $x2,$y2 because its not an attack. it's a right-click menu so it counts it as $x1,$y1
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure
- Creator of LA_RPG ERA
User avatar
octalot
General Code Maintainer
Posts: 783
Joined: July 17th, 2010, 7:40 pm
Location: Austria

Re: filter unit by killing the unit with set_menu_item

Post by octalot »

I think there's no unit on that hex when you reach the [fire_event]name=spoils_forced, because it was already killed by harm_unit. How about adding an [event]name=die just before the harm_unit, so that it's triggered by the unit dying?
Post Reply