Gaining XP whenever a unit is killed by plague

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.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Gaining XP whenever a unit is killed by plague

Post by Helmet »

A have a unit named Moho on side 1. Also on side 1 are units with a special plague type called fungal plague. I want Moho to gain experience whenever an enemy unit is killed by any side 1 unit using their fungal plague attack. I've tried many different filters and variations, and I can't get it right. The experience should be awarded to Moho during counter-attacks as well. Do I need a whole new event for counter-attacks using [filter_second_attack] or can a filter which uses [or] work? Thanks for your help.

The awarding of experience to Moho via [modify_unit] works, by the way. But not when I filter it.

I thought a name=die event should contain the code. I tried name=attack end, also.

Code: Select all

[event]
	name=die
	first_time_only=no
	[filter]
		side=1
		[filter_attack]
			special=fungal plague
		[/filter_attack]	
	[/filter]
	[modify_unit]
		[filter]
			id=Moho
		[/filter]
		[effect]
			apply_to=experience
			increase=$xp_leader_bonus #   <<< 	varies based on difficulty mode
		[/effect]
	[/modify_unit]
[/event]
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Pilauli
Posts: 115
Joined: August 18th, 2020, 12:56 pm

Re: Gaining XP whenever a unit is killed by plague

Post by Pilauli »

In a die event, [filter] generally filters the unit that just died. Try changing [filter] to [filter_second] to filter the "second unit" that killed the recently-deceased unit, while sticking with the die event. If that doesn't work, I'll try to research it later when I have more time.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Gaining XP whenever a unit is killed by plague

Post by Helmet »

That totally worked! Thanks, Pilauli.

But the solution makes no sense to me. Why did I need filter_second and not a common [filter]? After all, when I employ name=last_breath, a common filter works fine. Why doesn't name=last_breath also need a filter_second?

The following code for last_breath works like I expect, regardless of whether the unit died while attacking or counter-attacking.

I don't get it. What am I not seeing here?

Code: Select all

[event]
     	name=last_breath
		[filter]     		    
     			side=2
     		[/filter]
     		[message]
			speaker=unit
     			message= _ "I am a side 2 unit and now I am dead."
     		[/message]    
[/event]
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Pilauli
Posts: 115
Joined: August 18th, 2020, 12:56 pm

Re: Gaining XP whenever a unit is killed by plague

Post by Pilauli »

In last breath, you're filtering based on the dying unit's side. It says "I am a side 2 unit". Let me write you another example:

Code: Select all

[event]
    name=last_breath
    [filter_second]
        side=1
    [/filter_second]
    [message]
        speaker=unit
        message= _ "I don't know what side I am on, but I do know that I am dead and a side 1 unit killed me."
    [/message]
[/event]
I hope this illustrates the difference between what [filter] and [filter_second] do.

Both the die and the last_breath events describe the units' roles like this:
https://wiki.wesnoth.org/EventWML#last_breath wrote: Triggers when the primary unit is killed by the secondary unit
When you want to filter the primary (dying) unit, you use regular [filter]. When you want to filter the secondary (killer) unit, you use [filter_second].

Here is the section of the EventWML page that talks about filters: https://wiki.wesnoth.org/EventWML#.5Bfilter.5D

Edited about 2 seconds after posting to elaborate on some slightly unclear wording. I need to stop doing this.
Edit2: Realized that the quote block was trying to parse the entirety of my "https://wiki.wesnoth.org/EventWML#last_breath or https://wiki.wesnoth.org/EventWML#last_breath" attribution as a single URL, so I removed half of it so that it would actually work as a link. I really need to stop doing this.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Gaining XP whenever a unit is killed by plague

Post by Helmet »

I'm still struggling to understand what's wrong with my code.

I tested your code example. Your code displays a final message from any unit killed by side 1. That helped some. It seems like filter_second acts like a mirror and reverses primary and secondary units.

Could you make another example, maybe one that uses name=die?

I use last_breath all the time. I don't know why die is giving me such a hard time. Maybe I'm misunderstanding what die is for. The simple name may be misleading me. What do people generally use it for? If it had a different name, what would it be?

For example, last_breath could be renamed final_actions, because many tags can be employed prior to the death animation ([if], [set_variable], [end_level], etc.), none of which might involve a "last breath" message. Or maybe I'm using last_breath wrong.

* * *

New filter problem. Okay, Moho should gain experience when allied units kill an enemy unit with their fungal plague type attack. That code now works. But Moho is also gaining experience when he kills a unit with his fungal plague type attack. I don't want him to gain the typical experience and the bonus experience from his own kills. I need to filter Moho out. I am still struggling with understanding why the code works, so my attempts to subtract Moho have not worked. How do I exclude Moho?

