Zeklo Posted October 31, 2016 Share Posted October 31, 2016 (edited) Would anybody happen to know a clean way to prevent death from activating when having no health? Not reviving, not turning into a ghost, yata yata. Just plain old not dying. I want to implement some custom antics in its place when certain requirements are met, but I dunno if there is a simple way of doing this or if I'll have to take more complicated measures. Edited November 1, 2016 by Zeklo Error Link to comment https://forums.kleientertainment.com/forums/topic/71312-solved-prevent-death-upon-no-hp/ Share on other sites More sharing options...
Leonardo Cox Posted November 1, 2016 Share Posted November 1, 2016 You can try messing around with the EventHandler for death in the stategraph: --taken from Wilson's SG. EventHandler("death", function(inst) if inst.sleepingbag ~= nil and (inst.sg:HasStateTag("bedroll") or inst.sg:HasStateTag("tent")) then -- wakeup on death to "consume" sleeping bag first inst.sleepingbag.components.sleepingbag:DoWakeUp() inst.sleepingbag = nil end inst.sg:GoToState("death") end), You could use a Stategraphevent in your modmain to edit Wilson's SG (assuming you are using his for your character.) --put this somewhere in your modmain.lua, it should overwrite the Eventhandler for death. local EventHandler = GLOBAL.EventHandler local newdeath = EventHandler("death", function(inst) if inst.sleepingbag ~= nil and (inst.sg:HasStateTag("bedroll") or inst.sg:HasStateTag("tent")) then -- wakeup on death to "consume" sleeping bag first inst.sleepingbag.components.sleepingbag:DoWakeUp() inst.sleepingbag = nil end if inst.prefab ~= "your characterprefab name here" then inst.sg:GoToState("death") else --whatever antics you want here end end ), AddStategraphEvent("wilson", newdeath) --if not wilson, then its probably SGwilson. Link to comment https://forums.kleientertainment.com/forums/topic/71312-solved-prevent-death-upon-no-hp/#findComment-831724 Share on other sites More sharing options...
DarkXero Posted November 1, 2016 Share Posted November 1, 2016 No, no messing with the death state. Do something else. local function CanDie(inst) local death = false if inst.components.sanity.current < 50 then death = true end return death end local function master_postinit(inst) local health = inst.components.health local health_SetVal = health.SetVal health.SetVal = function(self, val, cause, afflicter) if val <= 0 and not self.inst:CanDie() then self.currenthealth = 1 else health_SetVal(self, val, cause, afflicter) end end inst.CanDie = CanDie end Like that. Leave the hp at 1 and only let it die when the CanDie function allows. Link to comment https://forums.kleientertainment.com/forums/topic/71312-solved-prevent-death-upon-no-hp/#findComment-831729 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