Jump to content

Listen for event?


Recommended Posts

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

 

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

  • Developer

 

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

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 here

end

AddPrefabPostInit("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

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 init

inst:AddComponent("hauntable")
Link to comment
Share on other sites

@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

 

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...