Administrators Lpsd Posted December 10, 2016 Administrators Share Posted December 10, 2016 (edited) I was wondering if there's a way to detect when an element has been created, via events. then I found this from 2009, looks like they decided not to implement it, https://bugs.mtasa.com/view.php?id=4591#c25041 If not by handler, is it possible to replicate this kind of feature? Would be really useful imo. Edited December 10, 2016 by LopSided_ Link to comment
Captain Cody Posted December 10, 2016 Share Posted December 10, 2016 (edited) You can try this; I'm not sure of the performance impact it would have though. -- Table to store current elements Elements = {} -- Type of element you want to search for Type = "object" -- Factor in already created objects -- for i,v in pairs(getElementsByType(Type)) do Elements[v] = true end -- Every secound check for new elements -- setTimer ( function() for i,v in pairs(getElementsByType(Type)) do if not Elements[v] then Elements[v] = true triggerCreated(v) end end end, 1000, 0 ) -- Output chat box the elements data if it was newly created -- function triggerCreated(element) outputChatBox(tostring(element).." Created") end Edited December 10, 2016 by CodyL 1 Link to comment
Administrators Lpsd Posted December 10, 2016 Author Administrators Share Posted December 10, 2016 11 minutes ago, CodyL said: You can try this; I'm not sure of the performance impact it would have though. -- Table to store current elements Elements = {} -- Type of element you want to search for Type = "object" -- Factor in already created objects -- for i,v in pairs(getElementsByType(Type)) do Elements[v] = true end -- Every secound check for new elements -- setTimer ( function() for i,v in pairs(getElementsByType(Type)) do if not Elements[v] then Elements[v] = true triggerCreated(v) end end end, 1000, 0 ) -- Output chat box the elements data if it was newly created -- function triggerCreated(element) outputChatBox(tostring(element).." Created") end Just what I was looking for, thanks. Link to comment
Captain Cody Posted December 10, 2016 Share Posted December 10, 2016 If you need a faster or a slower response time, lower the 1000 interval. To low may cause some performance impacts due to it looping through every thing of that object type every time that is triggered though. 1 Link to comment
Administrators Lpsd Posted December 10, 2016 Author Administrators Share Posted December 10, 2016 Small problem when trying to output/retrieve object's co-ordinates -- Table to store current elements Elements = {} -- Type of element you want to search for Type = "spawnpoint" -- Factor in already created objects -- for i,v in pairs(getElementsByType(Type)) do Elements[v] = true end -- Every secound check for new elements -- setTimer ( function() for i,v in pairs(getElementsByType(Type)) do if not Elements[v] then Elements[v] = true triggerCreated(v) end end end, 1000, 0 ) function triggerCreated(element) outputChatBox(tostring(element).." Created") local x, y, z = getElementPosition ( element ) outputChatBox("x: " .. x .. ", y: " .. y .. ", z: ".. z) end "tostring(element)" gives me "userdata: 000002CD", or similar (the numbers/letters change each time a new element is made) Therefore, I can't use that with getElementPosition. Any suggestions? Link to comment
Captain Cody Posted December 10, 2016 Share Posted December 10, 2016 tostring element outputs the userdata of the element element is the element itself if you want remove the outputchatbox tostring(element) Link to comment
Administrators Lpsd Posted December 10, 2016 Author Administrators Share Posted December 10, 2016 14 minutes ago, CodyL said: tostring element outputs the userdata of the element element is the element itself if you want remove the outputchatbox tostring(element) Sorry, I didn't explain myself properly. I was using this: local x, y, z = getElementPosition ( element ) However, x y & z are all 0. Link to comment
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