Jump to content

Recommended Posts

Is there a way to script a random dodge so that all damage from the hit is negated? This is what I have so far (inside of master_postinit):

 

    local oldonhitfn = inst.components.combat.onhitfn
    
    inst.components.combat.onhitfn = function(inst, attacker, damage)
        if oldonhitfn and (math.random() > 0.333333) then
            oldonhitfn(inst, attacker, damage)
        else
            inst.components.talker:Say("Dodged!")
        end
    end

 

It should cause the player to dodge every third hit and have them say "Dodged!", but instead they only say "Dodged!".

 

 

Link to comment
https://forums.kleientertainment.com/forums/topic/48520-scripting-dodge-hit/
Share on other sites

Is this meant to be a character trait or a creature property? "onhitfn" is a set of stuff that happens after getting hit.

 

If it's a character trait, you could try to sometimes add the tag "alwaysblock" after getting hit, and else remove it. (after getting hit, the character becomes immune to the next hit... or loses the immunity)

Theory:
local function onhit(inst)
if math.random() < CHANCE then
inst:AddTag("block")
else
inst:RemoveTag("block")
end
end

function fn()
[...]
inst.components.combat.onhitfn = onhit

If it's a creature property, you can listen for the attack event and change the damage to zero in similiar fashion.

Theory:
local function dodgechance(inst)
if math.random() < CHANCE then
inst.components.combat.damage = 0
else
inst.components.combat.damage = DAMAGE
end
end

function fn()
[...]
inst:ListenForEvent("onattackother",dodgechance)

Is this meant to be a character trait or a creature property? "onhitfn" is a set of stuff that happens after getting hit.

 

If it's a character trait, you could try to sometimes add the tag "alwaysblock" after getting hit, and else remove it. (after getting hit, the character becomes immune to the next hit... or loses the immunity)

Theory:

local function onhit(inst)

if math.random() < CHANCE then

inst:AddTag("block")

else

inst:RemoveTag("block")

end

end

function fn()

[...]

inst.components.combat.onhitfn = onhit

If it's a creature property, you can listen for the attack event and change the damage to zero in similiar fashion.

Theory:

local function dodgechance(inst)

if math.random() < CHANCE then

inst.components.combat.damage = 0

else

inst.components.combat.damage = DAMAGE

end

end

function fn()

[...]

inst:ListenForEvent("onattackother",dodgechance)

 

I meant as a character trait. It really bothers me that this effects the FOLLOWING hit, but I guess it's the same considering the player won't know when they have immunity.

 

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
×
  • Create New...