Jump to content

Knockback immune


Recommended Posts

elo

I wish to give my custom character immunity to the smacking the Elite Pigs do to you in YOTP, or when bosses punch you in Forge.

I want to remap the wilson stategraph and inject it in my modmain but i'm a little lost

I did manage to disable stunlock that way so I'm hoping it could more or less be the same deal

Quote

AddStategraphPostInit("wilson", function(sg)
   local old_attacked = sg.events.attacked.fn
    
   sg.events.attacked.fn = function(inst, data)
    if not inst.components.health:IsDead() then
           if inst:HasTag("mynewtag") and data.attacker ~= nil then
              inst.SoundEmitter:PlaySound("dontstarve/wilson/hit")
            if inst.hurtsoundoverride ~= nil then
                inst.SoundEmitter:PlaySound(inst.hurtsoundoverride)
            elseif not inst:HasTag("mime") then
                inst.SoundEmitter:PlaySound((inst.talker_path_override or "dontstarve/characters/")..(inst.soundsname or inst.prefab).."/hurt")
            end
            return
           else
               return old_attacked(inst, data)
           end
       end
   end
end)

 

Link to comment
Share on other sites

Knockback is handled in the knockback eventhandler:

EventHandler("knockback", function(inst, data)
        if not (inst.components.health:IsDead() or inst:HasTag("beaver")) then
            if inst.sg:HasStateTag("parrying") then
                inst.sg.statemem.parrying = true
                inst.sg:GoToState("parry_knockback", {
                    timeleft =
                        (inst.sg.statemem.task ~= nil and GetTaskRemaining(inst.sg.statemem.task)) or
                        (inst.sg.statemem.timeleft ~= nil and math.max(0, inst.sg.statemem.timeleft + inst.sg.statemem.timeleft0 - GetTime())) or
                        inst.sg.statemem.parrytime,
                    knockbackdata = data,
                })
            else
                inst.sg:GoToState((data.forcelanded or inst.components.inventory:ArmorHasTag("heavyarmor") or inst:HasTag("heavybody")) and "knockbacklanded" or "knockback", data)
            end
        end
    end),

copied from SG wilson. So do the same thing you did with the onattacked and just alter this event to your liking.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...