Jump to content

Show vehicle blips all over the map without lag


Fool97

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
Link to comment

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
Link to comment
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
Link to comment
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
Link to comment
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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...