Somnei Posted August 28, 2022 Share Posted August 28, 2022 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. Link to comment Share on other sites More sharing options...
Leonidas IV Posted August 29, 2022 Share Posted August 29, 2022 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) Link to comment Share on other sites More sharing options...
Somnei Posted August 29, 2022 Author Share Posted August 29, 2022 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. Link to comment Share on other sites More sharing options...
KXWl1 Posted August 31, 2022 Share Posted August 31, 2022 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. Link to comment Share on other sites More sharing options...
Somnei Posted August 31, 2022 Author Share Posted August 31, 2022 17 minutes ago, KXWl1 said: You can try to print something and see if it shows on console. Very good tip for debugging! I always make sure to use a lot of prints when I am stuck on a problem. Link to comment Share on other sites More sharing options...
Boogiepop210 Posted November 16, 2022 Share Posted November 16, 2022 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.