Making a unit invisible after attacking/killing

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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
Nyanyanyan
Posts: 2
Joined: May 11th, 2018, 10:40 pm

Making a unit invisible after attacking/killing

Post by Nyanyanyan » August 5th, 2018, 2:34 pm

I've been trying to make a guerilla tactics ability, which would mean a unit could attack from a position where it is invisible and if the target dies, move to another location to re-enter invisibility.

I have succeeded in making the unit be able to move after attacking, but no matter what I tried I haven't been able to make the unit be able to stealth at all after the attack during that turn.

As an example, a unit has Ambush, it attacks another unit and kills it, it can then move another 3 hexes but even upon entering a forest the unit will not turn invisible until the start of the next turn of that faction.
I have tried working around that by just giving the unit a flat out invisibility ability through an object that only persist for one turn, but that still didn't work.

Here's the code that I've been using in my attempts so far:

Code: Select all

#define ABILITY_HARSTEALTH
    # Canned definition of the Stealth ability to be included in the
    # HITANDRUN filter clause.
    [hides]
        id=harstealth
        name= _ "stealth"
        female_name= _ "stealth"
        description= _ "The unit is invisible after a successful ambush.

Enemy units cannot see this unit, except if they have units next to it. Any enemy unit that first discovers this unit immediately loses all its remaining movement."
        affect_self=yes
    [/hides]
#enddef

#define HITANDRUN FILTER
    [event]
        name=die
        first_time_only=no

        [filter_second]
            {FILTER}
        [/filter_second]


        {MODIFY_UNIT x,y=$x2,$y2 moves 3}
        {MODIFY_UNIT x,y=$x2,$y2 attacks_left 0}

	[unstore_unit]
		variable=second_unit
		{COLOR_HEAL}
		text= _ "Stealth!"
		find_vacant=no
	[/unstore_unit]

	[object]
		silent=yes
		duration=turn
		[filter]
			x,y=$x2,$y2
		[/filter]

		[effect]
			apply_to=new_ability
			[abilities]
				id=harstealth
		  	 [/abilities]
		[/effect]
	[/object]
[/event]
#enddef
and putting

Code: Select all

{HITANDRUN (type=-unit id here-)}
Into the unit .cfg
I tried using both the id and the macro for the harstealth ability, but they both do nothing as far as I can see.

I have a feeling that this is caused by a restriction that doesn't allow units that fought that turn to enter invisibility, but that's just a guess.

Any help would be appreciated.

User avatar
zookeeper
WML Wizard
Posts: 9726
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Making a unit invisible after attacking/killing

Post by zookeeper » August 5th, 2018, 2:46 pm

You probably need to manually (re)set the unit.status.uncovered status to "no" as well.

Nyanyanyan
Posts: 2
Joined: May 11th, 2018, 10:40 pm

Re: Making a unit invisible after attacking/killing

Post by Nyanyanyan » August 5th, 2018, 5:22 pm

Thanks, that did the trick for being able to restealth.
Using the harstealth ability doesn't seem to work though, but since that was a workaround anyway it doesn't matter that much.

Thank you again for the quick and precise response.

Post Reply