Check units current 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.
Check units current defense
I want to have an unit with an ability to attack units over a larger range. I've already figured out how to use [set_menu_item] with [harm_unit] to do (nearly) what I want.
The thing is, it currently hits 100% of the time and I want it to act like a normal attack (hit at a chance specified by the terrain the defender is standing on).
Is there a way to access the defending units current defense?
If not, does any other way exist how I could achieve this?
Also, is it possible to check if the defender is invisible?
If it helps, here is my current code
what it does right now is:
store attacking unit, when selected (or moved)
when you right click on the unit you want to attack it checks if the attacking unit is in range
if it is in range you can click a "fire arrow" button. This deals the defender a preset ammount of pierce damage
The attacking unit looses all it's movement and both units get exp (like in a normal attack).
The thing is, it currently hits 100% of the time and I want it to act like a normal attack (hit at a chance specified by the terrain the defender is standing on).
Is there a way to access the defending units current defense?
If not, does any other way exist how I could achieve this?
Also, is it possible to check if the defender is invisible?
If it helps, here is my current code
Code: Select all
#define VR_RANGE_MENU_ITEM DAMAGE
#event: select ballista -> store ballista
[event]
id=vr_select_range_ab
name= select,moveto
first_time_only=no
[filter]
side=$side_number
ability=vr_range
[filter_wml]
attacks_left=1
[/filter_wml]
[/filter]
[store_unit]
variable=vr_ballista_unit
[filter]
x,y=$x1,$y1
[/filter]
[/store_unit]
[/event]
[set_menu_item]
id=vr_range_menu
description="Fire arrow"
[show_if]
[have_unit]
[not]
side=$side_number
[/not]
x,y=$x1,$y1
[filter_owner]
[enemy_of]
side=$side_number
[/enemy_of]
[/filter_owner]
[/have_unit]
[and]
[have_location]
[and]
x,y=$x1,$y1
radius=2
[/and]
[and]
[filter]
find_in=vr_ballista_unit
side=$side_number
[filter_wml]
attacks_left=1
[/filter_wml]
[/filter]
[/and]
[/have_location]
[/and]
[/show_if]
[command]
{VR_EASY_SET_VARIABLES vr_ballista_unit.attacks_left 0 value}
{VR_EASY_SET_VARIABLES vr_ballista_unit.moves 0 value}
[unstore_unit]
variable=vr_ballista_unit
find_vacant=no
[/unstore_unit]
#hits 100%
[harm_unit]
[filter]
x,y=$x1,$y1
[/filter]
[filter_second]
find_in=vr_ballista_unit
[/filter_second]
amount= {DAMAGE}
damage_type=pierce
animate=yes
experience=yes
fire_event=yes
[primary_attack]
name=longshot
[/primary_attack]
[/harm_unit]
{CLEAR_VARIABLE vr_ballista_unit}
[/command]
[/set_menu_item]
#enddef
store attacking unit, when selected (or moved)
when you right click on the unit you want to attack it checks if the attacking unit is in range
if it is in range you can click a "fire arrow" button. This deals the defender a preset ammount of pierce damage
The attacking unit looses all it's movement and both units get exp (like in a normal attack).
Re: Check units current defense
do you use wensoth 1.12 or 1.13 ?
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
Re: Check units current defense
Doable with Lua https://github.com/ProditorMagnus/Agele ... er.cfg#L81
There was discussion about making it visible from WML, but not sure if anything happened there.
There was discussion about making it visible from WML, but not sure if anything happened there.
Re: Check units current defense
1.12gfgtdf wrote:do you use wensoth 1.12 or 1.13 ?
Thank you, I'll have a look at it. I'm not really good with Lua though.Ravana wrote:Doable with Lua https://github.com/ProditorMagnus/Agele ... er.cfg#L81
There was discussion about making it visible from WML, but not sure if anything happened there.
Would be great if it will be implemented for WML.
Re: Check units current defense
Seconded. I was also trying to do this recently.Would be great if it will be implemented for WML.
Maintainer of the Imperial Era and the campaigns Dreams of Urduk, Epic of Vaniyera, Up from Slavery, Fall of Silvium, Alfhelm the Wise and Gali's Contract.
But perhaps 'maintainer' is too strong a word.
But perhaps 'maintainer' is too strong a word.
Re: Check units current defense
note that your code which uses a select event to store data isn't mp safe and will casue OOS in when used in multiplayer. ow to fix this is unfortunateley differnt betwen 1.12 and 1.13:
for 1.12: add needs_select=yes, there are still some corner cases where this wont worn correctly though.
for 1.13: sync manually by using [sync_variable]
EDIT:
somehwere in a preload event and you have a [store_unit_defense] tag that takes id=, loc_y=, loc_x= and a variable= keys.
EDIT2: you prbabyl shodul name it differntly and prefix it with your addon abbivation to prevent naming clashes.
for 1.12: add needs_select=yes, there are still some corner cases where this wont worn correctly though.
for 1.13: sync manually by using [sync_variable]
EDIT:
creating a wml tag that does this for your is quire easy, just addVyncyn wrote:Would be great if it will be implemented for WML.
Code: Select all
[lua]
code = <<
function wesnoth.wml_actions.store_unit_defense(cfg)
local u = wesnoth.get_units(cfg)[1]
local def = wesnoth.unit_defense(u, wesnoth.get_terrain(cfg.loc_x, cfg.loc_y))
wesnoth.set_variable(cfg.variable or "terrain_defense", def)
end
>>
[/lua]
EDIT2: you prbabyl shodul name it differntly and prefix it with your addon abbivation to prevent naming clashes.
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
Re: Check units current defense
Sorry, I don't understand this. I put this code in the cfg file
and added {VR_LUA_BALLISTA_RANGE} to the [era] and this code
in the [command] tags. Now all it does it give my this error
Code: Select all
#define VR_LUA_BALLISTA_RANGE
[event]
id=vr_lua
name= preload
first_time_only=no
[lua]
code = <<
function wesnoth.wml_actions.store_unit_defense(cfg)
local u = wesnoth.get_units(cfg)[1]
local def = wesnoth.unit_defense(u, wesnoth.get_terrain(cfg.loc_x, cfg.loc_y))
wesnoth.set_variable(cfg.variable or "terrain_defense", def)
end
>>
[/lua]
[/event]
#enddef
Code: Select all
[store_unit_defense]
id=vr_ballista_defender_defense_id
loc_x=$x1
loc_y=$y1
variable=vr_ballista_defender_defense_var
[/store_unit_defense]
Re: Check units current defense
Means your filter doesnt match any unit.
Re: Check units current defense
Ok thanks.Ravana wrote:Means your filter doesnt match any unit.
I got rid of the error, but It still doesn't work. How do I access the value of the stored defense?
Re: Check units current defense
This code creates normal wml variable, so with $.
Re: Check units current defense
Totally forgot that. Everything seems to work now, thanks.
Edit: Or not. For some reason it uses the defense the attacker would have if he stands on the defenders terrain or something like that.
Edit: Or not. For some reason it uses the defense the attacker would have if he stands on the defenders terrain or something like that.
Re: Check units current defense
Instead of using "$x1,$y1", you probably want to use the location of the vr_ballista_defender.Vyncyn wrote:For some reason it uses the defense the attacker would have if he stands on the defenders terrain or something like that.
http://www.wesnoth.org/wiki/User:Sapient... "Looks like your skills saved us again. Uh, well at least, they saved Soarin's apple pie."
Re: Check units current defense
But $x1,$y1 should be the location of the defender. After all it's the same location as I have in [harm_unit]. I wouldn't know how to access the location otherwise.
Re: Check units current defense
Make sure you are not confused by
(Note: it is a WML defense. So the higher it is, the weaker the unit is.)
Re: Check units current defense
I know. I tested the variable with [floating_text] and it seems to depend soley on where the defending unit is standig, not on their actual defense.
e.g I had a ship with 10% defense, a smallfoot unit and a mounted unit and the variable always gave back 40 on castle, 60 on land and 50 on forest; The attacking unit has movement_type=mounted, so I really don't understand where those values come from. Seems like it always uses smallfoot, but why?
e.g I had a ship with 10% defense, a smallfoot unit and a mounted unit and the variable always gave back 40 on castle, 60 on land and 50 on forest; The attacking unit has movement_type=mounted, so I really don't understand where those values come from. Seems like it always uses smallfoot, but why?