Vultraz

Untitled

Mar 29th, 2015
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.85 KB | None | 0 0
  1. local helper = wesnoth.require "lua/helper.lua"
  2.  
  3. function wesnoth.wml_actions.find_respawn_point(cfg)
  4.     local respawn_near = cfg.respawn_near or helper.wml_error "[find_respawn_point] missing required respawn_near= key"
  5.     local variable = cfg.variable or "nearest_hex"
  6.     local respawn_point
  7.     local radius = 1
  8.  
  9.     if not wesnoth.eval_conditional { { "have_unit", { id = respawn_near} } } then
  10.         respawn_near = "Tallin"
  11.     end
  12.  
  13.     repeat
  14.         respawn_point = wesnoth.get_locations({
  15.             include_borders = false,
  16.             { "and", { { "filter", { id = respawn_near} },
  17.                         radius = radius } },
  18.             { "and", { { "not", { { "filter", {} } } },
  19.             { "not", { terrain = "Wo,*^Xm,X*,Q*" } } } }
  20.         })
  21.  
  22.         radius = radius + 1
  23.     until respawn_point[1]
  24.  
  25.     wesnoth.set_variable(variable .. ".x", respawn_point[1][1])
  26.     wesnoth.set_variable(variable .. ".y", respawn_point[1][2])
  27. end
Advertisement
Add Comment
Please, Sign In to add comment