. . . Posted July 21, 2017 Share Posted July 21, 2017 (edited) Hello, I would like to know if there's a way to disable the carefulwalker component then re-enable it someway on player? I tried removing it, but removing it crashes the game. Edited July 21, 2017 by SuperDavid Link to comment Share on other sites More sharing options...
ZupaleX Posted July 21, 2017 Share Posted July 21, 2017 Maybe instead of removing the component you should see which part you want to disable and target only that. What do you want to do? Link to comment Share on other sites More sharing options...
. . . Posted July 21, 2017 Author Share Posted July 21, 2017 When my character has certain value I would like for the component to be ignored, or at least my character doesn't get a speed penalty & play that carefulwalker animation. Since it doesn't really make sense for when my character jumping to get slowed by the ground xD.. Link to comment Share on other sites More sharing options...
ZupaleX Posted July 21, 2017 Share Posted July 21, 2017 Unverified but my assumption is that this line in the carefulwalker.lua component is doing the job inst:ListenForEvent("unevengrounddetected", OnUnevenGroundDetected) You could do a RemoveEventCallback on the function which is called when the event "unevengrounddetected" is caught by the character. When you want to re-enable it, you can add the ListenForEvent again. The tricky part if you don't want to do dirty business is to recover the original OnUnevenGroundDetected which is a local function. Link to comment Share on other sites More sharing options...
. . . Posted July 21, 2017 Author Share Posted July 21, 2017 Well I just edited the carefulwalker.lua to not effect things that have a jumping value, since I couldn't think of anything else other than Spoiler inst:ListenForEvent("unevengrounddetected", function(inst, data) inst.components.carefulwalker:OnRemoveFromEntity() end) which didn't work. I guess this problem is solved now, even though copy-paste game files then editing them is bad, but whatever . Link to comment Share on other sites More sharing options...
ZupaleX Posted July 21, 2017 Share Posted July 21, 2017 That's a very bad practice indeed. This will make your mod incompatible with any other mod doing something to that component. I will come up with a more elegant solution a bit later but right now I am off to prepare dinner Link to comment Share on other sites More sharing options...
code4240 Posted July 22, 2017 Share Posted July 22, 2017 Yeah I agree, you shouldn't even let the thought of editing a file enter your head. If you get an idea that requires this and you'd not doing a massive overhaul mod or something you should just immediately throw it out. Anyway these functions should do the trick. local function remove_ground_listener(inst) inst.uneven_ground_holder = inst.event_listeners["unevengrounddetected"][inst][1] inst.event_listeners["unevengrounddetected"][inst][1] = function() --print("This function has been nullified") end end local function restore_ground_listener(inst) inst.event_listeners["unevengrounddetected"][inst][1] = inst.uneven_ground_holder end it worked ingame for me but I didn't put any checks to prevent errors so you might have to work on that if you ever get crashes due to one of these values not being there or something. Link to comment Share on other sites More sharing options...
. . . Posted July 22, 2017 Author Share Posted July 22, 2017 (edited) 24 minutes ago, code4240 said: Anyway these functions should do the trick. local function remove_ground_listener(inst) inst.uneven_ground_holder = inst.event_listeners["unevengrounddetected"][inst][1] inst.event_listeners["unevengrounddetected"][inst][1] = function() --print("This function has been nullified") end end local function restore_ground_listener(inst) inst.event_listeners["unevengrounddetected"][inst][1] = inst.uneven_ground_holder end it worked ingame for me This code seems to have delay before not being affected by sinkhole penalty unlike edit to carefulwalker.lua? Since if my character jumps while kinda close to a sinkhole then goes over it he gets slow for half a second. But thank you for your help man & maybe you can help me with something which shouldn't be very difficult to do but I have no idea how to do it xD.. So, I edited grue.lua component to just add this check over the sanity penalty in it's OnUpdate function when it hits an entity if self.inst.components.sanity then self.inst.components.sanity:DoDelta(-TUNING.SANITY_MEDLARGE) end since I have some entities which can be hit by grue, but don't have Sanity thus crashing the game. Maybe you know how I can do this without editing grue.lua xD? Edited July 22, 2017 by SuperDavid Link to comment Share on other sites More sharing options...
code4240 Posted July 22, 2017 Share Posted July 22, 2017 10 minutes ago, SuperDavid said: This code seems to have delay before not being affected by sinkhole penalty unlike edit to carefulwalker.lua? Since if my character jumps while kinda close to a sinkhole then goes over it he gets slow for like half the jump. The carefulwalker component just activates/deactivates itself when the event happens so you could try manually calling the code to deactivate it inside the remover function: if inst.components.carefulwalker:IsCarefulWalking() then inst.components.carefulwalker:ToggleCareful(false) end And to do the opposite in the restore function by finding the nearest entities with the unevenground component and manually pushing the event (after reenabling the function): -- Find the nearest entities with the component. -- This could be easier if all entities with this component have a tag, but I don't know if they do and I'm -- not going to dig through every single entity that has this component to find out. -- The event gets pushed roughly 2 or 3 times per second so you can use a pretty small radius. local ents = FindEntity(inst, radius, function(guy) return guy.components.unevenground ~= nil end ) for i, k in pairs(ents) do -- Reset the entities so they will immediately call the event k:Disable() k:Enable() end You could also duplicate the OnNotifyNearbyPlayers function that's in unevenground instead of resetting the entity, but it's a local-only function so there's no way to call it from outside. If you duplicated it you'd have to change it if this function was ever changed in an update. DISCLAIMER: I don't really have a convenient way to test this, so I don't know if it will actually work. This is just the first thing I'd think to do. Link to comment Share on other sites More sharing options...
code4240 Posted July 22, 2017 Share Posted July 22, 2017 (edited) 56 minutes ago, SuperDavid said: since I have some entities which can be hit by grue, but don't have Sanity thus crashing the game. Maybe you know how I can do this without editing grue.lua xD? I think the easiest way would be to give your NPC the sanity component and just set inst.components.sanity.ignore = true. I found this when I was looking at how to override the DoDelta function in sanity.lua and noticed it was checking an ignore variable and cancelling if it was true. I'm not sure if this is being called anywhere else in the entityscript though, so you might have to check for that. Edited July 22, 2017 by code4240 Link to comment Share on other sites More sharing options...
ZupaleX Posted July 22, 2017 Share Posted July 22, 2017 For the carefulwalker, removing the function which triggers it should do the job. Though a nicer way to write it way would be -- in your prefab post init. Comment: that will only work though assuming there is only 1 listener to that event inst.uneven_ground_holder = inst.event_listeners["unevengrounddetected"][inst][1] --When you want to disable it inst:RemoveEventCallback("unevengrounddetected", inst.uneven_ground_holder) -- When you want to reactivate it inst:ListenForEvent("unevengrounddetected", inst.uneven_ground_holder) This should prevent a delay if you disable the callback early enough. The only reason I could see a delay would be if the component is still being updated for some reason. Another method which is more radical but should work without delay and risk of the carefulwalker being toggled back on would be -- in your prefab post init. inst.OriginalOnUpdateCarefulWalker = inst.components.carefulwalker.OnUpdate --When you want to disable it inst.components.carefulwalker:ToggleCareful(false) inst.components.carefulwalker.OnUpdate = function(dt) return end -- When you want to reactivate it inst.components.carefulwalker.OnUpdate = inst.OriginalOnUpdateCarefulWalker Not sure what you try to achieve with the sanity thing. You want your character to ignore sanity loss when hit by charlie? Link to comment Share on other sites More sharing options...
. . . Posted July 22, 2017 Author Share Posted July 22, 2017 1 minute ago, ZupaleX said: Not sure what you try to achieve with the sanity thing. You want your character to ignore sanity loss when hit by charlie? It's a NPC character & since they don't have Sanity but have the grue component they crash the game when hit by the grue. So if the NPC could ignore the sanity loss that would be great ! 2 minutes ago, ZupaleX said: -- in your prefab post init. inst.OriginalOnUpdateCarefulWalker = inst.components.carefulwalker.OnUpdate By prefab post init where exactly do you mean, do I have to add prefab postinit inside sinkholes or something? Link to comment Share on other sites More sharing options...
ZupaleX Posted July 22, 2017 Share Posted July 22, 2017 (edited) Quote It's a NPC character & since they don't have Sanity but have the grue component they crash the game when hit by the grue. So if the NPC could ignore the sanity loss that would be great ! But if the NPC doesn't have sanity, there is nothing to ignore? I am confused. Quote By prefab post init where exactly do you mean, do I have to add prefab postinit inside sinkholes or something? You should put that in the post init of the entity listening to the "onunevenground" event. Then if it should apply only to your own character, you should put that in your master_postinit function. Edited July 22, 2017 by ZupaleX Link to comment Share on other sites More sharing options...
. . . Posted July 22, 2017 Author Share Posted July 22, 2017 6 minutes ago, ZupaleX said: You should put that in the post init of the entity listening to the "onunevenground" event. Then if it should apply only to your own character, you should put that in your master_postinit function. Your code worked with 0 delay!! Thank you very much !!! 7 minutes ago, ZupaleX said: But if the NPC doesn't have sanity, there is nothing to ignore? I am confused. Well let me say in more detail, so I have an NPC which does not posses Sanity, but has the "grue" component to get hit in darkness. Normally the grue component doesn't have any "if" check to see if the entity it's hitting as sanity or not in its OnUpdate function. So when my NPC gets hit by the grue the game crashes because there's no Sanity to give a penalty to on my NPC. So, I was wondering if there was a way I can make that crash not happen? And thanks so much for your help ZupaleX !! Link to comment Share on other sites More sharing options...
ZupaleX Posted July 22, 2017 Share Posted July 22, 2017 Glad it worked for the carefulwalker. Did you end up having to override the OnUpdate function? About the sanity issue I guess code4240 suggestion is the easiest to do. Link to comment Share on other sites More sharing options...
. . . Posted July 22, 2017 Author Share Posted July 22, 2017 1 minute ago, ZupaleX said: Glad it worked for the carefulwalker. Did you end up having to override the OnUpdate function? Yes I did. 1 minute ago, ZupaleX said: About the sanity issue I guess code4240 suggestion is the easiest to do. If I put " inst.components.sanity.ignore = true " will that make the NPC's Sanity not go down from DoDelta's too or will those still lower their Sanity? Link to comment Share on other sites More sharing options...
ZupaleX Posted July 22, 2017 Share Posted July 22, 2017 function Sanity:DoDelta(delta, overtime) if self.redirect ~= nil then self.redirect(self.inst, delta, overtime) return end if self.ignore then return end [...] end So I would say yes! 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