Divergent/mods/Corpse Twitching/gamedata/scripts/impulse.script

98 lines
2.8 KiB
Plaintext
Raw Normal View History

bones_list = {
[1] = "bip01_head",
[2] = "bip01_spine",
[3] = "bip01_l_hand",
[4] = "bip01_r_hand",
[5] = "bip01_l_foot",
[6] = "bip01_r_foot",
}
timer_twitch = 0
corpses_to_update = {}
time_factor = 6
basic_duration = 10
function on_game_start()
time_factor = SYS_GetParam(2,"alife","time_factor")
RegisterScriptCallback("actor_on_before_death", on_actor_before_death)
RegisterScriptCallback("actor_on_update", update_corpses)
RegisterScriptCallback("npc_on_death_callback", npc_on_death_callback)
RegisterScriptCallback("bullet_on_impact", bullet_on_impact)
end
function bullet_on_impact(bullet)
if bullet.target_id ~= 65535 then
local obj = level.object_by_id(bullet.target_id)
if obj and (IsStalker(obj)) and (not obj:alive()) and corpses_to_update[obj:id()] then
printf("shot")
corpses_to_update[obj:id()].duration = corpses_to_update[obj:id()].duration - basic_duration * time_factor
end
end
end
function on_actor_before_death()
CreateTimeEvent("actorhit1","imphit2", 0.25, impulse_actor)
end
function npc_on_death_callback(npc)
if not npc then return end
local twitch_power = math.random() * 3.5
--CreateTimeEvent("npchit1","gimphit2", 0, death_impulse, npc)
corpses_to_update[npc:id()] = {
power = twitch_power,
duration = twitch_power * basic_duration * time_factor,
death_time = game.get_game_time()
}
end
function death_impulse(npc)
if npc:get_physics_shell() then
local mul = 30000
npc:get_physics_shell():apply_force(math.random(-1,1) * mul * 0.5, 0, math.random(-1,1) * mul * 0.5)
return true
end
end
function update_corpses()
local tg = time_global()
if timer_twitch > tg then return end
timer_twitch = tg + 50
local c_time = game.get_game_time()
for k,v in pairs(corpses_to_update) do
local obj = level.object_by_id(k)
if not obj then
corpses_to_update[k] = nil
else
impulse_corpse(obj, v, c_time)
if v.duration < -1 * v.death_time:diffSec(c_time) then
corpses_to_update[k] = nil
end
end
end
end
function impulse_corpse(obj, data, c_time)
local h = hit()
--printf(data.power * ((data.duration + data.death_time:diffSec(c_time)) / data.duration))
h.impulse = data.power * ((data.duration + data.death_time:diffSec(c_time)) / data.duration)
h.draftsman = obj
local dirx = math.random() * 2 + -1
local diry = math.random() * 2 + -1
local dirz = math.random() * 2 + -1
h.direction = vector():set(dirx,diry,dirz)
h:bone(bones_list[math.random(1,6)]) -- чтобы учитывалась броня
h.power = 0.01
h.type = hit.burn
obj:hit(h)
end
function impulse_actor()
if not db.actor:alive() then
AddUniqueCall(update_corpses)
local twitch_power = math.random() * 3.5
corpses_to_update[db.actor:id()] = {
power = twitch_power,
duration = twitch_power * basic_duration * time_factor,
death_time = game.get_game_time()
}
end
return true
end