Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function wml_actions.wounded_unit(cfg)
- local unit_type = wesnoth.unit_types[cfg.type] or helper.wml_error("[wounded_unit]: missing a valid type= key")
- local min_hp = cfg.min_hp or 1
- local max_hp = cfg.max_hp or unit_type.hitpoints
- local min_exp = cfg.min_exp or 0
- local max_exp = cfg.max_exp or unit_type.experience - 1
- local seed = wesnoth.random(1,100)
- local unit = wesnoth.create_unit(cfg)
- if not (unit.x and unit.y) then
- if cfg.placement and cfg.placement == 'leader' then
- local leader = wesnoth.get_units({ side = unit.side, canrecruit = 'yes' })[1]
- unit.x = leader.x
- unit.y = leader.y
- else
- helper.wml_error("[wounded_unit]: no location found to put unit")
- end
- end
- unit.hitpoints = min_hp + math.floor((seed / 100) * (max_hp - min_hp))
- unit.experience = min_exp + math.floor(((100 - seed) / 100) * (max_exp - min_exp))
- wesnoth.put_unit(unit)
- end
Advertisement
Add Comment
Please, Sign In to add comment