Functional code, except for being able to exclude Moho:

Code: Select all

[event]
	name=die
	first_time_only=no
	[filter_second]
			 special=fungal plague
	[/filter_second]		         
		[message]
			speaker=narrator
			message="Moho gains "$xp_leader_bonus|" experience"$display_one_time|"."
		[/message]
		[modify_unit]
			[filter]
				id=Moho
			[/filter]
			[effect]
				apply_to=experience
				increase=$xp_leader_bonus
			[/effect]
		[/modify_unit]
[/event]
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Pilauli
Posts: 115
Joined: August 18th, 2020, 12:56 pm

Re: Gaining XP whenever a unit is killed by plague

Post by Pilauli »

Code: Select all

[event]
    name=last_breath
    [filter]
        race=elf
     [/filter]
     [filter_second]
         race=orc
     [/filter_second]
     [message]
         speaker=unit
         message= _ "I am a lovely elf, but a vicious orc killed me!"
     [/message]
     [message]
         speaker=second_unit
         message= _ "I am a strong orc, and I just killed one of those annoying elves!  But it won't shut up!"
     [/message]
[/event]

Code: Select all

[event]
    name=die
    [filter]
        race=elf
     [/filter]
     [filter_second]
         race=orc
     [/filter_second]
     # The elf can't say anything because the elf is dead.
     [message]
         speaker=second_unit
         message= _ "I am a strong orc, and I just killed one of those annoying elves!  Bam!  Dead!"
     [/message]
[/event]
Does that make sense?

---

Your example with last_breath works because you want the event to trigger when particular units (any side 2 units) die. Whenever a unit reaches the last_breath stage, the game uses [filter] to check whether the dying unit is one of your special units (i.e. on side 2) or not.

Your original die event did not work, because you want the event to trigger when particular units (on side 1) kill anyone else (using fungal plague). When a unit dies, the game uses [filter] to check whether the dead unit is/was one of your special ones. But you want it to check whether the dead unit was killed by one of your special units.

---

In other words, the game always uses [filter] for the victim and [filter_second] for the killer.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Gaining XP whenever a unit is killed by plague

Post by Helmet »

Ah! I think I finally understand. I wasn't filtering what I thought I was filtering.

Whew.

Thanks for those examples, Pilauli. They helped a lot.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Gaining XP whenever a unit is killed by plague

Post by Helmet »

Pilauli wrote: October 21st, 2020, 1:57 am Your original die event did not work, because you want the event to trigger when particular units (on side 1) kill anyone else (using fungal plague). When a unit dies, the game uses [filter] to check whether the dead unit is/was one of your special ones. But you want it to check whether the dead unit was killed by one of your special units.
filter_second has provided a new challenge. I didn't want Moho to gain any bonus experience when he personally kills an enemy unit (side 2) with his special plague type attack. He should only receive the regular experience. I added-to the filter to exclude Moho and it seems to work, as far as that goes. However, something weird is happening.

When an enemy units kills any side 1 unit who possesses the special plague type attack, Moho gains an experience bonus. Moho shouldn't gain an experience bonus when his own units are killed by side 2.

Here's the code. It almost works. It doesn't give Moho bonus experience for his own kills.

Then again, when a side 1 unit who does not have the special plague type attack kills a side 2 unit, Moho is now receiving bonus experience and he should not. Man, I fix one thing and something else breaks...

Any help would be appreciated.

Code: Select all

	name=die
	first_time_only=no
	[filter_second]
		[and]
			 special=fungal plague
		[/and]
		[and]
			[not]
			 	id=Moho
			[/not]			
		[/and]
	[/filter_second]
Last edited by Helmet on October 21st, 2020, 3:54 am, edited 1 time in total.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Pilauli
Posts: 115
Joined: August 18th, 2020, 12:56 pm

Re: Gaining XP whenever a unit is killed by plague

Post by Pilauli »

I suspect that the special=fungal plague part isn't working right.

I'm going to do research on the wiki, but if you see this before I finish my research, then you can test the following to see if I'm on the right track:

Have one unit (which is not Moho and does not have the special attack) kill another unit (which is not Moho and does not have the special attack.) Basically, is the computer misunderstanding the filter special=fungal plague, or does it completely ignore it?

Oops, I just re-read your post, and it looks like you already basically tested this, and it just ignores it. Sorry. Will go do research now.

Okay, results found! (I hope.)
Reference: https://wiki.wesnoth.org/EventWML#.5Bfi ... _attack.5D

I think your code should actually look like this:

