Woodside235 Posted January 6, 2015 Share Posted January 6, 2015 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 More sharing options...
Mobbstar Posted January 6, 2015 Share Posted January 6, 2015 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 theninst:AddTag("block")elseinst:RemoveTag("block")endendfunction fn()[...]inst.components.combat.onhitfn = onhitIf 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 theninst.components.combat.damage = 0elseinst.components.combat.damage = DAMAGEendendfunction fn()[...]inst:ListenForEvent("onattackother",dodgechance) Link to comment https://forums.kleientertainment.com/forums/topic/48520-scripting-dodge-hit/#findComment-597682 Share on other sites More sharing options...
Woodside235 Posted January 6, 2015 Author Share Posted January 6, 2015 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 theninst:AddTag("block")elseinst:RemoveTag("block")endendfunction fn()[...]inst.components.combat.onhitfn = onhitIf 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 theninst.components.combat.damage = 0elseinst.components.combat.damage = DAMAGEendendfunction 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. Link to comment https://forums.kleientertainment.com/forums/topic/48520-scripting-dodge-hit/#findComment-597808 Share on other sites More sharing options...
Woodside235 Posted January 6, 2015 Author Share Posted January 6, 2015 inst:AddTag("block") I enabled block 100% of the time to test it, it isn't blocking hits. Link to comment https://forums.kleientertainment.com/forums/topic/48520-scripting-dodge-hit/#findComment-597834 Share on other sites More sharing options...
Mobbstar Posted January 6, 2015 Share Posted January 6, 2015 I enabled block 100% of the time to test it, it isn't blocking hits.that was theory, not actual code. The tag is called "alwaysblock" Link to comment https://forums.kleientertainment.com/forums/topic/48520-scripting-dodge-hit/#findComment-597837 Share on other sites More sharing options...
Woodside235 Posted January 7, 2015 Author Share Posted January 7, 2015 that was theory, not actual code. The tag is called "alwaysblock" So here's a tricky thing to deal with: the onhit function doesn't get called if an attack was blocked. Thus, once block is enabled it stays enabled. Any ideas? Link to comment https://forums.kleientertainment.com/forums/topic/48520-scripting-dodge-hit/#findComment-598123 Share on other sites More sharing options...
Kzisor Posted January 7, 2015 Share Posted January 7, 2015 @Woodside235, I've posted in your other thread which you asked about sound how to actually accomplish what you are wanting to do in a simple fashion. Link to comment https://forums.kleientertainment.com/forums/topic/48520-scripting-dodge-hit/#findComment-598130 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now