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

Re: Gaining XP whenever a unit is killed by plague

Post by Helmet »

Yes, it's late here, too. I should've gone to bed a while ago. But I felt like I was on the precipice of a breakthrough, so I kept thinking...just a little longer.

I put fungal plague in quotes. And turned-off the id=Moho part. Dang, I forgot what I learned in the playtest. I think Moho stopped getting experience. All these playtests are blurring together.

Filters! Arg!
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 »

I'm going to call it quits for the night. My next idea would take a while. I'm thinking maybe I need an [if] and [then]. It feels wrong, though. Thanks for the help!
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 »

Yes, argh.

My preliminary results are as follows: I stripped out all of the "optional" stuff, added an indicator, and set up a very simple test scenario. It seems to work so far...

Code: Select all

[event]
	name=die
	first_time_only=no
	[filter_second_attack]
		special=plague
	[/filter_second_attack]
    [message]
        speaker=narrator
        message= _ "A $second_unit.type| has just slain a $unit.type| with a plague attack."
    [/message]
[/event]
(In other words, I have made it properly filter for plague. So now we know how to filter for a special.) Next up: filter for the correct special!

---

EDIT: Eureka! It appears that the attack filters (in practice) don't work with the special's name after all! The wiki lied to me!
I made a quick and sloppy unit with a fungal plague special. Then here are the filters I tried:

Code: Select all

[filter_second_attack]
    special="plague"
[/filter_second_attack]
Oddly, this one (just "plague") matched not only the regular plague, but also the fungal plague. I don't know why. Maybe it's because all of the plague-type specials are classified as plague? I mean, if you look at it, the special definition opens with [plague] and closes with [/plague], just like how ambush and submerge are both [hides]. Huh. I ought to run some tests on that. Not tonight, though.
---

Code: Select all

[filter_second_attack]
    special="fungal plague"
[/filter_second_attack]
Second attempt. This event never fired. At all. Like Wesnoth apparently thought there was no such special as "fungal plague".
---

Code: Select all

[filter_second_attack]
    special="fungal plague(FungalZombie)"
[/filter_second_attack]
Third attempt. This one worked perfectly, at least as far as I tested it. When one of my "FungalZombie" units killed an enemy, then I got the message that said it was working. When a different unit killed an enemy, no message.

---

And now I had better test whether it works to combine this with an ID-based filter. BRB.

---

Everything seems to work!

Code: Select all

[event]
    name=die
    first_time_only=no

    [filter_second]
        side=1
        [not]
            id=Moho
        [/not]
    [/filter_second]

    [filter_second_attack]
        special="fungal plague(FungalZombie)"
    [/filter_second_attack]

	[modify_unit]
		[filter]
			id=Moho
		[/filter]
		[effect]
			apply_to=experience
			increase=5
		[/effect]
	[/modify_unit]
[/event]
You will need to "fix" two parts: change "FungalZombie" to the unit type that fungal plague actually creates, and change Moho's XP boost back to the variable that depends on the difficulty. (You said the XP boost part was working already, and I didn't want to have to re-create variable assignments in my simple test scenario if I didn't need to.)

I think that solves everything, so I'm off to bed now. Goodnight!
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Gaining XP whenever a unit is killed by plague

Post by Celtic_Minstrel »

Helmet wrote: October 21st, 2020, 12:36 am It seems like filter_second acts like a mirror and reverses primary and secondary units.
This is quite some misinterpretation… but I guess you've gotten it figured out by now, right?
Pilauli wrote: October 21st, 2020, 5:17 am

Code: Select all

[filter_second_attack]
    special="fungal plague(FungalZombie)"
[/filter_second_attack]
Third attempt. This one worked perfectly, at least as far as I tested it. When one of my "FungalZombie" units killed an enemy, then I got the message that said it was working. When a different unit killed an enemy, no message.
I am very confused at how this could possibly work, though maybe I'm missing some other change you made. Still, even then, if this really works, it seems like a weird undocumented feature, which also means there's no guarantee that it will continue to work in later versions.

The reason why all the other attempts weren't working is because special checks the tag name of the ability, which in this case is [plague], rather than the id. There is a new feature to check the ID instead using special_id, but I'm not sure if it works in version 1.14. I thought it did, but the wiki says it doesn't. If special_id doesn't work in 1.14 though, you could use a formula:

Code: Select all

[filter_second_attack]
	formula="index_of('fungal plague', specials) >= 0"
[/filter_second_attack]
I'm pretty sure that will work even in 1.14.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
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, 5:17 am EDIT: It appears that the attack filters (in practice) don't work with the special's name after all!
Wow, the code works. Thank you!
Celtic_Minstrel wrote: October 21st, 2020, 12:58 pm
Helmet wrote: October 21st, 2020, 12:36 am It seems like filter_second acts like a mirror and reverses primary and secondary units.
This is quite some misinterpretation… but I guess you've gotten it figured out by now, right?
Yes, at long last, I understand filter_second. Thanks for asking.
Pilauli wrote: October 21st, 2020, 5:17 am

Code: Select all

[filter_second_attack]
    special="fungal plague(FungalZombie)"
[/filter_second_attack]
Celtic_Minstrel wrote: October 21st, 2020, 12:58 pmI am very confused at how this could possibly work, though maybe I'm missing some other change you made. Still, even then, if this really works, it seems like a weird undocumented feature, which also means there's no guarantee that it will continue to work in later versions.

