yanecc Posted September 8, 2024 Share Posted September 8, 2024 (edited) I've tried the code below for i, prefab in pairs({ "spat", "warg", "gingerbreadwarg" }) do AddPrefabPostInit(prefab, function(inst) if inst.event_listening and inst.event_listening.spawnedforhunt then table.insert(inst.event_listening.spawnedforhunt[inst], 1, OnSpawnedForHunt) else inst:ListenForEvent("spawnedforhunt", OnSpawnedForHunt) end end) end No error occurs, but it doesn't work. Edited September 8, 2024 by yanecc Link to comment https://forums.kleientertainment.com/forums/topic/159569-help-how-to-add-a-high-priority-event-listener-for-a-prefab/ Share on other sites More sharing options...
Rickzzs Posted September 8, 2024 Share Posted September 8, 2024 You missed half the code. Look at how ListenForEvent adds new listeners. function EntityScript:ListenForEvent(event, fn, source) --print ("Listen for event", self, event, source) source = source or self if not source.event_listeners then source.event_listeners = {} end AddListener(source.event_listeners, event, self, fn) if not self.event_listening then self.event_listening = {} end AddListener(self.event_listening, event, source, fn) end Link to comment https://forums.kleientertainment.com/forums/topic/159569-help-how-to-add-a-high-priority-event-listener-for-a-prefab/#findComment-1746544 Share on other sites More sharing options...
yanecc Posted September 8, 2024 Author Share Posted September 8, 2024 (edited) 52 minutes ago, Rickzzs said: You missed half the code. Look at how ListenForEvent adds new listeners. function EntityScript:ListenForEvent(event, fn, source) --print ("Listen for event", self, event, source) source = source or self if not source.event_listeners then source.event_listeners = {} end AddListener(source.event_listeners, event, self, fn) if not self.event_listening then self.event_listening = {} end AddListener(self.event_listening, event, source, fn) end Ah, Yes. Thank you very much. As you said I missed some code. So the full version is as below and it works as expected. if inst.event_listeners and inst.event_listeners.spawnedforhunt or inst.event_listening and inst.event_listening.spawnedforhunt then table.insert(inst.event_listeners.spawnedforhunt[inst], 1, OnSpawnedForHunt) table.insert(inst.event_listening.spawnedforhunt[inst], 1, OnSpawnedForHunt) else inst:ListenForEvent("spawnedforhunt", OnSpawnedForHunt) end Edited September 8, 2024 by yanecc Link to comment https://forums.kleientertainment.com/forums/topic/159569-help-how-to-add-a-high-priority-event-listener-for-a-prefab/#findComment-1746548 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