Somnei Posted August 28, 2022 Share Posted August 28, 2022 (edited) 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 August 29, 2022 by Somnei Link to comment https://forums.kleientertainment.com/forums/topic/142891-how-do-i-listen-for-combat-on-a-prefab/ 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) 1 Link to comment https://forums.kleientertainment.com/forums/topic/142891-how-do-i-listen-for-combat-on-a-prefab/#findComment-1596256 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 https://forums.kleientertainment.com/forums/topic/142891-how-do-i-listen-for-combat-on-a-prefab/#findComment-1596266 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 https://forums.kleientertainment.com/forums/topic/142891-how-do-i-listen-for-combat-on-a-prefab/#findComment-1596449 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. 1 Link to comment https://forums.kleientertainment.com/forums/topic/142891-how-do-i-listen-for-combat-on-a-prefab/#findComment-1596451 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 1 Link to comment https://forums.kleientertainment.com/forums/topic/142891-how-do-i-listen-for-combat-on-a-prefab/#findComment-1610157 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