Jump to content

Recommended Posts

Hi!

I want to know how to write a hook for when a mob starts to fight.

I'm guessing it's possible to simply add a "listenforevent" to the mob, but I'm unsure what events trigger during combat or how to find what events are available to listen for. Are there any files I can read that contain all events or something like that?

Or, if there is another, better, way - please let me know!

I just want to make the royal pig guards swap their torches if they fight during the night - which should be easy enough provided I can make a function trigger whenever they start to fight.

 

edit: So far I have tried listening for "attack", "onattack", "onattackother", "onhitother" and "doattack" with no luck.

Edited by Somnei

It's supposed to work, maybe you're not doing it right.

local function SwapEquip(inst, data)
  	print("Testing if it's run")
	--Stuff
end

AddPrefabPostInit("the_pig_prefab", function(inst)
	inst:ListenForEvent("onattack", SwapEquip)
end)

 

  • Like 1

Hm, that is strange. I wonder if the royal guards are just bugged somehow...

I wrote some code based on your example and it didn't work, so I then tried copying your code so mine was identical (replacing "the_pig_prefab" with "pigman_city" and "pigman_royalguard" as well to be on the safe side - still nothing.

I've made a workaround by instead adding an attackcallback on their weapon, but I'm just a bit puzzled as to why the other way isn't working for me.

On 8/30/2022 at 7:50 AM, Somnei said:

Hm, that is strange. I wonder if the royal guards are just bugged somehow...

I wrote some code based on your example and it didn't work, so I then tried copying your code so mine was identical (replacing "the_pig_prefab" with "pigman_city" and "pigman_royalguard" as well to be on the safe side - still nothing.

I've made a workaround by instead adding an attackcallback on their weapon, but I'm just a bit puzzled as to why the other way isn't working for me.

You can try to print something and see if it shows on console.

On 8/29/2022 at 2:24 PM, Leonidas IV said:
local function SwapEquip(inst, data)
  	print("Testing if it's run")
	--Stuff
end

AddPrefabPostInit("the_pig_prefab", function(inst)
	inst:ListenForEvent("onattack", SwapEquip)
end)

Its onattackother not onattack

  • Like 1

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
×
  • Create New...