Hotkeys and Animate units at will (solved). Now: Choose weapon used in attack..

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
Retributive
Posts: 47
Joined: February 20th, 2009, 12:45 pm
Location: Bordeaux, FRANCE.

Hotkeys and Animate units at will (solved). Now: Choose weapon used in attack..

Post by Retributive » August 9th, 2019, 8:56 pm

Hello to all.
My request is simple:

Are there any "Hotkey" system/macro in the WML ?
For exemple, by pressing some Key combinations (ctrl+shift+A for exemple), being able to trigger some predefined events/macos.

Your help will be allways thankfully welcome.
Thanks for reading me.

Friendly yours,
Retributive.
Last edited by Retributive on August 14th, 2019, 9:48 pm, edited 3 times in total.

User avatar
Pentarctagon
Forum Administrator
Posts: 3947
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Hotkeys ?

Post by Pentarctagon » August 9th, 2019, 9:36 pm

You probably want [set_menu_item]'s [default_hotkey], with use_hotkey=only.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code

Retributive
Posts: 47
Joined: February 20th, 2009, 12:45 pm
Location: Bordeaux, FRANCE.

Re: Hotkeys ?

Post by Retributive » August 10th, 2019, 9:08 am

Thank you, Pentarctagon.
That was very useful, exactly what I was looking for !

Now I need to find macros to "provoke" an unit's "Death" and various "Animations"..
For exemple, I want to use a hotkey and the unit dies (with animations) or attacks (with animations), etc..

So far, I am able to "Teleport" it in a remote corner of the map, but not to kill it.
Setting the "hitpoints" (with "MODIFY_UNIT") to 0 doesn't work.. No clues about triggering the animations though..
But I only know this page:
https://www.wesnoth.org/macro-reference.xhtml
Maybe there is a more complete reference somewhere ?..

Friendly yours,
Retributive.

Retributive
Posts: 47
Joined: February 20th, 2009, 12:45 pm
Location: Bordeaux, FRANCE.

Re: Hotkeys ?

Post by Retributive » August 10th, 2019, 5:19 pm

Managed to get the unit killed on hotkey:

Code: Select all

	[set_menu_item]
		id=KILL_UNIT
		use_hotkey=only
			[default_hotkey]
			key="A"
			ctrl=yes
			shift=yes
			[/default_hotkey]		
		[filter_location]
		x=$x1
		y=$y1
		[/filter_location]
	[command]
		[harm_unit]
			[filter]
			x=$x1
			y=$y1
			[/filter]		
		amount=1000
		animate=yes
		[/harm_unit]
	[/command]	
	[/set_menu_item]
;)
Last edited by Retributive on August 10th, 2019, 5:36 pm, edited 1 time in total.

User avatar
Ravana
Moderator
Posts: 2156
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Hotkeys ?

Post by Ravana » August 10th, 2019, 5:36 pm

There already is hotkey for that - shift k.

Retributive
Posts: 47
Joined: February 20th, 2009, 12:45 pm
Location: Bordeaux, FRANCE.

Re: Hotkeys ?

Post by Retributive » August 10th, 2019, 6:58 pm

Thank you, Ravana, but it is only in "Debug" mode..
To "provoque" an attack animation, I am testing the "[do_command]" + "[attack]" tags, but it seems to require a "[destination]" unit to function...
Like this:

Code: Select all

[command]
	[do_command]
		[attack]
	        weapon=0            
		defender_weapon=0
			[source]
				x,y=$x1,$y1
			[/source]
			[destination]
				id=other	# A hidden unit ID
			[/destination]
		[/attack]
    [/do_command]
[/command]	
.. but it doesn't work..

User avatar
Ravana
Moderator
Posts: 2156
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Hotkeys ?

Post by Ravana » August 10th, 2019, 10:52 pm

[do_command] is designed for simulating user input. I believe that is not what you need.

Retributive
Posts: 47
Joined: February 20th, 2009, 12:45 pm
Location: Bordeaux, FRANCE.

Re: Hotkeys ?

Post by Retributive » August 11th, 2019, 7:54 am

Thank you, Ravana.
I think I'm gonna look into this part:

Code: Select all

...wesnoth.create_animator

(Version 1.13.7 and later only)

    wesnoth.create_animator()

Returns an object that can be used to set up and run an animation. The object has three methods:

    animator:run()

Runs the animation. (Version 1.15.0 and later only) Implicitly clears the animator.
... 
Located here:
https://wiki.wesnoth.org/LuaWML/Units#wesnoth.effects

Retributive
Posts: 47
Joined: February 20th, 2009, 12:45 pm
Location: Bordeaux, FRANCE.

Re: Hotkeys ?

Post by Retributive » August 11th, 2019, 8:36 pm

