Jump to content

Recommended Posts

Hello,

I want to make a mod for the tooth trap. I want to override the OnExplode function to add a auto-reset tweak.

This is my code in the modmain.lua:
 

local function newOnExplode(inst, target)
    local oldOnExplode = inst.OnExplode
    oldOnExplode(inst, target)

	inst:DoTaskInTime(3, function() 
		if inst.components.mine then
			inst.components.mine.onreset(inst) 
			inst.components.mine:StopTesting()
			inst.components.mine.target = nil
			inst.components.mine.issprung = false
			inst.components.mine.inactive = false
			inst.components.mine:StartTesting()
		end
	end)
end

local function autoToothTrap(inst)
    inst.components.mine:SetOnExplodeFn(newOnExplode)
end

AddPrefabPostInit("trap_teeth", autoToothTrap)

But, the old OnExplode function is never triggered and it is what i'm searching ? Is it possible to override this function to add an action after the trap was trigerred ?

I find my mistake. I have to use the onexplode variable of the mine component to retrieve the old OnExplode function.

This code works fine:
 

local oldOnExplode

local function newOnExplode(inst, target)
    oldOnExplode(inst, target)
    inst:DoTaskInTime(3, function()
        if inst.components.mine then
            inst.components.mine.onreset(inst)
            inst.components.mine:StopTesting()
            inst.components.mine.target = nil
            inst.components.mine.issprung = false
            inst.components.mine.inactive = false
            inst.components.mine:StartTesting()
        end
    end)
end

local function autoToothTrap(inst)
    oldOnExplode = inst.components.mine.onexplode
    inst.components.mine:SetOnExplodeFn(newOnExplode)
end

AddPrefabPostInit("trap_teeth", autoToothTrap)

A great thank you to DrBLOOD for the Auto Tooth Trap mod which implement this tweak, but it's load a modified prefab file.

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