Clean "Hit and Run" weapons special

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
Gibimbius
Posts: 14
Joined: June 3rd, 2018, 11:27 am

Clean "Hit and Run" weapons special

Post by Gibimbius »

Is there a way to make a weapon special that adds back to the attacking unit some movement points at the end of the attack? I've found some some solutions but they were hackish and weren't weapon specials, they were abilities.
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Clean "Hit and Run" weapons special

Post by Ravana »

Only difference between ability and weapon special is the filter. So if you call those hacky there is no better way.
Gibimbius
Posts: 14
Joined: June 3rd, 2018, 11:27 am

Re: Clean "Hit and Run" weapons special

Post by Gibimbius »

Thanks, I dit it, based on Era of Magic Goblin Assassin "Hit and Run" ability:

Weapon special to be placed on the unit .cfg:

Code: Select all

#define WEAPON_SPECIAL_RETREAT
    [dummy]
        id=retreat
        name= _ "retreat"
        description=_"The attacker gains one move point after attacking"
    [/dummy]
#enddef
Event to be placed on scenario .cfg:

Code: Select all

###WEAPON_SPECIAL_RETREAT
    [event]
        name=attack_end
        id=retreat_event
        first_time_only=no
        [filter_attack]
            #name=$weapon
	    special=retreat	    
        [/filter_attack]
        {VARIABLE_OP unit.moves add 1}
        [unstore_unit]
            variable=unit
            {COLOR_WHITE}
            text="1"
            find_vacant=no
        [/unstore_unit]	
    [/event]
Any idea on how to make AI recognise the extra move point and use it as usual? So far the AI just ignores the ability.
vghetto
Posts: 755
Joined: November 2nd, 2019, 5:12 pm

Re: Clean "Hit and Run" weapons special

Post by vghetto »

Look at the mods Antar and Assassins in the Forest. I think they have something similar to what you want.
User avatar
lhybrideur
Posts: 369
Joined: July 9th, 2019, 1:46 pm

Re: Clean "Hit and Run" weapons special

Post by lhybrideur »

There is also Hit and run in Loti
Here is the code

Code: Select all

#define WEAPON_SPECIAL_HIT_AND_RUN
	[dummy]
		id=hit and run
		name= _ "hit and run"
		description= _ "When this attack is used, the unit regains half of its max MP."
	[/dummy]
#enddef

Code: Select all

[event]
	name=attack end
	first_time_only=no

	[filter_attack]
		special=hit and run
	[/filter_attack]
	{VARIABLE_OP unit.moves add "$($unit.max_moves/2)"}
	[unstore_unit]
		variable=unit
		find_vacant=no
		advance=no
	[/unstore_unit]
[/event]
User avatar
Heindal
Posts: 1355
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Clean "Hit and Run" weapons special

Post by Heindal »

It can be done way easier. As long as you define "Hit and Run" as an ability or weapon special, that allows you to move after attacking.

You can use "movement_used=0". "This determines how many movement points using this attack expends.
By default all movement is used up, set this to 0 to make attacking with this attack expend no movement."

Code: Select all

[attack]
        name=Hitandrun
        description=_"Hit and Run"
        icon=attacks/dagger-curved.png
        type=blade
        range=melee
        damage=3
        number=5
        movement_used=0
[/attack]
You can also add a dummy special to the attack, that explains how it works.
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
User avatar
lhybrideur
Posts: 369
Joined: July 9th, 2019, 1:46 pm

Re: Clean "Hit and Run" weapons special

Post by lhybrideur »

This is something different. The first solution, proposed Gibimbius and I consume all the movement then add back some. Your solution consider the unit can use what's left of its movement after the attack.
WoodenGoblin
Posts: 5
Joined: May 23rd, 2018, 8:10 pm

Re: Clean "Hit and Run" weapons special

Post by WoodenGoblin »

AFAIK movement_used solution only makes sense if the unit has skirmisher (or the enemy has no ZOC), as otherwise it will lose all moves after moving next to the enemy even if it doesn't attack. Event solution can work even without skirmisher.
User avatar
Heindal
Posts: 1355
Joined: August 11th, 2011, 9:25 pm
Location: Germany, Karlsruhe
Contact:

Re: Clean "Hit and Run" weapons special

Post by Heindal »

I see, just wanted to mention it, as it is an easier solution for a hit and run special and Gibimbius wanted such an easy solution. I use it for my hit and run specials and it works fine, considering some drawbacks such as ZOC.
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
Post Reply