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: 6
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: 9739
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: 6
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.

hyper_cubed
Posts: 33
Joined: March 31st, 2018, 7:52 pm
Location: USA

Re: Making a unit invisible after attacking/killing

Post by hyper_cubed » August 25th, 2018, 3:11 pm

I know you probably already have what you need, but here something that I did that has a limited number of turns that it lasts. You have to use an object to get the number of turns lasting effect. I hope this can help you in some way. This would give a unit that just killed another unit the ability to have an unchecked stealth ability for the current turn plus two more (unless normal un-ambushing events occur such as encountering an enemey or attacking again). You could change the number of turns it lasts to make it more dynamic or longer lasting.

Object:

Code: Select all

#define fake_object_quick_step
[object]
	id=quick_step
	take_only_once="yes"
	duration=turn
	silent="yes"
	[effect]
		apply_to=new_ability
		[abilities]
			[hides]
				id=fake_object_quick_step
				name= _ ""
				female_name= _ ""
				description= _ ""
				affect_self=yes
				[filter]
				[/filter]
			[/hides]
		[/abilities]
	[/effect]
[/object]
#enddef
Ability:

Code: Select all

#define abilities_quick_step
[dummy]
	id=quick_step
	name= _ "quick step"
	description= _ "When this unit kills a foe it blends into the environment stealthily and awaits new prey, although such facades only last a short while."
[/dummy]
#enddef
Event:

Code: Select all

################################
# ability: quick step
################################
[event]
	name=die
	first_time_only=no
	[filter_second]
		ability=quick_step
	[/filter_second]
	{VARIABLE i 0}
	[while]
		[variable]
			name="i"
			less_than=$second_unit.modifications.object.length
		[/variable]
		[do]
			[if]
				[variable]
					name=second_unit.modifications.object[$i].id
					equals="quick_step"
				[/variable]
				[then]
					{VARIABLE check_quick_step "yes"}
				[/then]
			[/if]
		{VARIABLE_OP i add 1}
		[/do]
	[/while]
	{CLEAR_VARIABLE i}
	[if]
		[variable]
			name=check_quick_step
			not_equals="yes"
		[/variable]
		[then]
			[modify_unit]
				[filter]
					id=$second_unit.id
				[/filter]
				{fake_object_quick_step}
			[/modify_unit]
			[store_unit]
				variable=quick_stepper
				kill=no
				[filter]
					id=$second_unit.id
				[/filter]
			[/store_unit]
			{CLEAR_VARIABLE quick_stepper.status.uncovered}
			{VARIABLE quick_stepper.status.quick_stepping "yes"}
			{VARIABLE quick_stepper.variables.un_quick_step 0}
			[unstore_unit]
				variable=quick_stepper
				find_vacant=no
			[/unstore_unit]
			{CLEAR_VARIABLE quick_stepper}
		[/then]
	[/if]
	{CLEAR_VARIABLE check_quick_step}
[/event]
[event]
	name=turn_refresh
	first_time_only=no
	[store_unit]
		[filter]
			[filter_wml]
				[status]
					quick_stepping="yes"
				[/status]
			[/filter_wml]
			[and]
			[filter_side]
				side=$side_number
			[/filter_side]
			[/and]
		[/filter]
		variable=quick_stepper
	[/store_unit]
	{VARIABLE i 0}
	[while]
		[variable]
			name="i"
			less_than=$quick_stepper.length
		[/variable]
		[do]
			[if]
				[variable]
					name=quick_stepper[$i].variables.un_quick_step
					less_than=2
				[/variable]
				[then]
					[set_variables]
						name=inject_quick_step_obj
						mode=insert
						[value]
							[modifications]
								{fake_object_quick_step}
							[/modifications]
						[/value]
					[/set_variables]
					[set_variables]
						name=inject_quick_step_ability
						mode=insert
						[value]
							[abilities]
								[hides]
									id=fake_object_quick_step
									name= _ ""
									female_name= _ ""
									description= _ ""
									affect_self=yes
									[filter]
									[/filter]
								[/hides]
							[/abilities]
						[/value]
					[/set_variables]
					[set_variables]
						name=quick_stepper[$i]
						mode=merge
						[insert_tag]
							name=value
							variable=inject_quick_step_obj
						[/insert_tag]
					[/set_variables]
					[set_variables]
						name=quick_stepper[$i]
						mode=merge
						[insert_tag]
							name=value
							variable=inject_quick_step_ability
						[/insert_tag]
					[/set_variables]
					{CLEAR_VARIABLE inject_quick_step_obj}
					{CLEAR_VARIABLE inject_quick_step_ability}
					{VARIABLE_OP quick_stepper[$i].variables.un_quick_step add 1}
				[/then]
				[else]
					{CLEAR_VARIABLE quick_stepper[$i].status.quick_stepping}
					{CLEAR_VARIABLE quick_stepper[$i].variables.un_quick_step}
				[/else]
			[/if]
			[unstore_unit]
				variable=quick_stepper[$i]
				find_vacant=no
			[/unstore_unit]
		{VARIABLE_OP i add 1}
		[/do]
	[/while]
	{CLEAR_VARIABLE i}
	{CLEAR_VARIABLE quick_stepper}
[/event]

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

Re: Making a unit invisible after attacking/killing

Post by Nyanyanyan » September 2nd, 2018, 10:00 pm

hyper_cubed wrote:
August 25th, 2018, 3:11 pm
~
Sorry for the late response and thank you very much.

Post Reply