Modify unit's displayed stats

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
The_Gnat
Posts: 2217
Joined: October 10th, 2016, 3:06 am
Contact:

Modify unit's displayed stats

Post by The_Gnat »

This is a rather odd question but I assume it is possible.

It is rather easy to modify a units stats with an [object] and [effect]. But what if you don't want to change the stats, only change the displayed stats.The situation is that I want a unit to have 6MP on water and 4MP on land. But that is not possible because if I set it to 6MP (movement cost water =1, movement cost land = 1.5) That is clearly going to break.

So what I thought is instead I can set 12MP and movement cost water = 2, movement cost land = 3. Then by setting vision = 6 it acts exactly how I want to. However, then the player sees the number 12MP on the unit bar. Which is weird :whistle:

So then I thought all I need is an event that makes the units MP stat display as only 6 instead of 12mp.

This is the stat I want to change:
image.png
image.png (146.97 KiB) Viewed 1030 times
The reason I ask is because I assume it is possible to modify the display because I can add an icon to the menu bar like this:

Code: Select all

[event]
    name=turn refresh
    #first_time_only=no

    [lua]
        code=<<
            local _ = wesnoth.textdomain "wesnoth-ROTL"
            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.ROTLensnared then
                    table.insert(s, { "element", {
                        image = "misc/web-status.png",
                        tooltip = _"ensnared: This unit is ensnared. Ensnared units' defenses are reduced to 10% making them vanurable to enemy attacks. Units remain ensnared for 1 round."
                    } })
                end
                return s
            end
        >>
    [/lua]
[/event]
Here with this code I am able to insert an element into the display table so I assume with some other code (which I currently have no idea about ;) ) I might be able to modify the displayed MP.
User avatar
Ravana
Forum Moderator
Posts: 3002
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: Modify unit's displayed stats

Post by Ravana »

It is not really documented, but wesnoth.theme_items should have all the elements you need.
User avatar
The_Gnat
Posts: 2217
Joined: October 10th, 2016, 3:06 am
Contact:

Re: Modify unit's displayed stats

Post by The_Gnat »

Okay great I will see if I can find out about that!
User avatar
josteph
Inactive Developer
Posts: 741
Joined: August 19th, 2017, 6:58 pm

Re: Modify unit's displayed stats

Post by josteph »

I think you want wesnoth.theme_items.unit_moves and .selected_unit_moves too. See https://github.com/wesnoth/wesnoth/blob ... #L684-L693.
Post Reply