Sign in to follow this  
Fool97

Show vehicle blips all over the map without lag

Recommended Posts

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 by Fool97

Share this post


Link to post

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 by idarrr
little mistake

Share this post


Link to post
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 by Fool97

Share this post


Link to post
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.

  • Like 1

Share this post


Link to post
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.

Share this post


Link to post

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.

Share this post


Link to post

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. 

Share this post


Link to post

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.