Force rebuild a unit
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.
Force rebuild a unit
Hi,
Is there a way of force rebuilding a unit from it's base type?
Is there a way of force rebuilding a unit from it's base type?
Re: Force rebuild a unit
Simple: kill it and spawn the unit again.
Code: Select all
[kill]
id=unit
[/kill]
[unit]
id=Unit
name=_"Unit"
type=Unit
x,y=$x1,$y1
[/unit]
The future belongs to those, who believe in the beauty of their dreams.
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
Developer of: Trapped, Five Fates, Strange Legacy, Epical, UR Epic Era
Dungeonmasters of Wesnoth, Wild Peasants vs Devouring Corpses, Dwarf Dwarfson Dwarvenminer
Re: Force rebuild a unit
That's not what I was after. My question was unclear.
I don't want a fresh unit, I want the current modifications+amlas minus some [object]
The object might affect attack, abilities, resistance ....
So I want to remove that object manually and then force rebuild the unit, so any effects that the object might have applied to be removed.
I don't want a fresh unit, I want the current modifications+amlas minus some [object]
The object might affect attack, abilities, resistance ....
So I want to remove that object manually and then force rebuild the unit, so any effects that the object might have applied to be removed.
- Lord-Knightmare
- Discord Moderator
- Posts: 2360
- 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: Force rebuild a unit
https://wiki.wesnoth.org/LuaWML/Units#w ... ificationsvghetto wrote: ↑June 23rd, 2021, 7:05 pm That's not what I was after. My question was unclear.
I don't want a fresh unit, I want the current modifications+amlas minus some [object]
The object might affect attack, abilities, resistance ....
So I want to remove that object manually and then force rebuild the unit, so any effects that the object might have applied to be removed.
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
Re: Force rebuild a unit
Thanks, remove_modifications is what I was looking for.
I didn't have an id set for the
That didn't work. I suspect it has something to do with the _ textdomain thingy.
Anyone knows why the lua snippet above did not work?
Eventually I bit the bullet and added an id to the objects and used vanilla [remove_object]. That did the job.
I didn't have an id set for the
[object]
s so I tried to remove them by name instead with the following:Code: Select all
function wesnoth.wml_actions.remove_object_name(cfg)
local obj_id = cfg.object_name
for _,unit in ipairs(wesnoth.get_units(cfg)) do
wesnoth.remove_modifications(unit, {name = obj_id}, "object")
end
end
name=_"Some Object"
Anyone knows why the lua snippet above did not work?
Eventually I bit the bullet and added an id to the objects and used vanilla [remove_object]. That did the job.
- Celtic_Minstrel
- Developer
- Posts: 2209
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Force rebuild a unit
If object_name is a translatable string, that's not a good choice to match the object by. You should match on something that's not translatable. That said, my understanding is that it should have worked, so I'm not sure what went wrong. If there's an issue, it's in the WML filters themselves, because I tried the following code and it also didn't match:
It matches if the underscores are removed, of course.
Code: Select all
local _ = wesnoth.textdomain "wesnoth"
print(wml.matches_filter({foo = _'bar', bar = 'foo'}, {foo = _'bar'}))
Re: Force rebuild a unit
The object name in WML was like so
I did std_print on object_name and the output was
The docs say that remove_modifications takes
Maybe using tag.filter_wml or literal, how would I go about transcribing it in lua to look exactly like WML's [filter_wml]?
name=_"Some Object"
I did std_print on object_name and the output was
Some Object
. It was without quotes and without the underscore.The docs say that remove_modifications takes
[filter_wml]
.Maybe using tag.filter_wml or literal, how would I go about transcribing it in lua to look exactly like WML's [filter_wml]?
- Celtic_Minstrel
- Developer
- Posts: 2209
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Force rebuild a unit
The filter in your example code is correct, assuming you had something like this:
But it looks like something in WML filters prevents it from matching translatable strings.
Code: Select all
[remove_object_name]
name=_"Some Object"
[/remove_object_name]