Animate hidden unit's attack

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
The_Gnat
Posts: 2215
Joined: October 10th, 2016, 3:06 am
Contact:

Animate hidden unit's attack

Post by The_Gnat »

Hi, I want to animate a lightning strike without the unit showing. So that it just looks like a lightning bolt.

This is my code:

Code: Select all

				# create fake unit
                                {NAMED_GENERIC_UNIT 1 (Elder Mage) 10 9 fake fake}
                                # hide fake unit
				[hide_unit]
					id=fake
				[/hide_unit]
				# move the screen so it is centered on the lightning
				[scroll_to_unit]
					id=fake
				[/scroll_to_unit]

				#animate the lightning attack
				[animate_unit]
					flag=attack

					[filter]
						id=fake
					[/filter]

					[primary_attack]
						range=ranged
					[/primary_attack]

					hits=yes
				[/animate_unit]
				
				# kill the fake unit
				[kill]
					id=fake
				[/kill]
Supposedly this should work, but in practice it doesn't. Is it not possible to animate a hidden unit? When I run this code I don't see anything at all so is the problem that the animation is hidden as well?

Any help would be great! :D
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: Animate hidden unit's attack

Post by enclave »

sorry for stupid question but have you tried the same code without hiding unit? Make sure the code works at all first..

PS. after you figure out if the problem is with "hidden unit" or with your code, here is a part of my working code for unit animation attack:

Code: Select all

[animate_unit]
			flag=attack
			[filter]
			x,y=$CG_archer.x,$CG_archer.y
			[/filter]
			[primary_attack]
			range=ranged
			[/primary_attack]
			hits=hit
			with_bars=yes
			[facing]
			[filter]
			x,y=$hac_ranged_attack_target.x,$hac_ranged_attack_target.y
			[/filter]
			[/facing]
			[/animate_unit]
comparing yours and mine I noticed a difference.. hits=hit (mine) hits=yes (yours) no idea if that makes a difference or not.. but for some reason i have hit instead of yes.. idk
User avatar
The_Gnat
Posts: 2215
Joined: October 10th, 2016, 3:06 am
Contact:

Re: Animate hidden unit's attack

Post by The_Gnat »

enclave wrote: December 29th, 2018, 10:46 pm sorry for stupid question but have you tried the same code without hiding unit? Make sure the code works at all first..
No that is a perfectly reasonable question. Yes I did test it and it animated the attack exactly when I remove:

Code: Select all

[hide_unit]
	id=fake
[/hide_unit]

Also is your code animating a hidden unit?
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: Animate hidden unit's attack

Post by enclave »

nope my code is not for hidden units...

I also would want to know a way to animate hidden units.. but not hidden like u did, but hidden via using:

Code: Select all

[effect]
apply_to=image_mod
replace="O(0)"
[/effect]
coz unit animations dont seem to work on that unit anymore.. unless maybe i need to start them with ~BLIT(...?
User avatar
The_Gnat
Posts: 2215
Joined: October 10th, 2016, 3:06 am
Contact:

Re: Animate hidden unit's attack

Post by The_Gnat »

Yes I agree it would be quite useful. I briefly considered animating a fake unit which had no image, but then you would still be able to see the HP bar, which defeats the point.

Potentially is it possible to animate a fake unit, such as the move_unit_fake does?
User avatar
Ravana
Forum Moderator
Posts: 2950
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Animate hidden unit's attack

Post by Ravana »

Bars can be given offset to make them out of screen.

I would first ask why you want to make it part of unit animation? Could use event.
User avatar
The_Gnat
Posts: 2215
Joined: October 10th, 2016, 3:06 am
Contact:

Re: Animate hidden unit's attack

Post by The_Gnat »

It might be possible to create a unit with no image. Then to animate it with_bars=no. That would be equivalent to an invisible unit.

But that would require an extra unit which I would rather not create if it is possible.

EDIT: @ ravana - I am merely trying to simulate the attack frame for the Elder Mage lightning. Is there another way?
User avatar
Ravana
Forum Moderator
Posts: 2950
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Animate hidden unit's attack

Post by Ravana »

Havent tried animations, didnt notice anything useful from reference today. Seems that doing it with unit is still the way to go.
User avatar
The_Gnat
Posts: 2215
Joined: October 10th, 2016, 3:06 am
Contact:

Re: Animate hidden unit's attack

Post by The_Gnat »

Okay. Thank you for responding!

So for now I believe I will create a fake version of the [base_unit] Elder Mage, not listed in the help menu with no picture and animate it with_bars=no.
User avatar
beetlenaut
Developer
Posts: 2814
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Animate hidden unit's attack

Post by beetlenaut »

I've done this before, and it works fine: Use a [for] loop that does something like:

Code: Select all

[item]
    ...
    halo="image-"+$i+".png"
[/item]
[delay]...
[remove_item]...
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: Animate hidden unit's attack

Post by enclave »

wait.. could you tell me why you are hiding the unit at all? because your unit doesnt have the type of attack or? coz I just add the attack in some animation cases and remove it right after attack happened.. ?

PS.
ah yeah i think i know what you mean..

in this case you could probably add animation to your king that would have ranged lightning strike.. and then remove it after attack... just a thought..

oh well.. im full of silly ideas.. you could change defense animation of the unit before lightning (the defense animation would include lightning strike in it) and then use [harm_unit] tag with just defender animation in it... and then of course restore the defense animation to default..
User avatar
The_Gnat
Posts: 2215
Joined: October 10th, 2016, 3:06 am
Contact:

Re: Animate hidden unit's attack

Post by The_Gnat »

enclave wrote: December 29th, 2018, 11:31 pm wait.. could you tell me why you are hiding the unit at all? because your unit doesnt have the type of attack or? coz I just add the attack in some animation cases and remove it right after attack happened.. ?
Its because I want a lightning strike far off on the other side of the map. For story reasons it is a strange sighting that the characters see. :)

in this case you could probably add animation to your king that would have ranged lightning strike.. and then remove it after attack... just a thought..

you could change defense animation of the unit before lightning (the defense animation would include lightning strike in it) and then use [harm_unit] tag with just defender animation in it... and then of course restore the defense animation to default..
That is true but I want the event un-related to your units. I appreciate your suggestions though and will keep them in mind for future scenarios 8)
beetlenaut wrote: December 29th, 2018, 11:30 pm I've done this before, and it works fine: Use a [for] loop that does something like:
Thank you! I think this is probably best for what I want to do. :D
User avatar
The_Gnat
Posts: 2215
Joined: October 10th, 2016, 3:06 am
Contact:

Re: Animate hidden unit's attack

Post by The_Gnat »

Thanks to beetlenaut here is my final working code:

Code: Select all

{RANDOM 1..3} # random direction for the lightning

	# iterate through each image to animate a lightning strike
	[for]
		start,end,step=1,4,1

		[do]
			# show the image
			 # using halo="" not image="" so that a larger sized image such as lightning can be shown
			[item]
				redraw=yes
				x,y=10,9
				halo="halo/lightning-bolt-$random|-$i|.png"    
			[/item]
			# pause so the animation can be seen properly
			[delay]
				time=80
			[/delay]
			# remove that frame of the animation
			[remove_item]
				x,y=10,9
			[/remove_item]
		[/do]
	[/for]
	
{CLEAR_VARIABLE random}

enclave
Posts: 936
Joined: December 15th, 2007, 8:52 am

Re: Animate hidden unit's attack

Post by enclave »

The_Gnat wrote: December 30th, 2018, 1:17 am Thanks to beetlenaut here is my final working code:
thanks for sharing the working code :) might be useful to many people some day.
Post Reply