chaosdc123 Posted February 23, 2019 Share Posted February 23, 2019 so im trying to fix a mod (im not going to try and post it, just inform the original author how to fix it) the original mod is woge the doge everything works fine but the sleep mechanic, when you push O it makes you go to sleep (it drains your hunger faster but doesnt heal you) and pushing P wakes you up (stops draining your hunger) here is the coding i think is relevent (mod main) local SLEEP = GLOBAL.Action() SLEEP.str = "Sleep" SLEEP.id = "SLEEP" SLEEP.fn = function(act) if not act.target:HasTag("busy") then act.target.sg:GoToState("sleep") act.target:AddComponent("healthRegen") end end AddAction(SLEEP) local WAKEUP = GLOBAL.Action() WAKEUP.str = "Wakeup" WAKEUP.id = "WAKEUP" WAKEUP.fn = function(act) act.target.sg:GoToState("wake") act.target:RemoveComponent("healthRegen") end AddAction(WAKEUP) local function wakeup(player) GLOBAL.BufferedAction(player, player, GLOBAL.ACTIONS.WAKEUP):Do() end AddModRPCHandler("leifworkaround", "Wakeup", wakeup) (lua) local function OnKeySleep(inst, data) if data.inst == ThePlayer then if data.key == KEY_O then --inst.components.propagator.StartSpreading() inst.AnimState:SetBank("hound") inst.AnimState:SetBuild("hound_pear_fix") if TheWorld.ismastersim then BufferedAction(inst, inst, ACTIONS.SLEEP):Do() -- Since we are the server, do the action on the server. else SendRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.SLEEP.code, inst, ACTIONS.SLEEP.mod_name) end end end end local function OnKeyWakeup(inst, data) if data.inst == ThePlayer then if data.key == KEY_P then --inst.components.propagator.StopSpreading() inst.AnimState:SetBank("hound") inst.AnimState:SetBuild("hound_pear_fix") SendModRPCToServer(MOD_RPC["leifworkaround"]["Wakeup"]) inst:DoTaskInTime(1, function() inst.AnimState:SetBank("hound_pear") inst.AnimState:SetBuild("hound_pear2") end) end end end ive tried to change the line "act.target:AddComponent("healthRegen")" to "self.player.pushevent("healthregen") but that hard crashed the game to where it disabled all my mods I have almost no experience to coding, i love this mod and just wished it worked 100% correctly i pan to link him to this thread Link to comment Share on other sites More sharing options...
chaosdc123 Posted February 23, 2019 Author Share Posted February 23, 2019 changing healthregen to health regeneration crashes the game so i think its "working" it just doesnt know how much hp to give per tick/second Link to comment Share on other sites More sharing options...
chaosdc123 Posted February 23, 2019 Author Share Posted February 23, 2019 (edited) function Health:StartRegen(amount, period, interruptcurrentregen) -- We don't always do this just for backwards compatibility sake. While unlikely, it's possible some modder was previously relying on -- the fact that StartRegen didn't stop the existing task. If they want to continue using that behavior, they now just need to add -- a "false" flag as the last parameter of their StartRegen call. Generally, we want to restart the task, though. if interruptcurrentregen ~= false then self:StopRegen() end if self.regen == nil then self.regen = {} end self.regen.amount = amount self.regen.period = period if self.regen.task == nil then self.regen.task = self.inst:DoPeriodicTask(self.regen.period, DoRegen, nil, self) end end ok so i found this, i tried to use this and this function Health:StopRegen() --print("Health:StopRegen") if self.regen ~= nil then if self.regen.task ~= nil then --print(" stopping task") self.regen.task:Cancel() self.regen.task = nil end self.regen = nil end end but sadly im not sure what im doing, atm the files look like this (when i try to start the server it hard crashes) local SLEEP = GLOBAL.Action() SLEEP.str = "sleep" SLEEP.id = "SLEEP" SLEEP.fn = function(act) if not act.target:HasTag("busy") then act.target.sg:GoToState("sleep") act.target:AddComponent("Health:StartRegen"(5,100) return false end end end AddAction(SLEEP) local WAKEUP = GLOBAL.Action() WAKEUP.str = "Wakeup" WAKEUP.id = "WAKEUP" WAKEUP.fn = function(act) act.target.sg:GoToState("wake") act.target:AddComponent("Health:StopRegen") end AddAction(WAKEUP) local function wakeup(player) GLOBAL.BufferedAction(player, player, GLOBAL.ACTIONS.WAKEUP):Do() end AddModRPCHandler("leifworkaround", "Wakeup", wakeup) Edited February 23, 2019 by chaosdc123 Link to comment Share on other sites More sharing options...
chaosdc123 Posted February 23, 2019 Author Share Posted February 23, 2019 i just found the fix, it was simple, he put min hunger to be 50, which is 50x the current hunger, so i made it 0.25 and it worked like a charm 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