shadowm

Untitled

Jan 16th, 2013
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.82 KB | None | 0 0
  1. function wesnoth.wml_actions.check_unit_in_range(cfg)
  2.     local primary_suf = helper.get_child(cfg, "filter") or
  3.         helper.wml_error "[check_unit_in_range] missing required [filter] tag"
  4.     local second_suf = helper.get_child(cfg, "filter_second") or
  5.         helper.wml_error "[check_unit_in_range] missing required [filter_second] tag"
  6.     local variable = cfg.variable
  7.  
  8.     if variable == nil then
  9.         variable = "in_range"
  10.     end
  11.  
  12.     local u1 = wesnoth.get_units(primary_suf) or
  13.         helper.wml_error "[check_unit_in_range] could not match primary unit"
  14.     local u2 = wesnoth.get_units(secondary_suf) or
  15.         helper.wml_error "[check_unit_in_range] could not match secondary unit"
  16.  
  17.     if helper.distance_between(u1.x, u1.y, u2.x, u2.y) <= u1.max_moves then
  18.         wesnoth.set_variable(variable, true)
  19.     else
  20.         wesnoth.set_variable(variable, false)
  21.     end
  22. end
Advertisement
Add Comment
Please, Sign In to add comment