AI Leader Message Upon Being Attacked?

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
CraZCanuck
Posts: 9
Joined: November 6th, 2020, 4:45 am

AI Leader Message Upon Being Attacked?

Post by CraZCanuck »

I've been looking through the mainline campaigns, trying to find how this would be done, but have either missed it or not seen it.

So I put the question to the gurus here:

Is there a way to have a message pop up when you enter a hex adjacent to and/or when you attack the boss for the first time? I'd love to have another tool at my disposal to show angry AI bosses. Maybe something similar to this:

Code: Select all

 
 
 [event]
        name=enter_hex
        [filter]
            side=1
            ???
        [/filter]

        [message]
            speaker=aileader
            message= _ "Stay back, invaders! You'll die for this!"
        [/message]
 [/event]       
        
 


Could I maybe filter it so it only proc's the first time a hex is entered adjacent to an AI leader? I don't know... Thinking out loud here. Thanks!


PS. Everyone here helping out in the WML Workshop is amazing. You're all the best. I am so looking forward to eventually releasing a campaign.
User avatar
WhiteWolf
Forum Moderator
Posts: 769
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: AI Leader Message Upon Being Attacked?

Post by WhiteWolf »

I'd use a subfilter to filter the adjacent unit:

Code: Select all

[event]
    name=enter_hex
    [filter]
        side=1
        [filter_adjacent]
            id=aileader
        [/filter_adjacent]
    [/filter]
    ... message stuff
By default, all events fire only once. So this will only trigger the first time a side 1 unit enters the hex next to aileader. Note that this will also trigger if (for example a skirmisher unit) moves past the enemy! If you want to avoid this, you should use [event]name=moveto instead of enter_hex.

Displaying a message when the boss is attacked for the first time is even simpler:

Code: Select all

[event]
    name=attack
    [filter]
        side=1
    [/filter]
    [filter_second]
        id=aileader
    [/filter_second]
    ... message stuff

This will trigger once, when a side 1 unit attacks aileader for the first time.
Main UMC campaigns: The Ravagers - now for 1.16, with new bugs!
Old UMC works: The Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Pilauli
Posts: 115
Joined: August 18th, 2020, 12:56 pm

Re: AI Leader Message Upon Being Attacked?

Post by Pilauli »

To answer a question you didn't ask (but might, perhaps, have been wondering about), it's also possible to make the AI leader respond differently to different units...

Code: Select all

[event]
    name=attack
    [filter]
        id=Brutus
    [/filter]
    [filter_second]
        id=Caesar
    [/filter_second]
    [message]
        speaker=Caesar
        message= _ "You too, Brutus?"
    [/message]
[/event]

[event]
    name=attack
    [filter]
        id=Ghost
    [/filter]
    [filter_second]
        id=Caesar
    [/filter_second]
    [message]
        speaker=Caesar
        message= _ "What hit me?"
    [/message]
[/event]

[event]
    name=attack
    [filter]
        side=1
        [not]
            id=Brutus, Ghost
        [/not]
    [/filter]
    [filter_second]
        id=Caesar
    [/filter_second]
    [message]
        speaker=Caesar
        message= _ "Ouch!"
    [/message]
[/event]
Disclaimer: not historically accurate.
In this case, if you attack with a horde including Brutus, Ghost (who, in my mind, is an actual ghost, or at least a very sneaky assassin), and several other units, Caesar will say all three things.

If you want to make him only say something to the first attacker, then you nee to put it all inside the same event. You can use various conditionals (I would recommend [if] or [switch]) inside of the event to make it do different things depending on who the attacker is. I find [if] a pain to type and read, so I tend to avoid it. I've never actually used [switch], but it looks neat. If you are interested, you can read more about them here: https://wiki.wesnoth.org/ConditionalActionsWML
CraZCanuck
Posts: 9
Joined: November 6th, 2020, 4:45 am

Re: AI Leader Message Upon Being Attacked?

Post by CraZCanuck »

Pilauli wrote: November 19th, 2020, 9:15 am To answer a question you didn't ask (but might, perhaps, have been wondering about), it's also possible to make the AI leader respond differently to different units...

Code: Select all

[event]
    name=attack
    [filter]
        id=Brutus
    [/filter]
    [filter_second]
        id=Caesar
    [/filter_second]
    [message]
        speaker=Caesar
        message= _ "You too, Brutus?"
    [/message]
[/event]

[event]
    name=attack
    [filter]
        id=Ghost
    [/filter]
    [filter_second]
        id=Caesar
    [/filter_second]
    [message]
        speaker=Caesar
        message= _ "What hit me?"
    [/message]
[/event]

[event]
    name=attack
    [filter]
        side=1
        [not]
            id=Brutus, Ghost
        [/not]
    [/filter]
    [filter_second]
        id=Caesar
    [/filter_second]
    [message]
        speaker=Caesar
        message= _ "Ouch!"
    [/message]
[/event]
Disclaimer: not historically accurate.
In this case, if you attack with a horde including Brutus, Ghost (who, in my mind, is an actual ghost, or at least a very sneaky assassin), and several other units, Caesar will say all three things.

If you want to make him only say something to the first attacker, then you nee to put it all inside the same event. You can use various conditionals (I would recommend [if] or [switch]) inside of the event to make it do different things depending on who the attacker is. I find [if] a pain to type and read, so I tend to avoid it. I've never actually used [switch], but it looks neat. If you are interested, you can read more about them here: https://wiki.wesnoth.org/ConditionalActionsWML
This is gold. I did not ask but you answered the question I wish I had. :lol: :lol: :lol:
Post Reply