How do I add abilities to individual units?

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
Ringcaat
Posts: 68
Joined: August 21st, 2004, 11:54 am
Location: Minneapolis, Minnesota
Contact:

How do I add abilities to individual units?

Post by Ringcaat »

I'd like to create an object that gives units the 'teleport' ability. I've looked through the Wiki, the utils.cfg file, and a saved game file, but I'm still at a loss. It's worth noting that the Wiki page on the [unit] tag (for unit types) doesn't include the [abilities] tag that I see being used, only an 'abilities' key.

I know how I can change some variable of a unit defined with a key, like its hitpoints, movement, or side. But how do I change something defined in a tag?
This is a young gryphon. She likes cheese. She will steal all your cheese.
User avatar
JW
Posts: 5047
Joined: November 10th, 2005, 7:06 am
Location: Chicago-ish, Illinois

Post by JW »

There used to be a user scenario where you teleported to different islands to collect things like that, but I haven't seen it in months. Hopefully zookeeper, EP, toms, et al can help you out on this one soon.
scott
Posts: 5248
Joined: May 12th, 2004, 12:35 am
Location: San Pedro, CA

Re: How do I add abilities to individual units?

Post by scott »

Ringcaat wrote:I'd like to create an object that gives units the 'teleport' ability. I've looked through the Wiki, the utils.cfg file, and a saved game file, but I'm still at a loss. It's worth noting that the Wiki page on the [unit] tag (for unit types) doesn't include the [abilities] tag that I see being used, only an 'abilities' key.

I know how I can change some variable of a unit defined with a key, like its hitpoints, movement, or side. But how do I change something defined in a tag?
You might be able to store the unit and do it manually.
1. In a normal scenario, store a Silver Mage and save the game
2. Examine the save file to find the variable of the stored unit. Note how the ability is stored.
3. Look at the Random Campaign on the 1.0 server for an example of how to add tags with keys to a stored variable (in this case he added traits instead of abilities).
4. Attempt to modify the stored-unit-tag-adding-technique you learned in step 3 to add the ability data structure you found in step 2. The result should be a series of {VARIABLE} macros that build up the tag and its keys one-by-one.
5. Apply the technique to some unit in-game. Don't forget to unstore the unit.
Hope springs eternal.
Wesnoth acronym guide.
User avatar
Sapient
Inactive Developer
Posts: 4453
Joined: November 26th, 2005, 7:41 am
Contact:

Post by Sapient »

dont forget...
6. Update the wiki 8)

(nice tip though)
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Rhuvaen
Inactive Developer
Posts: 1272
Joined: August 27th, 2004, 8:05 am
Location: Berlin, Germany

Post by Rhuvaen »

I used to simply store the unit, and then clone a new one, adding any tags that I needed, in your case something like:

Code: Select all

     [store_unit]
       variable=leader
       kill=yes
       [filter]
          side=1
       [/filter]
     [/store_unit]
     [unit]
       description=$leader.description
       type=$leader.type
       x=$leader.x
       y=$leader.y
       side=$leader.side
       canrecruit=1
       [abilities]
         [teleport]
            any_old_key=1
         [/teleport]
       [/abilities]
     [/unit]
Now this didn't work at all. :? Don't really know why...

But then I tried setting a variable directly, like this:

Code: Select all

    [store_unit]
       variable=leader
       kill=yes
       [filter]
          side=1
       [/filter]
     [/store_unit]
     [set_variable]
       name=leader.abilities.teleport.any_old_key
       value=1
     [/set_variable]
     [unstore_unit]
       variable=leader
     [/unstore_unit]
... and it worked! The teleport ability isn't displayed, I guess you need extra WML to do that, but the unit ends up being able to teleport.

Now, if only one could specify the terrain type used for teleporting, that would be really neat!

So my guess is that the teleport tag just gets created automatically when you set a key within it as a variable.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper »

Rhuvaen wrote:So my guess is that the teleport tag just gets created automatically when you set a key within it as a variable.
That is correct. As was said earlier, you can (and probably need to) build the teleport tag key by key (and in this case, all you need are the name and description keys, and even those are just so that the ability name and description are visible to the player).

If the ability however isn't displayed on the unit (in the right panel, etc) correctly, as someone mentioned, even when you add the right name and description keys to the [teleport] tag, then that should be considered a bug.
Rhuvaen
Inactive Developer
Posts: 1272
Joined: August 27th, 2004, 8:05 am
Location: Berlin, Germany

Post by Rhuvaen »

zookeeper wrote:If the ability however isn't displayed on the unit (in the right panel, etc) correctly, as someone mentioned, even when you add the right name and description keys to the [teleport] tag, then that should be considered a bug.
Well when I use those magic keys (which I had no clue about :)), the ability indeed is displayed in the panel on the right side. Wonderful - it'll be simple to distribute custom abilities across network games, for instance!
Swordy
Posts: 110
Joined: June 10th, 2005, 8:38 am

Post by Swordy »

You'd need to put in the descriptions manually :lol:
Which also means you can put in your own description :)

Code: Select all

[store_unit] 
variable=teleport_store
[filter] 
side=1
[/filter] 
[/store_unit]
{VARIABLE teleport_store.abilities[0].teleport[0].name ( _ "teleport")}
{VARIABLE teleport_store.abilities[0].teleport[0].description ( _ "Teleport:
This unit may teleport between any two friendly villages using one of its moves.")}
[unstore_unit]
variable=teleport_store
[/unstore_unit]
But what I really like is the customizable 'ambush' ability... you can make a unit hide in villages (for example), instead of forests :)
Ringcaat
Posts: 68
Joined: August 21st, 2004, 11:54 am
Location: Minneapolis, Minnesota
Contact:

Post by Ringcaat »

Thanks, all, this looks doable. :)
This is a young gryphon. She likes cheese. She will steal all your cheese.
wulf
Posts: 19
Joined: June 30th, 2005, 12:38 pm

Post by wulf »

i wanted to make a white mage become steadfast in a MP Quest
(see http://www.wesnoth.org/forum/viewtopic.php?t=11974).

this did not work:

Code: Select all

[set_variable]
       name=leader.abilities.steadfast.any_old_key
       value=1
[/set_variable]

i tried something like this, cause a white mage has allready a special ability:

Code: Select all

[set_variable]
       name=leader.abilities[1].steadfast[1].any_old_key
       value=1
[/set_variable]
various modification of this did not work either.

giving the mage the ability ambush seems to work.
question: is steadfast no ability?
no borders, no nation
Rhuvaen
Inactive Developer
Posts: 1272
Joined: August 27th, 2004, 8:05 am
Location: Berlin, Germany

Post by Rhuvaen »

wulf wrote:i wanted to make a white mage become steadfast in a MP Quest
(see http://www.wesnoth.org/forum/viewtopic.php?t=11974).
question: is steadfast no ability?
Yes, steadfast is a variation of the resistance effect. Check out the macro in abilities.cfg:

Code: Select all

#define ABILITY_STEADFAST
	[resistance]
		id=steadfast
		multiply=2
		max_value=50
		apply_to=blade,pierce,impact,fire,cold,holy
		[filter_base_value]
			greater_than=0
		[/filter_base_value]
		name= _ "steadfast"
		description= _ "Steadfast:
This unit's resistances are doubled, up to a maximum of 50%, when defending. Vulnerabilities are not affected."
		affect_self=yes
		active_on=defense
	[/resistance]
#enddef
So you need to add a "resistance" ability with all those elements. :D
Post Reply