Player hit reactions/Flinch on Bullet Hit

Hey everyone,

I was wondering if anyone could make (or point me to) a mod that makes the player stagger or flinch when getting shot—basically the same way NPCs react when they take a bullet.

I think it’d add a lot of immersion and balance, but I haven’t found anything like it so far. If someone knows a workaround or is down to create it, I’d really appreciate it!


Thanks in advance.
 
Hi, while I have not found the code that actually handles damage to NPCs/player, I found this snippet in game_lib.lua of SRIV (probably the same code as SRTT) :
Code:
-- Make a human play a direction stumble, blocking until the animation is done
--
-- name:            (string) name of character
-- nav_name:        (string) name of navpoint indicating the direction to stumble
-- percentage:        (float, optional) percentage done to check for (defaults to 0.8)
-- do_flinch:        (boolean, optional) true if a flinch should be in place of the stumble animations
--
-- If possible, the <a>action_play</a> script action should be used instead where possible.
--
function action_play_directional_stumble(name, nav_name, percentage, do_flinch)
    while not action_play_directional_stumble_do(name, nav_name, do_flinch) do
        thread_yield()
    end

    repeat
        thread_yield()
    until action_play_is_finished(name, percentage)
end
This is taken from nclok's SuperUI file, probably it is his comment
 
21223.gif

You can refer to this function:hypers:
SR3, SR4, and SRGOOH can all be used
 
Code:
function test_take_damage_cb(npc_name, attacker, hp, explode, melee, vomit, amount, is_tk, is_dfa, is_energy, is_stomp, is_headshot, ss_stun, is_buff, is_shark, ...)

    local material_effect = "cid_shield"
    local playback_duration = 1.0
    local anim_play = "flinch chest front"
    local explosion_spawn = "Murderbot_exp"
 

-- From SaintsRowMods.com User:bigbang

    local damage_type = "unknown"
    if explode then
        damage_type = "explosion"
    elseif melee then
        damage_type = "melee"
    elseif vomit then
        damage_type = "vomit"
    elseif is_tk then
        damage_type = "telekinesis"
    elseif is_dfa then
        damage_type = "death from above"
    elseif is_energy then
        damage_type = "energy"
    elseif is_stomp then
        damage_type = "stomp"
    elseif is_headshot then
        damage_type = "headshot"
    elseif ss_stun then
        damage_type = "stun"
    elseif is_buff then
        damage_type = "buff"
    elseif is_shark then
        damage_type = "shark"
    end
 
    local weapon_name = attacker or "unknown"
 
    local message = "You took damage!\n"
    message = message .. "Damage Type: " .. (damage_type or "nil") .. "\n"
    message = message .. "Damage From: " .. (weapon_name or "nil") .. "\n"
    message = message .. "Applying material effect: " .. material_effect .. "\n"
    message = message .. "anim play: " .. anim_play .. "\n"
    message = message .. "----> From \nwww.SaintsRowMods.com \nUser : bigbang\n"
    script_message(message)

--ingame effect apply -- From SaintsRowMods.com User:bigbang
    explosion_create(explosion_spawn, LOCAL_PLAYER, SYNC_ALL)
    action_play(LOCAL_PLAYER, anim_play,nil,false,nil,true,true,nil,nil)
end

function init_take_damage_test()
    on_take_damage("test_take_damage_cb", LOCAL_PLAYER)
 
    --script_message("Take Damage Test initialized\nTake any damage to see the material effect")
end

function cleanup_take_damage_test()
    on_take_damage("", LOCAL_PLAYER)
 
end


function common_function()
    while true do
   -- From SaintsRowMods.com User:bigbang
        if player_action_is_pressed("CBA_VDC_OFFHAND_GRENADE") and player_action_is_pressed("CBA_GAC_CANCEL_ACTIVITY") then
                -- insert + delete
                init_take_damage_test()
                script_message("enable init_take_damage_test\n----> From \nwww.SaintsRowMods.com \nUser : bigbang\n")
        elseif player_action_is_pressed("CBA_GAC_WEAPON_SELECT_7") and player_action_is_pressed("CBA_GAC_WEAPON_SELECT_8") then
                -- 7 + 8
                cleanup_take_damage_test()
                script_message("disabled init_take_damage_test\n----> From \nwww.SaintsRowMods.com \nUser : bigbang\n")
        elseif player_action_is_pressed("CBA_GAC_WEAPON_SELECT_6") and player_action_is_pressed("CBA_OFC_PICKUP_RELOAD") then
                -- 6 + R
        end
    delay(0.5)
    end
end

effect
Stumble.gif
 
Last edited:
Back
Top