Creating new unit statuses and getting them to show

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.
User avatar
bigkahuna
Posts: 657
Joined: September 11th, 2010, 6:24 pm
Location: In your mind.

Re: Creating new unit statuses and getting them to show

Post by bigkahuna »

I tested it out in a campaign and it doesn't work. Here is how I use it:

Code: Select all

#define POSSESSION
    [event]
	name=preload
	first_time_only=no
	[lua]
	    code=<<
		local _ = wesnoth.textdomain "wesnoth-SR"
		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.possessed then
			table.insert(s, { "element", {
			    image = "misc/waypoint.png",
			    tooltip = _"possessed: This unit has been possessed. It will be temporarily under control of its possessor's side until the magic wears off."
			} })
		    end
		    return s
		end
	    >>
	[/lua]
    [/event]
#enddef
I only use it in one scenario, so I place it toplevel in that scenario. When I access the scenario, I get this error:
stderr.txt wrote:error scripting/lua: [string "..."]:3: attempt to index field 'theme_items' (a nil value)
stack traceback:
[string "..."]:3: in function 'bytecode'
...L/Desktop/WolfQuest/Wesnoth1.9/data/lua/wml-tags.lua:206: in function 'cmd'
...L/Desktop/WolfQuest/Wesnoth1.9/data/lua/wml-tags.lua:220: in function <...L/Desktop/WolfQuest/Wesnoth1.9/data/lua/wml-tags.lua:213>
I checked, and I'm calling it right and everything... Does anyone have any ideas of the problem?
Check out my campaign Sweet Revenge!
Join the new R2D forum!
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Creating new unit statuses and getting them to show

Post by Anonymissimus »

Apparently your BfW version isn't new enough. You need 1.9.4 or greater. wesnoth.theme_items isn't nil for me.
EDIT
Perhaps you need even 1.9.5, the theme_items proxy table wasn't created immediately.
EDIT2
Well, no, 1.9.4 must be sufficient.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
Elvish_Hunter
Posts: 1576
Joined: September 4th, 2009, 2:39 pm
Location: Lintanir Forest...

Re: Creating new unit statuses and getting them to show

Post by Elvish_Hunter »

A sort-of thread necromancy... :twisted:
In the first post of this topic, silene said that the code to show the status icon should be placed in a preload event. This has the disadvantage to require modifying every scenario where you need to display your custom status.
In trunk, commits [rev]55393[/rev] and [rev]55394[/rev], I added support for stunned status icon in Dead Water and Under the Burning Suns. However, the approach that I used is different: instead of modifying every scenario, I added a [lua] tag directly in the _main.cfg, guarded by the campaign's #ifdef.
This is the code now available in DW's _main.cfg:

Code: Select all

[lua]
    code=<<	
	local _ = wesnoth.textdomain "wesnoth-dw"
	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.stunned then
			table.insert(s, { "element",  { image = "misc/stunned-status-icon.png",
			                                tooltip = _"stunned: This unit is stunned. It cannot enforce its Zone of Control."
			} } )
		end
		
		return s
	end
	>>
[/lua]
At least for single player campaigns, there is this alternative way that does not require modifying every scenario.
Current maintainer of these add-ons, all on 1.16:
The Sojournings of Grog, Children of Dragons, A Rough Life, Wesnoth Lua Pack, The White Troll (co-author)
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Creating new unit statuses and getting them to show

Post by Dugi »

Is there a way to make these statuses also colourise the units like poison and slow does? It is quite annoying to do it with [objects] with image_mod.
User avatar
Azeal
Posts: 97
Joined: July 24th, 2012, 8:19 am

Re: Creating new unit statuses and getting them to show

Post by Azeal »

I have a problem with the icons. When I use an icon for a status (made the same size as the poison and slows icon) the game seems to stretch the image. How can I fix this?
Post Reply