Well-met Posted June 18, 2021 Share Posted June 18, 2021 Hello For my character I edited a part of SGWilson.lua and copied the file and then put it in my mod. EventHandler("knockback", function(inst, data) if not (inst.components.health:IsDead() or inst:HasTag("wereplayer") or inst:HasTag("buffed")) then if inst.sg:HasStateTag("parrying") then inst.sg.statemem.parrying = true inst.sg:GoToState("parry_knockback", { timeleft = (inst.sg.statemem.task ~= nil and GetTaskRemaining(inst.sg.statemem.task)) or (inst.sg.statemem.timeleft ~= nil and math.max(0, inst.sg.statemem.timeleft + inst.sg.statemem.timeleft0 - GetTime())) or inst.sg.statemem.parrytime, knockbackdata = data, }) else inst.sg:GoToState((data.forcelanded or inst.components.inventory:ArmorHasTag("heavyarmor") or inst:HasTag("heavybody")) and "knockbacklanded" or "knockback", data) end end end), The ("buffed") tag is what's new. The problem is this requires me to remake the file and edit the entry every single time Klei does an update. My question is how can I remove this dependency on a clone file and instead put that stuff directly in my modmain? Link to comment Share on other sites More sharing options...
Monti18 Posted June 19, 2021 Share Posted June 19, 2021 I'm not sure, but I think you can use AddStategraphEvent and enter your event and it will overwrite the one in the SGWilson file. 2 Link to comment Share on other sites More sharing options...
Well-met Posted June 19, 2021 Author Share Posted June 19, 2021 8 hours ago, Monti18 said: I'm not sure, but I think you can use AddStategraphEvent and enter your event and it will overwrite the one in the SGWilson file. -- Knockback immunity AddStategraphEvent("SGwilson", Class EventHandler("knockback", function(inst, data) if not (inst.components.health:IsDead() or inst:HasTag("wereplayer") or inst:HasTag("buffed")) then if inst.sg:HasStateTag("parrying") then inst.sg.statemem.parrying = true inst.sg:GoToState("parry_knockback", { timeleft = (inst.sg.statemem.task ~= nil and GetTaskRemaining(inst.sg.statemem.task)) or (inst.sg.statemem.timeleft ~= nil and math.max(0, inst.sg.statemem.timeleft + inst.sg.statemem.timeleft0 - GetTime())) or inst.sg.statemem.parrytime, knockbackdata = data, }) else inst.sg:GoToState((data.forcelanded or inst.components.inventory:ArmorHasTag("heavyarmor") or inst:HasTag("heavybody")) and "knockbacklanded" or "knockback", data) end end end), Tried this, but as usual something's wrong and it crashes (lua is fun) Link to comment Share on other sites More sharing options...
Monti18 Posted June 19, 2021 Share Posted June 19, 2021 (edited) -- Knockback immunity AddStategraphEvent("SGwilson", GLOBAL.EventHandler("knockback", function(inst, data) if not (inst.components.health:IsDead() or inst:HasTag("wereplayer") or inst:HasTag("buffed")) then if inst.sg:HasStateTag("parrying") then inst.sg.statemem.parrying = true inst.sg:GoToState("parry_knockback", { timeleft = (inst.sg.statemem.task ~= nil and GetTaskRemaining(inst.sg.statemem.task)) or (inst.sg.statemem.timeleft ~= nil and math.max(0, inst.sg.statemem.timeleft + inst.sg.statemem.timeleft0 - GetTime())) or inst.sg.statemem.parrytime, knockbackdata = data, }) else inst.sg:GoToState((data.forcelanded or inst.components.inventory:ArmorHasTag("heavyarmor") or inst:HasTag("heavybody")) and "knockbacklanded" or "knockback", data) end end end) ) This works, Class had nothing to do there, as you directly add it to the stategraph class and EventHandler needed the GLOBAL and a ) was missing at the end. Edited June 19, 2021 by Monti18 1 1 Link to comment Share on other sites More sharing options...
Well-met Posted June 19, 2021 Author Share Posted June 19, 2021 1 hour ago, Monti18 said: -- Knockback immunity AddStategraphEvent("SGwilson", GLOBAL.EventHandler("knockback", function(inst, data) if not (inst.components.health:IsDead() or inst:HasTag("wereplayer") or inst:HasTag("buffed")) then if inst.sg:HasStateTag("parrying") then inst.sg.statemem.parrying = true inst.sg:GoToState("parry_knockback", { timeleft = (inst.sg.statemem.task ~= nil and GetTaskRemaining(inst.sg.statemem.task)) or (inst.sg.statemem.timeleft ~= nil and math.max(0, inst.sg.statemem.timeleft + inst.sg.statemem.timeleft0 - GetTime())) or inst.sg.statemem.parrytime, knockbackdata = data, }) else inst.sg:GoToState((data.forcelanded or inst.components.inventory:ArmorHasTag("heavyarmor") or inst:HasTag("heavybody")) and "knockbacklanded" or "knockback", data) end end end) ) This works, Class had nothing to do there, as you directly add it to the stategraph class and EventHandler needed the GLOBAL and a ) was missing at the end. It doesn't crash but it also doesn't do the expected effect. To test this one can c_spawn "propsign" and c_spawn "pigelite1" Link to comment Share on other sites More sharing options...
Monti18 Posted June 19, 2021 Share Posted June 19, 2021 I'm not sure what exactly this should do. How do you get the tag buffed? Do you want the pigs to not knock you back? Perhaps try to explain it a bit more and I can help. 1 Link to comment Share on other sites More sharing options...
Well-met Posted June 19, 2021 Author Share Posted June 19, 2021 If a character has "buffed" then it should be immune to push effects yes that is my goal. In the base game the only instances for this is in the pig mini-game or the Forge, but mods like Uncompromising Mode make much use of knockback. I see no reason your code shouldnt work (yes my character has "buffed") so this is really weird Link to comment Share on other sites More sharing options...
Monti18 Posted June 19, 2021 Share Posted June 19, 2021 Ah ok I see! I see the error, I completely overlooked it before, you need to add the stategraph event to wilson and not SGwilson. So the working code is AddStategraphEvent("wilson", GLOBAL.EventHandler("knockback", function(inst, data) if not (inst.components.health:IsDead() or inst:HasTag("wereplayer") or inst:HasTag("buffed")) then if inst.sg:HasStateTag("parrying") then inst.sg.statemem.parrying = true inst.sg:GoToState("parry_knockback", { timeleft = (inst.sg.statemem.task ~= nil and GetTaskRemaining(inst.sg.statemem.task)) or (inst.sg.statemem.timeleft ~= nil and math.max(0, inst.sg.statemem.timeleft + inst.sg.statemem.timeleft0 - GetTime())) or inst.sg.statemem.parrytime, knockbackdata = data, }) else inst.sg:GoToState((data.forcelanded or inst.components.inventory:ArmorHasTag("heavyarmor") or inst:HasTag("heavybody")) and "knockbacklanded" or "knockback", data) end end end) ) I just checked it and I didn't get knocked back. 1 1 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