Event "when leader dies"

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
Rya
Posts: 350
Joined: September 23rd, 2009, 9:01 am

Event "when leader dies"

Post by Rya »

I have 4 vs 4 CPU scenario and want to add the following rule to it: If one of the CPU leaders die, the other 3 leaders get 100 gold. How can I write such an event?
Wesnoth
The developer says "no".
User avatar
TheScribe
Posts: 465
Joined: June 17th, 2012, 8:17 pm
Location: You won't know till it's too late

Re: Event "when leader dies"

Post by TheScribe »

I think this is what you want. (I might have made a mistake in the code, it's been a while :roll: )

Code: Select all

  [event]
   name=die
    [filter]
     id=BadGuy
    [/filter]
    [gold]
     amount=100
     side=Badguyside2, Badguyside3, Badguyside4
    [/gold]
  [/event]
Replace the id in the 'die' event with the leader's id, and replace the sides with the sides that are to recieve gold.
Sorta on a break from the forums ATM, have been for a while. If I was doing something for/with you and I haven't recently, that's why, I will be back soon hopefully.
JaMiT
Inactive Developer
Posts: 511
Joined: January 22nd, 2012, 12:38 am

Re: Event "when leader dies"

Post by JaMiT »

So the four leaders are on the same team? As in they have the same team_name= in their [side] definitions? That would be one way to identify them in a [filter] tag. Here's a translation of your rule into WML:

Code: Select all

    [event]
        # "If [someone] die"
        name = die

        # "one of the CPU leaders"
        [filter]
            canrecruit = yes    # This matches leaders
            [filter_side]
                team_name = CPU  # This matches the same field in a [side] definition.
            [/filter_side]
        [/filter]

        # "get 100 gold"
        [gold]
            amount = 100

            # "the other 3 leaders" (which I am taking to mean the allies of the killed unit)
            [filter_side] # This tag (but not its contents) goes away in 1.12.
                [allied_with]
                    side = $unit.side   # This means the side of the unit that died.
                [/allied_with]
                [not]
                    side = $unit.side   # This means the side of the unit that died.
                [/not]
            [/filter_side]
        [/gold]
    [/event]
You could instead do a filter on each leader's ID, but then you would need to list all four IDs. The fewer details you encode into your event, the more robust the event is as changes are made to the scenario.
Last edited by JaMiT on January 15th, 2013, 7:31 pm, edited 1 time in total.
Reason: WML corrections
User avatar
TheScribe
Posts: 465
Joined: June 17th, 2012, 8:17 pm
Location: You won't know till it's too late

Re: Event "when leader dies"

Post by TheScribe »

I'd go with JaMiT's code if I were you, mine's kinda crude...
Sorta on a break from the forums ATM, have been for a while. If I was doing something for/with you and I haven't recently, that's why, I will be back soon hopefully.
Rya
Posts: 350
Joined: September 23rd, 2009, 9:01 am

Re: Event "when leader dies"

Post by Rya »

Oh yeah that solution seems really nice.

How would I know the leader unit ID anyway? Shouldn't I rather filter for side then?

By the way, the closing filter tag should be [/filter] I think. :-)


Edit: Hmm doesn't work it gives the following error:

Code: Select all

empty_side= and no [filter_side] is deprecated, use either side=1 or [filter_side]
That's strange...
Wesnoth
The developer says "no".
JaMiT
Inactive Developer
Posts: 511
Joined: January 22nd, 2012, 12:38 am

Re: Event "when leader dies"

Post by JaMiT »

Rya wrote:How would I know the leader unit ID anyway?
Sometimes leader IDs are assigned in the scenario.
Rya wrote:By the way, the closing filter tag should be [/filter] I think. :-)
Right. Fixed it.
Rya wrote:Edit: Hmm doesn't work it gives the following error:

Code: Select all

empty_side= and no [filter_side] is deprecated, use either side=1 or [filter_side]
That's strange...
Oh sorry. I was using the 1.11/1.12 syntax. In 1.10, you still need a [filter_side] tag (which I've edited into my earlier post).
Rya
Posts: 350
Joined: September 23rd, 2009, 9:01 am

Re: Event "when leader dies"

Post by Rya »

It works now. Thanks!
Wesnoth
The developer says "no".
Post Reply