Animation of storm

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
serclino
Posts: 40
Joined: May 18th, 2018, 9:54 pm

Animation of storm

Post by serclino »

Hi guys,

is it somehow possible to make an animation of storm hitting certain hex? I mean animation of Delfador's range attack, but without Delfador's presence. :D

Can anybody help?

Thanks!
User avatar
MoonyDragon
Posts: 149
Joined: November 29th, 2017, 5:46 pm

Re: Animation of storm

Post by MoonyDragon »

Hi there!
I assume you want to include your lightning as a part of some (start/moveto/???) event. In that case, you can easily animate a lightning by including this macro into your scenario file:

EDIT: Changed the LIGHTNING_HITS_HEX macro to circumvent a bug related to [remove_image]. (suggested by vghetto)

Code: Select all

#define LIGHTNING_HITS_HEX X Y
[set_variable]
    name=random_lightning
    rand="1,2,3"
[/set_variable]
[sound]
    name=lightning.ogg
[/sound]
[item]
    x,y={X},$({Y}-2)
    halo=halo/lightning-bolt-$random_lightning|-[1~4].png:100
[/item]
[delay]
    time=400
[/delay]
[remove_item]
    x,y={X},$({Y}-2)
    halo=halo/lightning-bolt-$random_lightning|-[1~4].png:100
[/remove_item]
[clear_variable]
    name=random_lightning
[/clear_variable]
#enddef
Whenever you want to display a lightning animation onto some hex, use the newly defined {LIGHTNING_HITS_HEX X Y} macro.
One example:

Code: Select all

[event]
    name=moveto
    
    [filter]
        side=1
        x,y=10,5
    [/filter]
    
    {LIGHTNING_HITS_HEX 10 5}
[/event]
In this case, the poor unit that moves to the hex x,y=10,5 gets struck by a lightning! Luckily for the unit though, it receives no damage :D
Last edited by MoonyDragon on February 17th, 2020, 2:33 pm, edited 1 time in total.
Default L0 Era - Level 1 leaders with level 0 recruits!
serclino
Posts: 40
Joined: May 18th, 2018, 9:54 pm

Re: Animation of storm

Post by serclino »

