Jump to content

[Solved] How to disable sanity loss from using wormhole


Recommended Posts

Hello, I need some help with this code I dunno what I did wrong or how this works

Here's the code

modmain.lua

Spoiler

AddPrefabPostInit("wormhole", function(inst)
	if not GLOBAL.TheWorld.ismastersim then return end
	local onActivate_old = inst.components.teleporter.onActivate
	inst.components.teleporter.onActivate = function(inst, doer, ...)
	
		if doer.components.sanity ~= nil and doer.prefab == "esctemplate" then
            doer.components.sanity:DoDelta(-TUNING.SANITY_MED)
        end
		
		return onActivate_old(inst, doer, ...)
	end
end)

 

if someone can help me out why this don't work or tell me if this is not the right way and show the right way that'd be great cause the only other thing I know to do is copypaste edit wormhole.lua into my mod which would cause compatibility issues with other mods who do that, thanks for your time have a great day!

Edited by SuperDavid
Link to comment
Share on other sites

if not GLOBAL.TheWorld.ismastersim then return end
local _oldOnActivate = inst.components.teleporter.onActivate

inst.components.teleporter.onActivate = function(inst, doer)
	if doer.prefab == "esctemplate" and doer.components.sanity and not doer.components.sanity.ignore then
		doer.components.sanity.ignore = true
		_oldOnActivate(inst, doer)
		doer.components.sanity.ignore = false
	else
		_oldOnActivate(inst, doer)
	end
end

 

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