207 lines
7.5 KiB
Plaintext
207 lines
7.5 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" },
|
|
}
|
|
|
|
--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,
|
|
}
|
|
|
|
local enable_weapon_drop = liz_wounded_redone_mcm.get_config("enable_weapon_drop")
|
|
local enable_bleeding = liz_wounded_redone_mcm.get_config("enable_bleeding")
|
|
local is_autoheal_enabled = liz_wounded_redone_mcm.get_config("autoheal")
|
|
|
|
|
|
function on_game_start()
|
|
RegisterScriptCallback("npc_on_before_hit", npc_on_before_hit)
|
|
RegisterScriptCallback("on_option_change", on_option_change)
|
|
end
|
|
|
|
|
|
function on_option_change()
|
|
enable_weapon_drop = liz_wounded_redone_mcm.get_config("enable_weapon_drop")
|
|
enable_bleeding = liz_wounded_redone_mcm.get_config("enable_bleeding")
|
|
is_autoheal_enabled = liz_wounded_redone_mcm.get_config("autoheal")
|
|
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
|
|
if not enable_bleeding then npc.bleeding = 0 end
|
|
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 enable_weapon_drop and 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
|
|
|
|
|
|
----------------------------------------------------
|
|
-- xr_wounded patches
|
|
----------------------------------------------------
|
|
xr_wounded.evaluator_wound.evaluate = function (self)
|
|
local o = self.object
|
|
if not (IsStalker(o) and o:alive()) then
|
|
return false
|
|
end
|
|
|
|
-- same as the original code but removed this bit for a testing purposes
|
|
-- if (o:critically_wounded() or o:in_smart_cover()) then
|
|
-- return false
|
|
-- end
|
|
|
|
if self.a.wounded_set ~= true then return false end
|
|
|
|
self.a.wound_manager:update()
|
|
|
|
if o:best_enemy() and load_var(o, "wounded_fight") == "true" then
|
|
return false
|
|
end
|
|
|
|
local state = tostring(load_var(o, "wounded_state"))
|
|
if (state == "nil") then
|
|
return false
|
|
end
|
|
|
|
return true
|
|
end
|
|
|
|
|
|
local originalIW = xr_wounded.init_wounded
|
|
xr_wounded.init_wounded = function(npc, ini, section, st, scheme)
|
|
originalIW(npc, ini, section, st, scheme)
|
|
|
|
if is_autoheal_enabled then return end
|
|
|
|
if tostring(section) then
|
|
st.autoheal = false
|
|
else
|
|
st.autoheal = ini:r_bool_ex(section, "autoheal", false)
|
|
end
|
|
end
|