The reason why all the other attempts weren't working is because special checks the tag name of the ability, which in this case is [plague], rather than the id. There is a new feature to check the ID instead using special_id, but I'm not sure if it works in version 1.14. I thought it did, but the wiki says it doesn't. If special_id doesn't work in 1.14 though, you could use a formula:

Code: Select all

[filter_second_attack]
	formula="index_of('fungal plague', specials) >= 0"
[/filter_second_attack]
I tested it and it almost works. If a side 1 unit without the special fungal plague kills an enemy unit, Moho gains bonus experience, which is not desirable. Moho should only gain the experience bonus when a unit becomes a fungal monster.

I've been working in 1.15.5, so I didn't test special_id in 1.14. Now that I think about it, I probably should be working in 1.14. I'm not sure if this is accurate, but it seemed like the animations in 1.15 ran smoother than in 1.14, and since I'm doing custom animations, I've been using 1.15.5.
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 »

Celtic_Minstrel wrote: October 21st, 2020, 12:58 pm
The reason why all the other attempts weren't working is because special checks the tag name of the ability, which in this case is [plague], rather than the id. There is a new feature to check the ID instead using special_id, but I'm not sure if it works in version 1.14.
The special_id worked in 1.15.5 like you indicated. A whole mess of new problems arose when I added my campaign to the 1.14 add-ons folder, so I couldn't test special_id there.

Code: Select all

    
[filter_second_attack]
       		special_id="fungal plague(Shroomling)"  	# Celtic_Minstrel  << works
#       	special="fungal plague(Shroomling)" 	# Pilauli  << works
# 		formula="index_of('fungal plague', specials) >= 0" #   Celtic_Minstrel  << almost works
[/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 »

Celtic_Minstrel wrote: October 21st, 2020, 12:58 pm it seems like a weird undocumented feature, which also means there's no guarantee that it will continue to work in later versions.
Matching the id with special= is actually documented, although deprecated in recent development versions. From the wiki:
https://wiki.wesnoth.org/FilterWML#Filtering_Weapons wrote: special: filter on the attack's special power, matches both id and tag name. (Version 1.15.2 and later only) Deprecated, see special_id and special_type instead.
I was trying to use the older syntax so the campaign would have backwards compatibility with 1.14, but if it doesn't work there anyway, then yeah, special_id="fungal plague(FungalZombie)" or special_tag=plague would be better choices.

(The reason I was confused about "fungal plague" (the special's name) not working is because I misread "tag name" as plain old "name", so I expected it to work with the special's name. I'm not confused about that anymore; thanks for explaining, CelticMinstrel!)
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, 4:48 pm I was trying to use the older syntax so the campaign would have backwards compatibility with 1.14, but if it doesn't work there anyway, then yeah, special_id="fungal plague(FungalZombie)" or special_tag=plague would be better choices.
Thanks for doing that. Even though I'm coding for 1.15, I've been trying to avoid using the new tags that won't work with 1.14, so my campaign will run on 1.14 when it's done. But I'm also trying to avoid code that will be invalidated in the near future.

I like how WML keep evolving, with simpler and more powerful tags. Keep up the good work, developers!
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
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Gaining XP whenever a unit is killed by plague

Post by Celtic_Minstrel »

Ah, I think get why the weird code with "fungal plague(FungalZombie)" works. It's because the ID of the special wasn't what I expected from all the prior examples, but is instead this weird value with the parentheses.

I would recommend using special (for 1.14) or special_id (for 1.15) rather than a formula - I only posted the formula because I wasn't sure if there was another way to do it in 1.14.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
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 »

Oh. Thank you for clearing that up.
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
Nyanyanyan
Posts: 73
Joined: May 11th, 2018, 10:40 pm

Re: Gaining XP whenever a unit is killed by plague

Post by Nyanyanyan »

Bit late, but the reason this doesn't work is that "special" simply isn't a valid unit filter.
Only things listed on this wiki page are valid entries for the [filter] tag: https://wiki.wesnoth.org/StandardUnitFilter
Using the [has_weapon] tag should do the trick.

Code: Select all

[filter_second]
	[has_weapon]
		special=fungal plague
	[/has_weapon]
[/filter_second]
Author of Age of Lords and the Revolution and Civil War and Expendable Leaders 2 multiplayer mods.
User avatar
Celtic_Minstrel
Developer
Posts: 2166
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Gaining XP whenever a unit is killed by plague

Post by Celtic_Minstrel »

The previous examples weren't using it in a unit filter either. Your example is also wrong, because it'll trigger when a unit with a plague weapon kills something with a different weapon (for example, if you removed the "fungal" part it would match a necromancer who killed something with Chill Wave). Putting it in [filter_attack] or [filter_second_attack], which specifically matches the weapon being used for the attack, is the correct answer.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
Nyanyanyan
Posts: 73
Joined: May 11th, 2018, 10:40 pm

Re: Gaining XP whenever a unit is killed by plague

Post by Nyanyanyan »

Truth be told I didn't realize there was a second page of replies :9
And oh yeah, you're right. [filter_attack] is definitely the way to go. I was trying to show how to filter a unit having a weapon, like Helmet tried to do. Didn't think about the case of multiple weapons.
Author of Age of Lords and the Revolution and Civil War and Expendable Leaders 2 multiplayer mods.
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 »

Celtic_Minstrel wrote: November 5th, 2020, 2:43 pm Putting it in [filter_attack] or [filter_second_attack], which specifically matches the weapon being used for the attack, is the correct answer.
Wow! Tested and proved effective. Thank you for anticipating and solving a subtle problem that would've arisen later.
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.
Post Reply