Eliminator Posted December 23, 2014 Share Posted December 23, 2014 (edited) I want to make something happen when you haunt a dead skeleton. How would I listen for that event? Edited December 26, 2014 by Eliminator Link to comment Share on other sites More sharing options...
przemolsz Posted December 23, 2014 Share Posted December 23, 2014 You can do it by calling AddHauntableCustomReaction function, like this:local function OnHaunt(haunted, haunter)--Place whatever you want it to do hereendAddPrefabPostInit("skeleton", function(inst)AddHauntableCustomReaction(inst, OnHaunt, false, false, false)end) Link to comment Share on other sites More sharing options...
Eliminator Posted December 23, 2014 Author Share Posted December 23, 2014 You can do it by calling AddHauntableCustomReaction function, like this:local function OnHaunt(haunted, haunter)endAddPrefabPostInit("skeleton", function(inst)AddHauntableCustomReaction(inst, OnHaunt, false, false, false)end)I tried that but I am getting this error:error calling PrefabPostInit: skeleton in mod skeleton (Skeleton Revive): [string "../mods/skeleton/modmain.lua"]:6: attempt to call global 'AddHauntableCustomReaction' (a nil value)LUA ERROR stack traceback: ../mods/skeleton/modmain.lua(6,1) =(tail call) ? =[C] in function 'xpcall' scripts/mods.lua(105,1) in function 'mod' scripts/mainfunctions.lua(140,1) =[C] in function 'SpawnPrefab' scripts/mainfunctions.lua(167,1) in function 'SpawnPrefab' scripts/mainfunctions.lua(174,1) in function 'SpawnSaveRecord' scripts/gamelogic.lua(661,1) in function 'PopulateWorld' scripts/gamelogic.lua(876,1) in function 'DoInitGame' scripts/gamelogic.lua(975,1) in function 'cb' ... =[C] in function 'GetPersistentString' scripts/saveindex.lua(90,1) in function 'Load' scripts/gamelogic.lua(1153,1) in function 'callback' scripts/playerprofile.lua(645,1) in function 'Set' scripts/playerprofile.lua(528,1) =[C] in function 'GetPersistentString' scripts/playerprofile.lua(526,1) in function 'Load' scripts/gamelogic.lua(1152,1) in main chunk =[C] in function 'require' scripts/mainfunctions.lua(663,1) Disabling skeleton (Skeleton Revive) because it had an error. Link to comment Share on other sites More sharing options...
Developer SethR Posted December 23, 2014 Developer Share Posted December 23, 2014 I tried that but I am getting this error Because that function is a utility function defined in standardcomponents.lua (i.e. in a separate space from your mod), you'll have to call GLOBAL.AddHauntableCustomReaction. Hope that helps! Link to comment Share on other sites More sharing options...
Eliminator Posted December 24, 2014 Author Share Posted December 24, 2014 Because that function is a utility function defined in standardcomponents.lua (i.e. in a separate space from your mod), you'll have to call GLOBAL.AddHauntableCustomReaction. Hope that helps!Thanks, it doesn't crash any more. You can do it by calling AddHauntableCustomReaction function, like this:local function OnHaunt(haunted, haunter)--Place whatever you want it to do hereendAddPrefabPostInit("skeleton", function(inst)AddHauntableCustomReaction(inst, OnHaunt, false, false, false)end) I did this but the skeleton is still not hauntable. When I try to haunt it, it just says "Examine skeleton". Link to comment Share on other sites More sharing options...
Sarcen Posted December 24, 2014 Share Posted December 24, 2014 Thanks, it doesn't crash any more. I did this but the skeleton is still not hauntable. When I try to haunt it, it just says "Examine skeleton". It probably means the skeleton doesnt have a hauntable component at all, add one in your skeleton initinst:AddComponent("hauntable") Link to comment Share on other sites More sharing options...
Eliminator Posted December 24, 2014 Author Share Posted December 24, 2014 It probably means the skeleton doesnt have a hauntable component at all, add one in your skeleton initinst:AddComponent("hauntable")Sorry, I just stated coding for don't starve. Whats my skeleton init? Link to comment Share on other sites More sharing options...
rezecib Posted December 24, 2014 Share Posted December 24, 2014 @Eliminator, Make a new line just before the OnHaunt function, and put it there. Link to comment Share on other sites More sharing options...
Eliminator Posted December 24, 2014 Author Share Posted December 24, 2014 @Eliminator, Make a new line just before the OnHaunt function, and put it there. I tried that but I get: "Attempted to index a global 'inst' (a nil value)" Link to comment Share on other sites More sharing options...
rezecib Posted December 24, 2014 Share Posted December 24, 2014 @Eliminator, Oh, oops, I would've defined the OnHaunt function inside the postinit, but looks like it wasn't written that way. Put it above AddHauntableCustomReaction instead. Link to comment Share on other sites More sharing options...
Eliminator Posted December 24, 2014 Author Share Posted December 24, 2014 @Eliminator, Oh, oops, I would've defined the OnHaunt function inside the postinit, but looks like it wasn't written that way. Put it above AddHauntableCustomReaction instead. I did this:AddPrefabPostInit("skeleton", function(inst)inst:AddComponent("hauntable")AddHauntableCustomReaction(inst, OnHaunt, false, false, false)end)Now it doesn't crash, but the skeleton is still not hauntable. Link to comment Share on other sites More sharing options...
Eliminator Posted December 25, 2014 Author Share Posted December 25, 2014 Bumb Link to comment Share on other sites More sharing options...
Eliminator Posted December 26, 2014 Author Share Posted December 26, 2014 Bump Link to comment Share on other sites More sharing options...
Kzisor Posted December 26, 2014 Share Posted December 26, 2014 You also have to set it for the player skeleton. AddPrefabPostInit("skeleton_player", function(inst)inst:AddComponent("hauntable")AddHauntableCustomReaction(inst, OnHaunt, false, false, false)end) Link to comment Share on other sites More sharing options...
Sarcen Posted December 26, 2014 Share Posted December 26, 2014 You also have to set it for the player skeleton.AddPrefabPostInit("skeleton_player", function(inst)inst:AddComponent("hauntable")AddHauntableCustomReaction(inst, OnHaunt, false, false, false)end) This makes sense, I knew there were two different types of skeletons, I just didnt think about it . I did look into AddHauntableCustomReaction, and that function adds the hauntable component if it does not exist. So my earlier suggestion is invalid (adding the inst:AddComponent("hauntable")), it was never required. 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