Add new recruitable unit with an object

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
lhybrideur
Posts: 369
Joined: July 9th, 2019, 1:46 pm

Add new recruitable unit with an object

Post by lhybrideur »

Hi everyone,
here is what I am trying to do.
I want to have one object on the map that when picked up allows the side to recruit a new unit type.
Here is what I would like to do:

Code: Select all

[object]
	name= _ "Intuitive Encyclopedia of Elementals"
	[effect]
		apply_to=???
		[allow_recruit]
			side=unit.side
			type=Vine Beast
		[/allow_recruit
	[/effect]
[/object]
Here is what I am currently doing (not tested)

Code: Select all

[object]
	name= _ "Intuitive Encyclopedia of Elementals"
	[effect]
		apply_to=new_ability
		[abilities]
			{ABILITY_BEGINNER_ELEMENTALIST}
		[/abilities]
	[/effect]
	description="Allow to recruit Vine Beasts"
[/object]
#define ABILITY_BEGINNER_ELEMENTALIST
[dummy]
	id=beginner_elementalist
	name= _ "beginner elementalist"
	description= _ "Allow to recruit Vine Beasts."
[/dummy]
#enddef
[event]
	name=turn refresh
	first_time_only=no
	[allow_recruit]
		[has_unit]
			ability=beginner_elementalist
		[/has_unit]
		type=Vine Beast
	[/allow_recruit]
[/event]
Do you have anything more simple that what I am currently doing?

EDIT: corrected the event. It is now working
Last edited by lhybrideur on July 27th, 2022, 6:45 pm, edited 2 times in total.
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2357
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: Add new recruit unit with an object

Post by Lord-Knightmare »

just using `[allow_recruit]` if gotten item. Unless you want to this to be just temporary (as in, would go away if you lose this unit)
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
User avatar
Celtic_Minstrel
Developer
Posts: 2195
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Add new recruitable unit with an object

Post by Celtic_Minstrel »

Is the idea that this book is an item that can be lost, or even given to another unit?

If so, I think the best approach would be to use a custom effect that gives the unit canrecruit=yes and extra_recruit=Vine Beast. You need some Lua setup to support it, but your WML would end up looking something like this:

Code: Select all

[object]
	name= _ "Intuitive Encyclopedia of Elementals"
	[effect]
		apply_to=allow_recruit
		type=Vine Beast
	[/effect]
[/object]
Basing it on extra_recruit means the unit who has the book would need to stand on a keep in order to recruit a Vine Beast. It'll also be able to recruit any other units that the side can recruit, though, which may be undesirable?
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
Ravana
Forum Moderator
Posts: 2997
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Add new recruitable unit with an object

Post by Ravana »

Code: Select all

[object]
	name= _ "Intuitive Encyclopedia of Elementals"
[/object]
[allow_recruit]
	side=$unit.side
	type=Vine Beast
[/allow_recruit
[object] to show message, but [allow_recruit] is usual actionWML and should not be inside.
User avatar
lhybrideur
Posts: 369
Joined: July 9th, 2019, 1:46 pm

Re: Add new recruitable unit with an object

Post by lhybrideur »

Thank to all of you for your answers
Lord-Knightmare wrote: July 27th, 2022, 6:10 pm
I am not sure if it is what you meant, but I think using

Code: Select all

[object]
	name= _ "Intuitive Encyclopedia of Elementals"
	[then]
		[allow_recruit]
			side=1
			type=Vine Beast
		[/allow_recruit]
	[/then]
	description="Allow to recruit Vine Beasts"
[/object]
should work.
I will try that asap.
Celtic_Minstrel wrote: July 29th, 2022, 12:29 am
If my idea does not work, I would like to try yours, but I have no idea how to write that in lua. Do you know if there is an example of custom apply_to in a campaign?

EDIT: my bit of code seems to work
Last edited by lhybrideur on July 29th, 2022, 6:52 pm, edited 1 time in total.
User avatar
Celtic_Minstrel
Developer
Posts: 2195
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Add new recruitable unit with an object

Post by Celtic_Minstrel »

To be clear, this is an example of a custom apply_to written in Lua. There are also several examples in the effects.lua file, which is also part of World Conquest.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply