Unit see another

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
User avatar
lhybrideur
Posts: 206
Joined: July 9th, 2019, 1:46 pm

Unit see another

Post by lhybrideur »

Hi everyone,
Here is what I am trying to do : change the variable activated of a unit of type Ice Hole to yes when it sees a unit of side 1.
At first I did that :

Code: Select all

[event]
        name=sighted
        first_time_only=no
        [filter]
            side=1
        [/filter]

        [filter_second]
            type=Ice Hole
        [/filter_second]
        [if]
            [variable]
                name=second_unit.variables.activated
                equals=yes
            [/variable]
            [else]
                [modify_unit]
                    [filter]
                        id=$second_unit.id
                    [/filter]
                    [variables]
                        activated=yes
                        bats=3
                    [/variables]
                [/modify_unit]
            [/else]
        [/if]
    [/event]


But this does not work and i don't know why.
I could use a filter_location with a radius equals to the unit's vision but it would pass through walls, wouldn't it?

Has anyone an idea ?

P.S.: currently i'm doing the opposite which works, but this is not what I want to do.

Code: Select all

[event]
        name=sighted
        first_time_only=no
        [filter]
            type=Ice Hole
        [/filter]

        [filter_second]
            side=1
        [/filter_second]
        [if]
            [variable]
                name=unit.variables.activated
                equals=yes
            [/variable]
            [else]
                [modify_unit]
                    [filter]
                        id=$unit.id
                    [/filter]
                    [variables]
                        activated=yes
                        bats=3
                    [/variables]
                [/modify_unit]
            [/else]
        [/if]
    [/event]
Here is the full code of the unit

Code: Select all

[unit_type]
    id=Ice Hole
    name= _ "Ice Hole"
    race=elemental
    image="scenery/ice-hole.png"
    hitpoints=14
    movement_type=smallfly
    movement=0
    vision=9
    experience=100
    level=0
    alignment=neutral
    advances_to=null
    {AMLA_DEFAULT}
    cost=34
    usage=scout
    description= _ ""
    die_sound=ice-break.ogg
    [event]
        name=sighted
        first_time_only=no
        [filter]
            side=1
        [/filter]

        [filter_second]
            type=Ice Hole
        [/filter_second]
        [if]
            [variable]
                name=second_unit.variables.activated
                equals=yes
            [/variable]
            [else]
                [modify_unit]
                    [filter]
                        id=$second_unit.id
                    [/filter]
                    [variables]
                        activated=yes
                        bats=3
                    [/variables]
                [/modify_unit]
            [/else]
        [/if]
    [/event]

    [event]
        name=sighted
        first_time_only=no
        [filter]
            type=Ice Hole
        [/filter]

        [filter_second]
            side=1
        [/filter_second]
        [if]
            [variable]
                name=unit.variables.activated
                equals=yes
            [/variable]
            [else]
                [modify_unit]
                    [filter]
                        id=$unit.id
                    [/filter]
                    [variables]
                        activated=yes
                        bats=3
                    [/variables]
                [/modify_unit]
            [/else]
        [/if]
    [/event]

    [event]
        name=side 1 turn end
        first_time_only=no
        [store_unit]
            [filter]
                side=2,3
                type=Ice Hole
            [/filter]
            variable=ice_holes
        [/store_unit]
        {FOREACH ice_holes i}
        [if]
            [variable]
                name=ice_holes[$i].variables.activated
                equals=yes
            [/variable]
            [then]
                [unit]
                    side=$ice_holes[$i].side
                    type="Ice Bat"
                    x=$ice_holes[$i].x
                    y=$ice_holes[$i].y
                [/unit]
                [modify_unit]
                    [filter]
                        id=$ice_holes[$i].id
                    [/filter]
                    [variables]
                        bats="$($ice_holes[$i].variables.bats-1)"
                    [/variables]
                [/modify_unit]
                [if]
                    [variable]
                        name=ice_holes[$i].variables.bats
                        equals=1
                    [/variable]
                    [then]
                        [kill]
                            x,y=$ice_holes[$i].x,$ice_holes[$i].y
                        [/kill]
                    [/then]
                [/if]
            [/then]
        [/if]
        {NEXT i}
        {CLEAR_VARIABLE ice_holes}
    [/event]
[/unit_type]
User avatar
octalot
Developer
Posts: 578
Joined: July 17th, 2010, 7:40 pm
Location: Austria

Re: Unit see another

Post by octalot »

sighted triggers when the Ice Hole's side sees the other unit, and so won't trigger if another unit on the Hole's side has already spotted the unit.
lhybrideur wrote: June 21st, 2021, 9:49 am I could use a filter_location with a radius equals to the unit's vision but it would pass through walls, wouldn't it?
You can put a terrain filter in [filter_radius], as in NR S02:

Code: Select all

        [filter]
            id=Tallin
            [filter_location]
                [filter]
                    id=Hamel
                [/filter]
                radius=5
                [filter_radius]
                    terrain=!,X*
                [/filter_radius]
            [/filter_location]
        [/filter]
User avatar
lhybrideur
Posts: 206
Joined: July 9th, 2019, 1:46 pm

Re: Unit see another

Post by lhybrideur »

octalot wrote: June 21st, 2021, 11:11 am sighted triggers when the Ice Hole's side sees the other unit, and so won't trigger if another unit on the Hole's side has already spotted the unit.
Yeah, this is the reason I imagined for why it was not working
lhybrideur wrote: June 21st, 2021, 9:49 am I could use a filter_location with a radius equals to the unit's vision but it would pass through walls, wouldn't it?
You can put a terrain filter in [filter_radius], as in NR S02:

Code: Select all

        [filter]
            id=Tallin
            [filter_location]
                [filter]
                    id=Hamel
                [/filter]
                radius=5
                [filter_radius]
                    terrain=!,X*
                [/filter_radius]
            [/filter_location]
        [/filter]
This seems nice. I will try it at come back to write if it works as I want. Thank you
User avatar
lhybrideur
Posts: 206
Joined: July 9th, 2019, 1:46 pm

Re: Unit see another

Post by lhybrideur »

It works like a charm
Post Reply