Random unit image

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
Posts: 4
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?

Posts: 289
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

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

        # This code was used to recruit a variation for another type.
        # You can leave this out.
            # image= …

        # Using transform_unit avoids glitches,
        # in difference to using the advance unit macro

        # In case the new unit has more HP than the old one
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)

Post Reply