Recruit Units without Castles

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
User avatar
thvk
Posts: 9
Joined: June 25th, 2020, 3:23 pm
Contact:

Recruit Units without Castles

Post by thvk »

Hi all,
I want to recruit units without castles just like in TLU.
What is the easiest way to do this?
Thanks for replies.
Campaigns Im making:
- The Return of the Darks[ unfinished ]

Violent is the last retreat of the ...

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

Re: Recruit Units without Castles

Post by Ravana »

Ultimate circle creates temporary castle around wherever unit moves.

User avatar
thvk
Posts: 9
Joined: June 25th, 2020, 3:23 pm
Contact:

Re: Recruit Units without Castles

Post by thvk »

Thats not what i want. I would prefer recruiting like the heavy summoner.
Campaigns Im making:
- The Return of the Darks[ unfinished ]

Violent is the last retreat of the ...

User avatar
beetlenaut
Developer
Posts: 2475
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Recruit Units without Castles

Post by beetlenaut »

Why don't you look at the code for the heavy summoner and see how it's done?
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide

User avatar
thvk
Posts: 9
Joined: June 25th, 2020, 3:23 pm
Contact:

Re: Recruit Units without Castles

Post by thvk »

Thank you for the reply.
But the Code looks very complicate to me. Maybe you can explain me how it works?

User avatar
beetlenaut
Developer
Posts: 2475
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Recruit Units without Castles

Post by beetlenaut »

OK, I looked at it, and that's a valid point.

Here is the important macro definition. I removed the unnecessary lines, so it's much easier to understand now. You can put this in a file in your utils folder or at the beginning of your scenario file.

Code: Select all

#define RECRUIT_MENU_ITEM DESCRIPTION COST UNIT
    [set_menu_item]
        id={DESCRIPTION} + "_menu_item"
        description={DESCRIPTION}+" - "+ _ "gold:"+" "+{COST}
        [filter_location]
            [filter_adjacent_location]
                [filter]
                    canrecruit=yes
                    side=$side_number
                [/filter]
            [/filter_adjacent_location]
        [/filter_location]
        [command]
            [store_gold]
                variable=actual_gold
                side=$side_number
            [/store_gold]
            [if]
		    [variable]
		        name=actual_gold
		        greater_than_equal_to={COST}
		    [/variable]
                [then]
                    [gold]
                        amount=-{COST}
                        side=$side_number
                    [/gold]
                    [unit]
                        type={UNIT}
                        side=$side_number
                        x,y=$x1,$y1
                        moves=0
                        animate=yes
                    [/unit]
                    {MODIFY_UNIT x,y=$x1,$y1 attacks_left 0}
                    {MODIFY_UNIT x,y=$x1,$y1 moves 0}
                [/then]
                [else]
                    [message]
                        speaker=narrator
                        side_for=$side_number
                        message= _ "I have insufficient gold. I am unable to summon."
                        image=wesnoth-icon.png
                    [/message]
                [/else]
            [/if]    
            {CLEAR_VARIABLE actual_gold}
        [/command]
    [/set_menu_item]
#enddef
This is an example of how you use it in a scenario.

Code: Select all

[event]
	name=prestart
	{RECRUIT_MENU_ITEM (Recruit a fighter) 14 (Elvish Fighter)}
[/event]
Put it in your code without changes, and make sure it works. If it works, then you can slowly modify it to make it work how you actually want. If you ask us for help, it's good to have a specific question.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide

User avatar
thvk
Posts: 9
Joined: June 25th, 2020, 3:23 pm
Contact:

Re: Recruit Units without Castles

Post by thvk »

Thank you. This is a very good help to me.

Post Reply