Fool97 Posted November 19, 2017 Share Posted November 19, 2017 (edited) I'm trying to create a blip with a icon id of 51 in all the cars in my server, but as soon as I add more cars it starts lagging, how can I iterate through all of them without lagging?! addEventHandler("onClientElementStreamIn", root, function () for _, veh in pairs(getElementsByType("vehicle")) do createBlipAttachedTo(veh, 51, 2, 255, 0, 0, 255, 0) end end ) addEventHandler("onClientElementStreamOut", root, function () for _, v in pairs(getAttachedElements(source) ) do if (getElementType(v) == "blip") then destroyElement(v) end end end ) Edited November 19, 2017 by Fool97 Link to comment
idarrr Posted November 19, 2017 Share Posted November 19, 2017 (edited) I guess, its because you keep creating that blips when element streamed in. So you ended up having more than 1 blip attached to that vehicle I think. Why are you using onClientElementStreamIn may I ask? You can just set the visible distance on argument 8 (argument 9) so it doesn't show up on radar when it's too far away from you. Edited November 19, 2017 by idarrr little mistake Link to comment
Fool97 Posted November 19, 2017 Author Share Posted November 19, 2017 (edited) 17 minutes ago, idarrr said: I guess, its because you keep creating that blips when element streamed in. So you ended up having more than 1 blip attached to that vehicle I think. Why are you using onClientElementStreamIn may I ask? You can just set the visible distance on argument 8 so it doesn't show up on radar when it's too far away from you. I thought using onClientElementStreamIn would just run the code when a vehicle or player was streamed in, avoiding the creation of the blips all the time, but you're saying it gets created all the time, i don't get it now ... About the 8th argument, I want to keep seeing the cars in my map all the time, but only in GPS I want to restrict it to 1000m. Just solve this problem by adding the created blips in a table and checking if the size of the vehicle pool was different from the size of the vehicle table, and later checking for streamed out elements and removing the vehicles from the vehicle table. Sorry for bothering instead of thinking ... Edited November 19, 2017 by Fool97 Link to comment
idarrr Posted November 19, 2017 Share Posted November 19, 2017 3 minutes ago, Fool97 said: I thought using onClientElementStreamIn would just run the code when a vehicle or player was streamed in, avoiding the creation of the blips all the time, but you're saying it gets created all the time, i don't get it now ... About the 8th argument, I want to keep seeing the cars in my map all the time, but only in GPS I want to restrict it to 1000m. Actually, you can still see that blips on the map (F11) all the time even if you set the visible distance, but it won't show up on radar when it's out of range. If you are not sure about duplicated blips, you can just try: function seeAllBlips () for i, v in pairs(getElementsByType("blip")) do outputChatBox(inspect(i)) outputChatBox("Blip: "..inspect(v)) outputChatBox("Attached to: "..inspect(getElementAttachedTo(v)) end end addCommandHandler("blips", seeAllBlips) Debugging is important. 1 Link to comment
msyyn Posted November 20, 2017 Share Posted November 20, 2017 13 hours ago, idarrr said: Actually, you can still see that blips on the map (F11) all the time even if you set the visible distance, but it won't show up on radar when it's out of range. This is correct, the visibility range only affects radar indeed, so all blips are still visible on full map. Link to comment
lopezloo Posted November 20, 2017 Share Posted November 20, 2017 You are attaching blip to every vehicle on the server when any vehicle got streamed in. That doesn't make any sense. Remove that loop and do it only for source. Link to comment
pa3ck Posted November 20, 2017 Share Posted November 20, 2017 BTW: When you use getElementsByType on client side, there's an optional argument, "streamedIn", if you set this to true, only the streamed in vehicles will be returned. 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