Creating new unit statuses and getting them to show
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.
Creating new unit statuses and getting them to show
It has been mentioned in the Lua changes for 1.9.4, but it might be worth advertising, especially since it doesn't really require any Lua knowledge.
Let's suppose you want to define an "entangled" status (that is, an "entangled=yes" line inside the [status] tag of unit). How do you get it to show up in the sidebar next to the invisible, slowed, poisoned statuses? By copy-pasting the code below in a scenario and modifying its literal strings.
The things to modify above are:
Ever wanted to display the equipment carried by units in the sidebar for a Wesnoth RPG? In 1.9.4, you can.[/advertisement]
Let's suppose you want to define an "entangled" status (that is, an "entangled=yes" line inside the [status] tag of unit). How do you get it to show up in the sidebar next to the invisible, slowed, poisoned statuses? By copy-pasting the code below in a scenario and modifying its literal strings.
Code: Select all
[event]
name=preload
first_time_only=no
[lua]
code=<<
local _ = wesnoth.textdomain "mydomain"
local old_unit_status = wesnoth.theme_items.unit_status
function wesnoth.theme_items.unit_status()
local u = wesnoth.get_displayed_unit()
if not u then return {} end
local s = old_unit_status()
if u.status.entangled then
table.insert(s, { "element", {
image = "entangled.png",
tooltip = _"entangled: This unit is entangled. It cannot move but it can still attack."
} })
end
return s
end
>>
[/lua]
[/event]
- the domain of your addon ("mydomain"), assuming that you are using translations. Otherwise just remove the underscore in the tooltip line.
- the name of the status (u.status.entangled). Note that if the attribute happens to be inside [variables], so be it: u.variables.whatever.
- the path to the image ("entangled.png").
- the tooltip of the status ("entangled: This unit ...").
Ever wanted to display the equipment carried by units in the sidebar for a Wesnoth RPG? In 1.9.4, you can.[/advertisement]
Re: Creating new unit statuses and getting them to show
that's nice, will save some writing in wml to make special images to show a unit status..but can this be used also to simplify defining what that status affects and pershaps a default way of getting rid of it?
That would really cut a few lines off the macro files, when the whole thing left would be to just write the event for applying a status, without tediously repeating all its effects and undoing them one by one in another
That would really cut a few lines off the macro files, when the whole thing left would be to just write the event for applying a status, without tediously repeating all its effects and undoing them one by one in another
Like cats? I've made a whole faction of them to kick ass with!
Don't like cats? I've made a whole faction of them to kick their asses! So everyone's happy :)
Felinian faction is part of the Beyond Southern Hells era
kitties need sprites! art topic here
Don't like cats? I've made a whole faction of them to kick their asses! So everyone's happy :)
Felinian faction is part of the Beyond Southern Hells era
kitties need sprites! art topic here
Re: Creating new unit statuses and getting them to show
Cool. Something I've always wanted.
Re: Creating new unit statuses and getting them to show
Wow This is a really neat feature. One thing I don't understand though -silene wrote:Unit statuses are not the only part of the user interface you can change. Every item tag that appears in data/themes/default.cfg can be modified. And if you are using a custom theme for your addon, you can add whatever theme item you wish and get it to display custom content.
In the above example of Lua, you've given us the needed attributes (fill-in-the-blanks if you will). But if we want to add/alter other themes, how would we find the needed attributes? For example -
When I look in the themes/default.cfg , all I see is this -
Code: Select all
[unit_status]
id=unit-status
font_size={DEFAULT_FONT_SMALL}
ref=unit-xp
rect="=+1,+3,=,+16"
xanchor=right
yanchor=fixed
[/unit_status]
Re: Creating new unit statuses and getting them to show
the status name gets bashed in as a varible..or rather container variable name, and from what i see the image and tooltip somehows are qualities of "element"..just where does this "element" come from?
Like cats? I've made a whole faction of them to kick ass with!
Don't like cats? I've made a whole faction of them to kick their asses! So everyone's happy :)
Felinian faction is part of the Beyond Southern Hells era
kitties need sprites! art topic here
Don't like cats? I've made a whole faction of them to kick their asses! So everyone's happy :)
Felinian faction is part of the Beyond Southern Hells era
kitties need sprites! art topic here
Re: Creating new unit statuses and getting them to show
That's orthogonal. The only thing that was missing for custom statuses was to display them the same way hardcoded ones are; so that's what I added. Everything else could already be done in WML and doesn't require any specific engine support.StDrake wrote:but can this be used also to simplify defining what that status affects and pershaps a default way of getting rid of it?
The .cfg theme files only define which boxes are displayed, what their name is, and where they are displayed. They sometimes also contain static parts of the interface, e.g. the village icon. But they do not define the dynamic content. That was up to the C++ engine, and now to the LuaWML engine too. For instance, display of unit statuses is done by reports.cpp/generate_reports.cpp and its code is similar to the code I posted (except it is C++ instead of Lua).bigkahuna wrote:When I look in the themes/default.cfg , all I see is this and nothing about the image path, tooltips, or name of status. Where are all the other attributes/aspects of the different themes defined? I cannot find it in any of the files.
That's just the way it is called, it doesn't come from anywhere in particular. For instance, assume you have an invisible slowed unit. Then the generator for unit statuses will create the following WML container on-the-fly and the engine will display it:StDrake wrote:the status name gets bashed in as a varible..or rather container variable name, and from what i see the image and tooltip somehows are qualities of "element"..just where does this "element" come from?
Code: Select all
#textdomain wesnoth
[element]
image="misc/invisible.png"
tooltip=_"invisible: "+_"This unit is invisible. It cannot be seen or attacked by enemy units."
[/element]
[element]
image="misc/slowed.png"
tooltip=_"slowed: "+_"This unit has been slowed. It will only deal half its normal damage when attacking and its movement cost is doubled."
[/element]
In the case of the Lua code I posted, the generator just calls the old generator that handles the default status and gets its result (which is a WML container like the one above) then it adds a new [element] tag to it if the unit has the given status. This new result is then returned to the engine, which displays all the elements one after the other in the box defined by the theme.
Re: Creating new unit statuses and getting them to show
Awesome! But...
I already know you can implement your own statuses with their own names from my experiments with A New Land. What I don't understand is how you say what they do.
While I'm on the subject, where do you find the LUA hardcode for specials tags, so you would be able to modify them?
I already know you can implement your own statuses with their own names from my experiments with A New Land. What I don't understand is how you say what they do.
While I'm on the subject, where do you find the LUA hardcode for specials tags, so you would be able to modify them?
"What do you mean, "a dwarvish dragonguard with marksman is overpowered"?"
Story of a Drake Outcast | The Nonsense Era
Played HttT-Underground Channels? Thought it was rubbish? Help us develop it here!
Story of a Drake Outcast | The Nonsense Era
Played HttT-Underground Channels? Thought it was rubbish? Help us develop it here!
Re: Creating new unit statuses and getting them to show
Wouldn't it be better to define a WML tag which does this?silene wrote:It has been mentioned in the Lua changes for 1.9.4, but it might be worth advertising, especially since it doesn't really require any Lua knowledge.
Let's suppose you want to define an "entangled" status (that is, an "entangled=yes" line inside the [status] tag of unit). How do you get it to show up in the sidebar next to the invisible, slowed, poisoned statuses? By copy-pasting the code below in a scenario and modifying its literal strings.The things to modify above are:Code: Select all
[event] name=preload first_time_only=no [lua] code=<< ... >> [/lua] [/event]
- the domain of your addon ("mydomain"), assuming that you are using translations. Otherwise just remove the underscore in the tooltip line.
- the name of the status (u.status.entangled). Note that if the attribute happens to be inside [variables], so be it: u.variables.whatever.
- the path to the image ("entangled.png").
- the tooltip of the status ("entangled: This unit ...").
Maybe usable like this:
Code: Select all
[event]
name=preload
first_time_only=no
[add_status_gui]
variable="u.status.entangled"
image="entangled.png"
tooltip=_ "entangled: This unit is entangled. It cannot move but it can still attack."
[/add_status_gui]
[/event]
Re: Creating new unit statuses and getting them to show
*appear from the shadows*
*disappear into the shadows*
Code: Select all
[lua]
code=<<
local old_unit_status = wesnoth.theme_items.unit_status
function wesnoth.theme_items.unit_status()
local u = wesnoth.get_displayed_unit()
if not u then return {} end
local s = old_unit_status()
if u.status.cfg.status then
table.insert(s, { "element", {
image = "cfg.image",
tooltip = _"cfg.tooltip"
} })
end
return s
end
wesnoth.register_wml_action("add_status_gui", cfg)
>>
[/lua]
Formerly known as the creator of Era of Chaos and maintainer of The Aragwaithi and the Era of Myths.
Re: Creating new unit statuses and getting them to show
Wouldn't that need to be...LightFighter wrote:*appear from the shadows**disappear into the shadows*Code: Select all
[lua] code=<< local old_unit_status = wesnoth.theme_items.unit_status function wesnoth.theme_items.unit_status() local u = wesnoth.get_displayed_unit() if not u then return {} end local s = old_unit_status() if u.status.cfg.status then table.insert(s, { "element", { image = "cfg.image", tooltip = _"cfg.tooltip" } }) end return s end wesnoth.register_wml_action("add_status_gui", cfg) >> [/lua]
Code: Select all
image = cfg.image,
tooltip = cfg.tooltip
You are a Dark Adept: you dimmerse yourself in the dark arts...potentially with great rewards....
-JW's personality quiz
-JW's personality quiz
Re: Creating new unit statuses and getting them to show
Well, the tooltip is supposed to be translateable. And the quotes around them are supposed to be there.Brilliand wrote:Wouldn't that need to be [...]
-
- Inactive Developer
- Posts: 2461
- Joined: August 15th, 2008, 8:46 pm
- Location: Germany
Re: Creating new unit statuses and getting them to show
"cfg.image" is considered a string by lua in any case so it looks for a file named "cfg.image". Brilliand is right.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
A Simple Campaign: campaign draft for wml starters • Plan Your Advancements: mp mod
The Earth's Gut: sp campaign • Settlers of Wesnoth: mp scenario • Wesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
Re: Creating new unit statuses and getting them to show
*facepalm* how could I forget...Anonymissimus wrote:"cfg.image" is considered a string by lua in any case so it looks for a file named "cfg.image". Brilliand is right.
Formerly known as the creator of Era of Chaos and maintainer of The Aragwaithi and the Era of Myths.
Re: Creating new unit statuses and getting them to show
1.9.4 is out! Excited, I looked through the changelog expecting to find this.
I didn't. Is there something I missed, is it a hidden update, or was it forgotten?silene wrote:Ever wanted to display the equipment carried by units in the sidebar for a Wesnoth RPG? In 1.9.4, you can.
Re: Creating new unit statuses and getting them to show
It is in 1.9.4 and mentioned here: http://forums.wesnoth.org/viewtopic.php?f=58&t=31022.bigkahuna wrote:Is there something I missed, is it a hidden update, or was it forgotten?