Code: Select all

	name=die
	first_time_only=no
	[filter_second]
		[not]
		 	id=Moho
		[/not]
	[/filter_second]
	[filter_second_attack]
		special=fungal plague
	[/filter_second_attack]
Basically, it looks like [filter_attack] (and [filter_second_attack]) stand alone, rather than going inside other filters.
About the [and]s:
Last edited by Pilauli on October 21st, 2020, 4:07 am, edited 1 time in total.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Gaining XP whenever a unit is killed by plague

Post by Helmet »

Fungal plague doesn't have any new coding. I copied it from mainline. All I did was add the word "fungal."

At the moment, the filter seems to think 3 things:
1) If a unit with the special fungal plague kills an enemy unit, give bonus experience to Moho.
2) If a unit who possesses the special fungal plague is killed by an enemy unit, give bonus experience to Moho (this is not desirable.)
3) Moho possesses the special fungal plague, but if he kills an enemy unit, he does not gain bonus experience (this is desirable).

Here is fungal plague.

Code: Select all

#define WEAPON_SPECIAL_FUNGAL_PLAGUE_TYPE TYPE
    # Canned definition of the Plague ability to be included in a
    # [specials] clause (with type specifier).
    [plague]
        id=fungal plague({TYPE})
        name= _ "fungal plague"
        description= _ "When a unit is killed by a Fungal Plague attack, that unit is replaced with a unit on the same side as the unit with the Plague attack. This doesn’t work on Undead or units in villages."
        type={TYPE}
    [/plague]
#enddef
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Pilauli
Posts: 115
Joined: August 18th, 2020, 12:56 pm

Re: Gaining XP whenever a unit is killed by plague

Post by Pilauli »

Hah, okay, well, I just edited my last post (because I didn't see you post), so you can try what I wrote in there.

Does fungal plague itself work? As in, does it properly make a fungus zombie or whatever it's supposed to make, when a unit with a fungal plague attack kills another unit? If so, I don't think it's likely to be a problem.

Unless you mis-spelled the name somehow, but I think the name is spelled properly.

Edit: can you clarify what happens if two units, neither of which has the fungal plague special, fight and one kills the other? Because that may shed light on how the filter is currently working failing to work.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Gaining XP whenever a unit is killed by plague

Post by Helmet »

Fungal plague turns a slain enemy unit into a fungus monster. It works.

I added the new filters you coded and did tests with units without fungal plague. Combat was normal. Test 1: the enemy footpad killed the side 1 spearman. Test 2: the side 1 spearman killed an enemy thug. Moho did not get bonus experience from this.

Unfortunately, Moho no longer gets bonus experience when one of his units turns an enemy into a fungus monster.

Hmm.

Code: Select all

	name=die
	first_time_only=no
	[filter_second]
		[not]
		 	id=Moho
		[/not]
	[/filter_second]
	[filter_second_attack]
		special=fungal plague
	[/filter_second_attack]
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Pilauli
Posts: 115
Joined: August 18th, 2020, 12:56 pm

Re: Gaining XP whenever a unit is killed by plague

Post by Pilauli »

AAAAAAAAAGH FILTERS LOL

Put "fungal plague" into quotes or parentheses, just to make sure that Wesnoth processes it as a whole word.

Try commenting out the killer-is-not-Moho part, temporarily, to see if that works.

If neither of those work, I'll have to think about it some more.
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: Gaining XP whenever a unit is killed by plague

Post by Helmet »

Okay, but before I do that, I made a little progress, maybe? See what you think. I added a side=2 filter in the beginning.
Moho gets bonus experience when units are turned into fungal monsters. Good. He doesn't get get bonus experience when he personally turns units into fungal monsters. Good. And now he doesn't get bonus experience when his special fungal plague units are killed. Good.

But here is the one problem. Moho gets bonus experience when the side 1 spearman kills an enemy unit.

Does that info help identify the problem?

Code: Select all

[event]
	name=die
	first_time_only=no
	[filter]
		side=2
	[/filter]
	[filter_second]
		[and]
			 special=fungal plague
		[/and]
		[and]
			[not]
			 	id=Moho
			[/not]			
		[/and]	
	[/filter_second]
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
Pilauli
Posts: 115
Joined: August 18th, 2020, 12:56 pm

Re: Gaining XP whenever a unit is killed by plague

Post by Pilauli »

This masks the problem a little bit, but doesn't solve it.

The trouble is that Wesnoth isn't seeing the filter for the special properly.

And, er, I'm not sure why. So now I should probably either go to sleep (it's late where I am) or else try random things until I can get it to work. Which one sounds like more fun? Tests it is.
Post Reply