Vultraz

Untitled

Jul 18th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.89 KB | None | 0 0
  1. function wml_actions.wounded_unit(cfg)
  2.     local unit_type = wesnoth.unit_types[cfg.type] or helper.wml_error("[wounded_unit]: missing a valid type= key")
  3.     local min_hp = cfg.min_hp or 1
  4.     local max_hp = cfg.max_hp or unit_type.hitpoints
  5.     local min_exp = cfg.min_exp or 0
  6.     local max_exp = cfg.max_exp or unit_type.experience - 1
  7.  
  8.     local seed = wesnoth.random(1,100)
  9.  
  10.     local unit = wesnoth.create_unit(cfg)
  11.  
  12.     if not (unit.x and unit.y) then
  13.         if cfg.placement and cfg.placement == 'leader' then
  14.             local leader = wesnoth.get_units({ side = unit.side, canrecruit = 'yes' })[1]
  15.  
  16.             unit.x = leader.x
  17.             unit.y = leader.y
  18.         else
  19.             helper.wml_error("[wounded_unit]: no location found to put unit")
  20.         end
  21.     end
  22.  
  23.     unit.hitpoints = min_hp + math.floor((seed / 100) * (max_hp - min_hp))
  24.     unit.experience = min_exp + math.floor(((100 - seed) / 100) * (max_exp - min_exp))
  25.  
  26.     wesnoth.put_unit(unit)
  27. end
Advertisement
Add Comment
Please, Sign In to add comment