Skarbonke

[HELP]VehicleBlips

Recommended Posts

Hello, I want that this resource would show the blips in the minimap, but not in the F11 or just cars that are close, cuz now it's showin all the cars, and it's laggy

local vehicleBlipRoot = createElement("vehicleBlipRoot", "vehicleBlipRoot")

--This function creates a blip for all currently streamed-in vehicles when the resource starts.
local function resourceStart()
    for _, vehicle in ipairs(getElementsByType("vehicle"), root, true) do
        if vehicle ~= getPedOccupiedVehicle(localPlayer) then
            local blip = createBlipAttachedTo(vehicle, 0, 1, 150, 150, 150, 255, -10, 150)
            setElementParent(blip, vehicleBlipRoot)
        end
    end
end
addEventHandler("onClientResourceStart", root, resourceStart)

--This function destroys a vehicle's blip when it streams out.
local function streamOut()
    for _, blip in ipairs(getElementChildren(vehicleBlipRoot)) do
        if getElementAttachedTo(blip) == source then
            destroyElement(blip)
        end
    end
    removeEventHandler("onClientElementStreamOut", source, streamOut)
    removeEventHandler("onClientElementDestroy", source, streamOut)
end

--This function creates a blip when a vehicle streams in.
local function streamIn()
    if getElementType(source) ~= "vehicle" then
        return
    end
    
    --Check if the vehicle already has a blip.
    for _, blip in ipairs(getElementChildren(vehicleBlipRoot)) do
        if getElementAttachedTo(blip) == source then
            return
        end
    end
    
    local blip = createBlipAttachedTo(source, 0, 1, 150, 150, 150, 255, -10, 150)
    setElementParent(blip, vehicleBlipRoot)
    addEventHandler("onClientElementStreamOut", source, streamOut)
    addEventHandler("onClientElementDestroy", source, streamOut)
end
addEventHandler("onClientElementStreamIn", root, streamIn)

 

Share this post


Link to post
10 hours ago, IIYAMA said:

blip createBlipAttachedTo ( element elementToAttachTo [, int icon = 0, int size = 2, int r = 255, int g = 0, int b = 0, int a = 255, int ordering = 0, float visibleDistance = 99999.0] )

https://wiki.multitheftauto.com/wiki/CreateBlipAttachedTo


local vehicleBlipRoot = createElement("vehicleBlipRoot", "vehicleBlipRoot")

--This function creates a blip for all currently streamed-in vehicles when the resource starts.
local function resourceStart()
	for _, vehicle in ipairs(getElementsByType("vehicle"), root, true) do
		if vehicle ~= getPedOccupiedVehicle(localPlayer) then
			local blip = createBlipAttachedTo(vehicle, 0, 1, 150, 150, 150, 255, -10, 100)
			setElementParent(blip, vehicleBlipRoot)
		end
	end
end
addEventHandler("onClientResourceStart", root, resourceStart)

--This function destroys a vehicle's blip when it streams out.
local function streamOut()
	for _, blip in ipairs(getElementChildren(vehicleBlipRoot)) do
		if getElementAttachedTo(blip) == source then
			destroyElement(blip)
		end
	end
	removeEventHandler("onClientElementStreamOut", source, streamOut)
	removeEventHandler("onClientElementDestroy", source, streamOut)
end

--This function creates a blip when a vehicle streams in.
local function streamIn()
	if getElementType(source) ~= "vehicle" then
		return
	end
	
	--Check if the vehicle already has a blip.
	for _, blip in ipairs(getElementChildren(vehicleBlipRoot)) do
		if getElementAttachedTo(blip) == source then
			return
		end
	end
	
	local blip = createBlipAttachedTo )( element elementToAttachTo [, int icon = 0, int size = 2, int r = 255, int g = 0, int b = 0, int a = 255, int ordering = 0, float visibleDistance = 99999.0] )
	setElementParent(blip, vehicleBlipRoot)
	addEventHandler("onClientElementStreamOut", source, streamOut)
	addEventHandler("onClientElementDestroy", source, streamOut)
end
addEventHandler("onClientElementStreamIn", root, streamIn)

Just can't get it to work :|

 

Share this post


Link to post

That is the syntax of a function. It will tell you in which order you have to put the arguments and which values are allowed per argument.

You can't place it directly in your code... Pls study the examples a bit of that function on wiki. If you put some effort in it, you can figure it out.

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

  • Recently Browsing   0 members

    No registered users viewing this page.