Random unit image

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
Andrzej127
Posts: 23
Joined: July 26th, 2019, 4:10 pm

Random unit image

Post by Andrzej127 »

Hello. I want to have an unit which have normal image in recruitment window and a random image when recruited. How can I do it?
Shiki
Developer
Posts: 348
Joined: July 13th, 2015, 9:53 pm
Location: Germany

Re: Random unit image

Post by Shiki »

I once made considerations in that direction. I.e. you can recruit a fire elemental, but don't know beforehead which one it will be, asmelee or ranged one.

The way to do it, is that you use a unit placed event, to modify the unit afterwards.
Example code from Era of Myths (the file is units/vampires/x2_Succubus.cfg):

Code: Select all

    [event]
        name=recruit # better: unit placed
        id=transform Succubus # an Id is needed, if the event is part of the [unit_type]
        first_time_only=no

        # This code was used to recruit a variation for another type.
        # You can leave this out.
        [modify_unit]
            [filter]
                type=EOM_Succubus
                x,y=$x1,$y1
            [/filter]
            variation=aristocrat
            # image= …
        [/modify_unit]

        # Using transform_unit avoids glitches,
        # in difference to using the advance unit macro
        [transform_unit]
            type=EOM_Succubus
            x,y=$x1,$y1
            transform_to=EOM_Noble
        [/transform_unit]

        # In case the new unit has more HP than the old one
        [heal_unit]
            [filter]
                type=EOM_Succubus
                x,y=$x1,$y1
            [/filter]
            amount=full
            restore_statuses=no
        [/heal_unit]
    [/event]
In short:
- create a unit_type which (only) serves for recruitment. This unit will be accessible in the help, and it stats will be shown there, so it should have the same.
- give it hide_help=yes and do_not_list=yes. The help page can still be accessed from the recruit window though.
- add the [event] above into the unit_type. (The event need to have an ID.)

- have a second unit type — or make it a [variation] of the same type — which has the same stats and the images/animations you like.

In your case:
- it will be enough to only change the image via modify_unit (as long as no animations are involved)
Try out the dark board theme.
Post Reply