Can someone walk me through an event filter?

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
ialdabaoth
Posts: 9
Joined: November 22nd, 2013, 5:57 pm

Can someone walk me through an event filter?

Post by ialdabaoth »

So, here's the logic of what I want to do:

I want a moveto event, that triggers whenever an Elvish Druid or Elvish Shyde moves out of a forest space that it started its turn in, into an adjacent space, but only if there are no other units (friendly or enemy) adjacent to the forest space OR the Druid/Shyde's new space. If those conditions are met, I want to spawn a friendly Wose Sapling in the forest space that the Druid/Shyde just left.

here's what I have so far:

Code: Select all

[event]
  name=moveto
  first_time_only=no
  [filter]
     type=Elvish Druid,Elvish Shyde
     [and]
        #I have no idea what to do here.
     [/and]
  [/filter]
  [unit]
    type=Wose Sapling
    side=$unit.side
    x,y=$x2,$y2
    animate=yes
  [/unit]
[/event]
Anonymissimus
Inactive Developer
Posts: 2460
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Can someone walk me through an event filter?

Post by Anonymissimus »

For the moved to hex, I suppose [filter]type=...[filter_adjacent][not] should do it.
For the moved away hex, you should probably figure it out using store_locations, and putting labels onto the stored locations. You don't need to put everything in that filter (not sure whether it's possible); if you manage to get the right locations stored, you can check all of those in a loop for units (but the moved unit itself is an exception), and use [if] to check for whether conditions are met. Once that's done you can perhaps "simplify" (complicate ?) the thing into a single filter.
If I cook up some code now it will most likely be wrong. It probably needs [filter_location], [filter_adjacent_location] and $x2 $y2 though.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
trewe
Translator
Posts: 122
Joined: December 24th, 2012, 5:37 pm
Location: Portugal
Contact:

Re: Can someone walk me through an event filter?

Post by trewe »

well,

Code: Select all

[event]
    name=moveto

    # Druid moves to a Forest tile which has no units adjacent
    [filter]
        type=Elvish Druid,Elvish Shyde
        [filter_location]
            terrain=*^F*
            [not]
                [filter_adjacent_location]
                    [filter]
                    [/filter]
                [/filter_adjacent_location]
            [/not]
        [/filter_location]
    [/filter]

    # if no units adjacent to the location just left (excluding the unit itself)
    [if]
        [have_location]
            x,y=$x2,$y2
            terrain=*^F*
            [filter_adjacent_location]
                x,y=$x1,$y1
            [/filter_adjacent_location]
            [not]
                [filter_adjacent_location]
                    [filter]
                        [not]
                            id=$unit.id
                        [/not]
                    [/filter]
                [/filter_adjacent_location]
            [/not]
        [/have_location]
        [then]
            [unit]
                type=Wose Sapling
                side=$unit.side
                x,y=$x2,$y2
                animate=yes
            [/unit]
        [/then]
    [/if]
[/event]
ialdabaoth
Posts: 9
Joined: November 22nd, 2013, 5:57 pm

Re: Can someone walk me through an event filter?

Post by ialdabaoth »

Brilliant! I even understand all that!

Thank you so much, you've given me a lot to work with.
Post Reply