Jump to content

Recommended Posts

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 by Zeklo
Error

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.

 

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.

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...