Tesumoto Posted May 28, 2018 Share Posted May 28, 2018 (edited) Hello everyone. I need your help. I have this function: local remove_hauntable_from = { 'beebox', 'treasurechest', 'cookpot', 'researchlab', 'researchlab2', 'meatrack', 'grass', 'twig', 'berrybush', 'berrybush2', 'sapling', 'red_mushroom', 'green_mushroom', } local Hauntables = GetModConfigData("Hauntables") local function RemoveHauntable(inst) if inst and inst.components.hauntable and (Hauntables == 1) then inst:RemoveComponent('hauntable') end end for k,name in pairs(remove_hauntable_from) do AddPrefabPostInit(name, RemoveHauntable) end She allows to forbid ghosts to interact with specified things.But I want the forbid to apply to everything except the prefabs I chose. Ghosts could only interact with "multiplayer_portal" and "amulet". Edited May 28, 2018 by Tezumoto Link to comment Share on other sites More sharing options...
ptr Posted May 28, 2018 Share Posted May 28, 2018 local hauntable_list = { multiplayer_portal = 1, amulet = 1, } local Hauntables = GetModConfigData("Hauntables") local function RemoveHauntable(inst) if inst and not hauntable_list[inst.prefab] and inst.components.hauntable and (Hauntables == 1) then inst:RemoveComponent('hauntable') end end AddPrefabPostInitAny(RemoveHauntable) Link to comment Share on other sites More sharing options...
Tesumoto Posted May 29, 2018 Author Share Posted May 29, 2018 (edited) On 29.05.2018 at 1:14 AM, ptr said: local hauntable_list = { multiplayer_portal = 1, amulet = 1, } local Hauntables = GetModConfigData("Hauntables") local function RemoveHauntable(inst) if inst and not hauntable_list[inst.prefab] and inst.components.hauntable and (Hauntables == 1) then inst:RemoveComponent('hauntable') end end AddPrefabPostInitAny(RemoveHauntable) The server crashes from time to time. [00:03:29]: [string "scripts/brains/stagehandbrain.lua"]:24: attempt to index field 'hauntable' (a nil value) LUA ERROR stack traceback: scripts/brains/stagehandbrain.lua:24 in (field) fn (Lua) <24-24> scripts/behaviourtree.lua:200 in (method) Visit (Lua) <199-205> scripts/behaviourtree.lua:643 in (method) Visit (Lua) <633-664> scripts/behaviourtree.lua:578 in (method) Visit (Lua) <554-610> scripts/behaviourtree.lua:22 in (method) Update (Lua) <20-27> scripts/brain.lua:212 in (method) OnUpdate (Lua) <205-214> scripts/brain.lua:135 in (method) Update (Lua) <105-147> scripts/update.lua:222 in () ? (Lua) <149-228> Edited May 29, 2018 by Tezumoto Link to comment Share on other sites More sharing options...
ptr Posted May 30, 2018 Share Posted May 30, 2018 Well, those prefabs are assumed to have hauntable, but you remove them, so that is what you should fix to make it work. Or you can play with hauntable it self, like Hauntable:SetOnHauntFn(function() return false end) Link to comment Share on other sites More sharing options...
Tesumoto Posted May 30, 2018 Author Share Posted May 30, 2018 14 minutes ago, ptr said: Well, those prefabs are assumed to have hauntable, but you remove them, so that is what you should fix to make it work. Or you can play with hauntable it self, like Hauntable:SetOnHauntFn(function() return false end) You can tell in more detail how to use "Hauntable: SetOnHauntFn (function () return false end)"? I'm not good at this. Link to comment Share on other sites More sharing options...
ptr Posted May 30, 2018 Share Posted May 30, 2018 replace inst:RemoveComponent('hauntable') with inst.components.hauntable:SetOnHauntFn(function() return false end) But I have not tested it Link to comment Share on other sites More sharing options...
Tesumoto Posted May 30, 2018 Author Share Posted May 30, 2018 (edited) 1 hour ago, ptr said: replace inst:RemoveComponent('hauntable') with inst.components.hauntable:SetOnHauntFn(function() return false end) But I have not tested it These changes do not cause crash of game, but ghosts can interact with everything. Can make an exception for "stagehandbrain.lua"? Or is it difficult? Edited May 30, 2018 by Tezumoto Link to comment Share on other sites More sharing options...
Tesumoto Posted May 30, 2018 Author Share Posted May 30, 2018 (edited) Maybe don't remove component and just remove Tag("haunted")? It seems this code fixed crash of game. local hauntable_list = { multiplayer_portal = 1, amulet = 1, stagehand = 1, } local Hauntables = GetModConfigData("Hauntables") local function RemoveHauntable(inst) if inst and not hauntable_list[inst.prefab] and inst.components.hauntable and (Hauntables == 1) then inst:RemoveComponent('hauntable') end end AddPrefabPostInitAny(RemoveHauntable) But this is not a full fix, but a crutches. Edited May 30, 2018 by Tezumoto Link to comment Share on other sites More sharing options...
ptr Posted May 30, 2018 Share Posted May 30, 2018 Try this local hauntable_list = { multiplayer_portal = 1, amulet = 1, } local function RemoveHauntable(inst) if inst and not hauntable_list[inst.prefab] and inst.components.hauntable then inst:AddTag("haunted") end end AddPrefabPostInitAny(RemoveHauntable) Link to comment Share on other sites More sharing options...
Tesumoto Posted May 30, 2018 Author Share Posted May 30, 2018 1 hour ago, ptr said: Try this local hauntable_list = { multiplayer_portal = 1, amulet = 1, } local function RemoveHauntable(inst) if inst and not hauntable_list[inst.prefab] and inst.components.hauntable then inst:AddTag("haunted") end end AddPrefabPostInitAny(RemoveHauntable) Everything works without errors, big thanks for your help. 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