MoonyDragon: Thank you :-) This is exactly what I've wanted. However, few days ago I found another solution, which also works for me. But I forgot to update this thread, that my problem is solved.
Still thank you for defining this variable for me (I'm not familiar with this yet).

Here is another way how to do it. Maybe someone with same task like me can use it later.

Code: Select all


	[item]
            x,y=10,5
            halo=halo/lightning-bolt-1-1.png
        [/item]

        [delay]
            time=50
        [/delay]

        [item]
            x,y=10,5
            halo=halo/lightning-bolt-1-2.png
        [/item]

        [delay]
            time=50
        [/delay]

        [item]
            x,y=10,5
            halo=halo/lightning-bolt-1-3.png
        [/item]

        [delay]
            time=50
        [/delay]

        [sound]
            name=lightning.ogg
        [/sound]

        {FLASH_WHITE ()}

        [item]
            x,y=10,5
            halo=halo/lightning-bolt-1-4.png
        [/item]

        [delay]
            time=400
        [/delay]

        [remove_item]
            x,y=10,5
        [/remove_item]

vghetto
Posts: 755
Joined: November 2nd, 2019, 5:12 pm

Re: Animation of storm

Post by vghetto »

MoonyDragon wrote: February 4th, 2020, 3:58 pm Hi there!
I assume you want to include your lightning as a part of some (start/moveto/???) event. In that case, you can easily animate a lightning by including this macro into your scenario file:

Code: Select all

#define LIGHTNING_HITS_HEX X Y
[set_variable]
    name=random_lightning
    rand="1,2,3"
[/set_variable]
[sound]
    name=lightning.ogg
[/sound]
[item]
    x,y={X},$({Y}-2)
    name=lightning_image
    halo=halo/lightning-bolt-$random_lightning|-[1~4].png:100
[/item]
[delay]
    time=400
[/delay]
[remove_item]
    name=lightning_image
[/remove_item]
[clear_variable]
    name=random_lightning
[/clear_variable]
#enddef
Whenever you want to display a lightning animation onto some hex, use the newly defined {LIGHTNING_HITS_HEX X Y} macro.
One example:

Code: Select all

[event]
    name=moveto
    
    [filter]
        side=1
        x,y=10,5
    [/filter]
    
    {LIGHTNING_HITS_HEX 10 5}
[/event]
In this case, the poor unit that moves to the hex x,y=10,5 gets struck by a lightning! Luckily for the unit though, it receives no damage :D
There is a problem with this code because remove_item is broken, there's github ticket about it somewhere.
The remove_item code will remove all images from your map, not just the lightning_image. I know because that's what happened to me when I tried using the LIGHTNING_HITS_HEX macro for my mod :)
User avatar
MoonyDragon
Posts: 149
Joined: November 29th, 2017, 5:46 pm

Re: Animation of storm

Post by MoonyDragon »

vghetto wrote: February 16th, 2020, 10:07 pm There is a problem with this code because remove_item is broken, there's github ticket about it somewhere.
The remove_item code will remove all images from your map, not just the lightning_image. I know because that's what happened to me when I tried using the LIGHTNING_HITS_HEX macro for my mod :)
The issue you are referring to exists only in wesnoth 1.15.2+dev, so for most users here, this is no reason to panic :lol:
But if you happen to use the most recent developmental (use with caution) version, you can make the code work nonetheless.
In the link, doofus-01 specified that the issue does not apply when coordinates are given, so simply change

Code: Select all

[remove_item]
    name=lightning_image
[/remove_item]
to

Code: Select all

[remove_item]
    x,y={X},$({Y}-2)
    name=lightning_image
[/remove_item]
Default L0 Era - Level 1 leaders with level 0 recruits!
vghetto
Posts: 755
Joined: November 2nd, 2019, 5:12 pm

Re: Animation of storm

Post by vghetto »

MoonyDragon wrote: February 17th, 2020, 2:14 am The issue you are referring to exists only in wesnoth 1.15.2+dev, so for most users here, this is no reason to panic :lol:
I'm not sure how you concluded that this exists only in 1.15.2+dev? I used 1.14.9 and it happened with that.
Yes, the addition of the x,y will not remove all other images, but it will remove all images occupying that hex (which is 2 hexes above where the player moved to) along with the lightning. I did try to add halo= and image= to remove_item but those didn't work. I even tried to spell out the remove halo path and wrote multiple remove_item with the expanded -[1~4].png part. No luck.
Switching the [item] from halo to image broke the lightning effect for me.

Edit: ok, this seems to fix it. I left out the :100 part in my previous attempts.
The name=lightning_image line is superfluous.

Code: Select all

[remove_item]
    x,y={X},$({Y}-2)
    name=lightning_image
    image=halo/lightning-bolt-$random_lightning|-[1~4].png:100
[/remove_item]
User avatar
MoonyDragon
Posts: 149
Joined: November 29th, 2017, 5:46 pm

Re: Animation of storm

Post by MoonyDragon »

vghetto wrote: February 17th, 2020, 5:04 am I'm not sure how you concluded that this exists only in 1.15.2+dev? I used 1.14.9 and it happened with that.
Yes, the addition of the x,y will not remove all other images, but it will remove all images occupying that hex (which is 2 hexes above where the player moved to) along with the lightning. I did try to add halo= and image= to remove_item but those didn't work. I even tried to spell out the remove halo path and wrote multiple remove_item with the expanded -[1~4].png part. No luck.
Switching the [item] from halo to image broke the lightning effect for me.

Edit: ok, this seems to fix it. I left out the :100 part in my previous attempts.
The name=lightning_image line is superfluous.

Code: Select all

[remove_item]
    x,y={X},$({Y}-2)
    name=lightning_image
    image=halo/lightning-bolt-$random_lightning|-[1~4].png:100
[/remove_item]
You are absolutely correct. I used the versions 1.14.9 and 1.15.2 without ever noticing such a bug. In this regard, I first heard of it from you :lol:
Doofus-01 reported to play on 1.15.2+dev when reporting this bug, so I assumed (since I used 1.15.2 in total ignorance of it) that it was restricted to this version.
Concerning the code itself, I will update it to include your (bug-proof) solution.
Default L0 Era - Level 1 leaders with level 0 recruits!
Post Reply