ColombianCam Posted April 20, 2019 Share Posted April 20, 2019 I'm trying to make woodie be able to use living logs as an off and on switch of his state, if he eats a living log as a beaver he turns into woodie and vice versa, but I'm not able to make it happen without crashing, I've been looking at everything related to this, event handlers because transforming is an event but how do I apply it to a eaten item? it says eater is not defined to say it's woodie who transforms if eaten. I noticed that there was only inst so I decided to replace everything with eater to see if it worked, I've stressed out options in the past by using woodie's prefab own transform bits but it doesn't work, i've read rezecibs post to understand. inst:AddComponent("edible") inst.components.edible.foodtype = FOODTYPE.WOOD inst.components.edible.woodiness = 0 inst.components.edible.healthvalue = 0 inst.components.edible.hungervalue = 0 if eater.isbeavermode:value() then eater:RemoveTag("beaver") eater.Network:RemoveUserFlag(USERFLAGS.CHARACTER_STATE_1) eater.isbeavermode:set(false) eater:PushEvent("stopbeaver") OnBeaverModeDirty(eater) if not eater.isbeavermode:value() then eater:AddTag("beaver") eater.Network:AddUserFlag(USERFLAGS.CHARACTER_STATE_1) eater.isbeavermode:set(true) eater:PushEvent("startbeaver") OnBeaverModeDirty(eater) inst.components.edible:SetOnEatenFn(oneaten) Link to comment Share on other sites More sharing options...
Ultroman Posted April 20, 2019 Share Posted April 20, 2019 (edited) I'm not sure what you're actually editing here. I'm going to assume that this code is inside an AddPrefabPostInit("livinglog", function). There are a number of problems. Your if-statements are missing their closing "end". At the bottom you're hooking up a function that you haven't shown to be there. Your two if-statements are in the wrong context. You can't just put if-statements about what happens when the food is eaten into a post-init function. Those if-statements have to be executed when the food is eaten, not when it is initialized. You're assuming that you can check the status of being a beaver on any character eating this food. Only Woodie will have the eater.isbeavermode variable. This should work (assuming your code is otherwise correct; I don't know how Woodie's tranformation works): inst:AddComponent("edible") inst.components.edible.foodtype = FOODTYPE.WOOD inst.components.edible.woodiness = 0 inst.components.edible.healthvalue = 0 inst.components.edible.hungervalue = 0 inst.components.edible:SetOnEatenFn( function(inst, eater) if eater.prefab == "woodie" and eater.isbeavermode:value() then eater:RemoveTag("beaver") eater.Network:RemoveUserFlag(USERFLAGS.CHARACTER_STATE_1) eater.isbeavermode:set(false) eater:PushEvent("stopbeaver") OnBeaverModeDirty(eater) end if eater.prefab == "woodie" and not eater.isbeavermode:value() then eater:AddTag("beaver") eater.Network:AddUserFlag(USERFLAGS.CHARACTER_STATE_1) eater.isbeavermode:set(true) eater:PushEvent("startbeaver") OnBeaverModeDirty(eater) end end) Edited April 20, 2019 by Ultroman Link to comment Share on other sites More sharing options...
CarlZalph Posted April 21, 2019 Share Posted April 21, 2019 19 hours ago, Ultroman said: I'm not sure what you're actually editing here. I'm going to assume that this code is inside an AddPrefabPostInit("livinglog", function). There are a number of problems. Your if-statements are missing their closing "end". At the bottom you're hooking up a function that you haven't shown to be there. Your two if-statements are in the wrong context. You can't just put if-statements about what happens when the food is eaten into a post-init function. Those if-statements have to be executed when the food is eaten, not when it is initialized. You're assuming that you can check the status of being a beaver on any character eating this food. Only Woodie will have the eater.isbeavermode variable. This should work (assuming your code is otherwise correct; I don't know how Woodie's tranformation works): inst:AddComponent("edible") inst.components.edible.foodtype = FOODTYPE.WOOD inst.components.edible.woodiness = 0 inst.components.edible.healthvalue = 0 inst.components.edible.hungervalue = 0 inst.components.edible:SetOnEatenFn( function(inst, eater) if eater.prefab == "woodie" and eater.isbeavermode:value() then eater:RemoveTag("beaver") eater.Network:RemoveUserFlag(USERFLAGS.CHARACTER_STATE_1) eater.isbeavermode:set(false) eater:PushEvent("stopbeaver") OnBeaverModeDirty(eater) end if eater.prefab == "woodie" and not eater.isbeavermode:value() then eater:AddTag("beaver") eater.Network:AddUserFlag(USERFLAGS.CHARACTER_STATE_1) eater.isbeavermode:set(true) eater:PushEvent("startbeaver") OnBeaverModeDirty(eater) end end) Should lump that into an if-else to stop it from calling the below code immediately in case the netvar changes immediately. inst:AddComponent("edible") inst.components.edible.foodtype = FOODTYPE.WOOD inst.components.edible.woodiness = 0 inst.components.edible.healthvalue = 0 inst.components.edible.hungervalue = 0 inst.components.edible:SetOnEatenFn(function(inst, eater) if eater.prefab == "woodie" then if eater.isbeavermode:value() then eater:RemoveTag("beaver") eater.Network:RemoveUserFlag(USERFLAGS.CHARACTER_STATE_1) eater.isbeavermode:set(false) eater:PushEvent("stopbeaver") OnBeaverModeDirty(eater) else eater:AddTag("beaver") eater.Network:AddUserFlag(USERFLAGS.CHARACTER_STATE_1) eater.isbeavermode:set(true) eater:PushEvent("startbeaver") OnBeaverModeDirty(eater) end end end) Link to comment Share on other sites More sharing options...
ColombianCam Posted April 21, 2019 Author Share Posted April 21, 2019 Thanks a bunch guys! After analyzing what y'all proposed I landed on this function(inst, eater) if eater.prefab == "woodie" and not eater.isbeavermode:value() then eater.components.beaverness:SetPercent(.25) elseif eater.prefab == "woodie" and eater.isbeavermode:value()then eater.components.beaverness:SetPercent(1) end end) which instead of making the character go into transformation, it sets the transformation values of the log meter, so I don't have to code any transformation bits and the game does it for me, if the log meter reached this log beaverness value. Link to comment 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