Figured it out:

Code: Select all

		[command]
			[animate_unit]
			flag=attack
			[filter]
				id=$unit.id	# I use a variable in the "select" "[event]"
			[/filter]			
			[/animate_unit]
		[/command]	
It comes inside a "[set_menu_item]" :

Code: Select all

	[set_menu_item]
		id=unit_attacks			# or whatever unique lowercase ID
		use_hotkey=only
			[default_hotkey]
				key="A"		# or any key you want
				ctrl=yes
				shift=yes	# you can add "alt" too
			[/default_hotkey]		
		[command]
		# do your thing here
		[/command]	
	[/set_menu_item]
It was that simple (found sample codes somewhere in the forums), but there is not (to my knowledge) a list of the usable "flag"s. So I used this page here:
https://units.wesnoth.org/1.5.10/animations.html
Most of the time you only have "attack" or "defend", for some reason "death", "standing" and "idle" don't work (didn't test the others..).

I struggled because I was putting the "[filter]" tag before the "flag". You have to put it after.
All I need to do is find a way to choose the facing of the attack, and I'm done (for now ;))

All my thanks to Ravana and Pentarctagon for their advices and helps!

Friendly yours,
Retributive.

Retributive
Posts: 47
Joined: February 20th, 2009, 12:45 pm
Location: Bordeaux, FRANCE.

Re: [SOLVED] Hotkeys and Animate units at will.

Post by Retributive » August 12th, 2019, 8:10 pm

Quick update:
I had trouble triggering the animations in the desired directions (6 hotkeys -> 6 different directions).
The unit strikes automatically in direction where it entered the last Hex on its last movement.
ie: If it entered from the south-ouest side, it will automatically attack towards the north-est direction.

I solved it that (brutal and inelegant) way:

Code: Select all

[command]	# I created 6 Hotkeys for the six directions of attack
	[animate_unit]
	flag=attack
	[filter]
		id=$unit.id	# I use a variable in the "select" "[event]"
	[/filter]	
	[facing]	
		[filter]	# I created 6 units ID-ed from the 6 directions, in the outter void zone border Hexes of the map.
		id=north	# That way the unit is attacking in the desired direction while setting the "facing" "filter" to the desired ID.
		[/filter]	# The 6 dum units being hidden of course. "north" being the ID of the northern dum unit.
	[/facing]		# All the filters with coordonates I tried ("[filter] x,y=$x1,($y1+1) [/filter]" for example), did not work.
	[/animate_unit]
[/command]	
If someone knows a better solution, he is welcome to share.. ;)

Friendly yours,
Retributive.

User avatar
Ravana
Moderator
Posts: 2156
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: [SOLVED] Hotkeys and Animate units at will.

Post by Ravana » August 12th, 2019, 8:35 pm

Unit has facing attribute, it is not replay safe, but could work here to update that before animation.

Retributive
Posts: 47
Joined: February 20th, 2009, 12:45 pm
Location: Bordeaux, FRANCE.

Re: [SOLVED] Hotkeys and Animate units at will.

Post by Retributive » August 13th, 2019, 9:23 am

"[modify_unit]+facing=" works perfectly, thank you Ravana !

Retributive
Posts: 47
Joined: February 20th, 2009, 12:45 pm
Location: Bordeaux, FRANCE.

Re: [SOLVED] Hotkeys and Animate units at will.

Post by Retributive » August 13th, 2019, 7:48 pm

I am having issues definig the attack used for the animation, I am trying this code:

Code: Select all

		[animate_unit]
		flag=attack
			[filter]
				id=$unit.id
			[/filter]	
			[primary_attack]
				name=$unit.attack[0].name	# Tested: this is the name of the first attack of the unit
			[/primary_attack]
		[/animate_unit]
..but I don't always get the same attack every trigger..
How can I achieve that ?

I simply copied the code from the "Scepter of Fire"'s scenario "6_Towards_the_Caves.cfg" below..

Code: Select all

        [animate_unit]
            flag=attack

            [filter]
                id=Thursagan
            [/filter]

            [primary_attack]
                name=hammer
            [/primary_attack]

            hits=yes

            [facing]
                [filter]
                    id=Durstorn
                [/filter]
            [/facing]

            [animate]
                flag=defend

                [filter]
                    id=Durstorn
                [/filter]

                hits=yes
                text= _ "<i>Thud!</i>"
                red=255
                green=0
                blue=0

                [facing]
                    [filter]
                        id=Thursagan
                    [/filter]
                [/facing]
            [/animate]
        [/animate_unit]
Without the "[animate]" and the "[facing]" parts. Are they needed for the animation to correctly function ?

Any advice will be welcome, as usual ;)

Post Reply