Divergent/mods/NPC Wounded Redone/gamedata/scripts/liz_wounded_redone.script

155 lines
6.0 KiB
Plaintext

-- took from dismemberment mod
local creatures_cls = {
[clsid.script_stalker] = { "human", "stalker_damage" },
-- [clsid.dog_s] = { "dog", "m_dog_damage" },
-- [clsid.pseudodog_s] = { "pseudo_dog", "m_pseudodog_damage" },
-- [clsid.psy_dog_s] = { "pseudo_dog", "m_pseudodog_damage" },
-- [clsid.boar_s] = { "boar", "m_boar_damage" },
-- [clsid.flesh_s] = { "flesh", "m_flesh_damage" },
-- [clsid.cat_s] = { "cat", "cat_damage" },
-- [clsid.zombie_s] = { "zombie", "m_zombie_damage" },
-- [clsid.tushkano_s] = { "tushkano", "m_tushkano_damage" },
-- [clsid.snork_s] = { "snork", "m_snork_damage" },
-- [clsid.controller_s] = { "controller", "m_controller_damage" },
-- [clsid.bloodsucker_s] = { "bloodsucker", "m_bloodsucker_damage" },
-- [clsid.chimera_s] = { "chimera" },
-- [clsid.burer_s] = { "burer", "m_burer_damage" },
-- [clsid.fracture_s] = { "fracture", "fracture_normal_damage" },
-- [clsid.gigant_s] = { "giant", "m_giant_damage" },
}
-- took from dismemberment mod
-- local creatures_kind = {
-- ["SM_KARLIK"] = { "karlik", "m_tushkano_damage" },
-- ["SM_PSYSUCKER"] = { "bloodsucker", "m_bloodsucker_damage" },
-- ["SM_LURKER"] = { "chimera" },
-- }
--damage to bones in this list make npc go into wounded state instead of dying
local non_lethal_bones = {
["bip01_l_upperarm"] = true,
["bip01_l_forearm"] = true,
["bip01_l_hand"] = true,
["bip01_l_finger0"] = true,
["bip01_l_finger01"] = true,
["bip01_l_finger02"] = true,
["bip01_l_finger1"] = true,
["bip01_l_finger11"] = true,
["bip01_l_finger12"] = true,
["bip01_l_finger2"] = true,
["bip01_l_finger21"] = true,
["bip01_l_finger22"] = true,
["bip01_r_upperarm"] = true,
["bip01_r_forearm"] = true,
["bip01_r_hand"] = true,
["bip01_r_finger0"] = true,
["bip01_r_finger01"] = true,
["bip01_r_finger02"] = true,
["bip01_r_finger1"] = true,
["bip01_r_finger11"] = true,
["bip01_r_finger12"] = true,
["bip01_r_finger2"] = true,
["bip01_r_finger21"] = true,
["bip01_r_finger22"] = true,
["bip01_l_thigh"] = true,
["bip01_l_calf"] = true,
["bip01_l_foot"] = true,
["bip01_l_toe0"] = true,
["bip01_r_thigh"] = true,
["bip01_r_calf"] = true,
["bip01_r_foot"] = true,
["bip01_r_toe0"] = true,
}
--damage to bones in this list will make npc drop his weapon
local hand_bones = {
-- ["bip01_l_forearm"] = true,
-- ["bip01_l_hand"] = true,
-- ["bip01_l_finger0"] = true,
-- ["bip01_l_finger01"] = true,
-- ["bip01_l_finger02"] = true,
-- ["bip01_l_finger1"] = true,
-- ["bip01_l_finger11"] = true,
-- ["bip01_l_finger12"] = true,
-- ["bip01_l_finger2"] = true,
-- ["bip01_l_finger21"] = true,
-- ["bip01_l_finger22"] = true,
-- ["bip01_r_forearm"] = true,
["bip01_r_hand"] = true,
["bip01_r_finger0"] = true,
["bip01_r_finger01"] = true,
["bip01_r_finger02"] = true,
["bip01_r_finger1"] = true,
["bip01_r_finger11"] = true,
["bip01_r_finger12"] = true,
["bip01_r_finger2"] = true,
["bip01_r_finger21"] = true,
["bip01_r_finger22"] = true,
}
local wounded_states = {
[0] = "wounded",
[1] = "wounded_heavy",
[2] = "wounded_heavy_2",
[3] = "wounded_heavy_3"
}
local allowed_hit_types = {
[hit.wound] = true,
[hit.fire_wound] = true,
}
function on_game_start()
RegisterScriptCallback("npc_on_before_hit", npc_on_before_hit)
end
function npc_on_before_hit(npc, shit, bone_id, flags)
if not (npc:alive()) then return end
if npc:has_info("npcx_is_companion") then return end
-- local community = character_community(npc)
-- local npc_kind = ini_sys:r_string_ex(npc:section(), "kind")
-- local npc_damage_section = (creatures_cls[npc:clsid()] and creatures_cls[npc:clsid()][2]) or (npc_kind and creatures_kind[npc_kind] and creatures_kind[npc_kind][2]) or (npc:section())
local npc_damage_section = (creatures_cls[npc:clsid()] and creatures_cls[npc:clsid()][2]) or (npc:section()) -- took from dismemberment code
if npc_damage_section then
local bone_name = npc:bone_name(bone_id)
local str = bone_name and ini_sys:r_string_ex(npc_damage_section, bone_name)
local p = str and str_explode(str, ",")
if p and p[1] then
local hit_power_mult = tonumber(p[1]) or 1 -- if not found then 1
local predicted_health = npc.health - (shit.power * hit_power_mult)
if predicted_health <= 0 and non_lethal_bones[bone_name] and allowed_hit_types[shit.type] then --handle wounded state
flags.ret_value = false
local state = state_mgr.get_state(npc)
if state ~= "wounded_heavy" and state ~= "wounded_heavy_2" and state ~= "wounded_heavy_3" then
local new_state = wounded_states[math.random(0, #wounded_states)]
npc.health = 0.1
-- npc.bleeding = 0
save_var(npc, "wounded_state", new_state)
save_var(npc, "wounded_fight", "false")
-- save_var(npc, "wounded_victim", "nil")
save_var(npc, "victim_surrender", true)
state_mgr.set_state(npc, new_state, nil, nil, nil, { fast_set = true })
end
elseif hand_bones[bone_name] then -- handle drop weapon feature
if character_community(npc) == "zombied" then return end --ignore zombies. they don't know waht to do if they loose weapon
-- flags.ret_value = false
local item = npc:active_item()
local slot = npc:active_slot()
if (item) and ((slot == 2) or (slot == 3)) and (npc:dont_has_info("npcx_is_companion")) then
death_manager.set_weapon_drop_condition(npc, item)
npc:drop_item(item)
end
end
end
end
end