DarkREM66 Posted August 15, 2020 Share Posted August 15, 2020 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 ? Link to comment https://forums.kleientertainment.com/forums/topic/120965-how-to-override-a-prefab-function/ Share on other sites More sharing options...
DarkREM66 Posted August 15, 2020 Author Share Posted August 15, 2020 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. Link to comment https://forums.kleientertainment.com/forums/topic/120965-how-to-override-a-prefab-function/#findComment-1363009 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