[store_unit_defense]
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.
- Argesilao2
- Posts: 113
- Joined: February 18th, 2020, 9:28 pm
- Location: Piciule Patrie
[store_unit_defense]
How it works exactly the tag [store_unit_defense] in 1.15.6, if it works?
Please, don't send me to the wiki page; A simple example that works is welcome.
if the tag doesn't work, it's better to indicate it, or to remove the tag from the wiki page, or change the instructions; someone could waste hours trying to make it work.
Thank you!
Please, don't send me to the wiki page; A simple example that works is welcome.
if the tag doesn't work, it's better to indicate it, or to remove the tag from the wiki page, or change the instructions; someone could waste hours trying to make it work.
Thank you!
Re: [store_unit_defense]
I've just tried to write a unit test for it, and think it's had a typo in it since 1.15.3.
Re: [store_unit_defense]
store_unit_defense seems broken in 1.15. Might want to open a github ticket for it.
It works on 1.14
It works on 1.14
Code: Select all
[event]
name=moveto
first_time_only=no
[filter]
side=1
[/filter]
[store_unit_defense]
x,y=$x1,$y1
loc_x,loc_y=$x1,$y1
variable=mydefense
[/store_unit_defense]
[message]
speaker=unit
message=_"My defense is $mydefense|"
[/message]
#{CLEAR_VARIABLE mydefense}
[/event]
Re: [store_unit_defense]
Bugfix and example/unit test: #5246
- Argesilao2
- Posts: 113
- Joined: February 18th, 2020, 9:28 pm
- Location: Piciule Patrie
Re: [store_unit_defense]
@vghetto: thanks for the attemps, but I'm writing a campaign for the 1.15 version, and it doesn't work.
@octalot: well, at least now I know that I can't use this tag. I'll try something different; thanks for the warning.
@octalot: well, at least now I know that I can't use this tag. I'll try something different; thanks for the warning.
Re: [store_unit_defense]
Are you trying to check the unit's defense on a particular tile, or are you trying to check its defense on a particular terrain type?
I had some ideas, and I've now actually written up some little code samples, so you don't have to answer that question after all. Except inside your own head.
Inside any StandardUnitFilter (that's what you write in the [filter] section of an event, or to specify who dies inside a [kill] tag, or whatever) you can write
Here's another sample event. This version can be used in more places, but it only tells you about the unit's movetype. It doesn't actually process to tell you what defense the unit gets on its current tile. (Note that the complicated-looking equation,
If you do this one, let me give you a quote from the wiki:
If the unit has no defined defense on that terrain, it will just show a blank. For example, if you tweaked my example, you might get something like this:
I had some ideas, and I've now actually written up some little code samples, so you don't have to answer that question after all. Except inside your own head.
Inside any StandardUnitFilter (that's what you write in the [filter] section of an event, or to specify who dies inside a [kill] tag, or whatever) you can write
defense=
to filter based on what terrain defense the unit has on the tile that it is standing on at the time. This uses the "backwards" definition of defense that the movetypes do, where the "defense" value is actually how likely a unit is to get hit, rather than how likely he is to dodge. Here's a little example.
Code: Select all
[event]
name=moveto
[filter]
side=1
defense=70,80,90 # The event will fire if the unit is on side 1 and the unit's defense is any of these values.
[/filter]
[message]
speaker=unit
message= _ "This terrain is terrible! Couldn't you find me a nice, defensible spot?"
[/message]
[/event]
$(100 - $unit.defense.shallow_water|)
, is to convert it into the format most casual Wesnoth players will expect. Just like the other one, if $unit.defense.shallow_water|
is a large number, the unit is likely to be hurt while standing there.)
Code: Select all
[event]
name=moveto
[filter]
side=1
[/filter]
[message]
speaker=unit
message= _ "I have $(100 - $unit.defense.shallow_water|)% defense in shallow water. Keep that in mind when I reach the river."
[/message]
[/event]
There are a couple other things that may also come up when using thehttps://wiki.wesnoth.org/UnitsWML#.5Bmovetype.5D wrote: Default keys for the [movement_costs], [vision_costs], and [defense] tags are deep_water, shallow_water, reef, swamp_water, flat, sand, forest, hills, mountains, village, castle, cave, frozen, unwalkable, fungus, and impassable.
$unit.defense.terrain|
version:If the unit has no defined defense on that terrain, it will just show a blank. For example, if you tweaked my example, you might get something like this:
Certain units have negative defense values. For example, the horseman's says "-70". A negative defense value means that if the unit is on that terrain, the defense can never be better. A horseman has 40% defense on flat terrain, so you would expect him to have 40% on forest (which usually takes the better of the two terrain defense values), but he actually has 30% because of that "-" in the terrain defense section of his movetype. If you have any situations where it might become relevant, you should take this into account.A Wesnoth Unit wrote: I have % defense in impassable.
- Argesilao2
- Posts: 113
- Joined: February 18th, 2020, 9:28 pm
- Location: Piciule Patrie
Re: [store_unit_defense]
I was ignorant of this possibility; It will allow me to solve my problem with ease.Pilauli wrote: ↑October 27th, 2020, 8:16 pm Inside any StandardUnitFilter (that's what you write in the [filter] section of an event, or to specify who dies inside a [kill] tag, or whatever) you can writedefense=
to filter based on what terrain defense the unit has on the tile that it is standing on at the time.
Thank you very much.