Jump to content

blip help


Dimos7

Recommended Posts

--[[*****************************************************************************
*
*  PROJECT:     VehicleBlips
*  LICENSE:     GNU GPLv3
*  FILE:        :VehicleBlips/cVehicleBlips.lua
*  PURPOSE:     Vehicle blips.
*  DEVELOPERS:  John_Michael <[email protected]>
*  
********************************************************************************]]
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, 300)
			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, 300)
	setElementParent(blip, vehicleBlipRoot)
	addEventHandler("onClientElementStreamOut", source, streamOut)
	addEventHandler("onClientElementDestroy", source, streamOut)
end
addEventHandler("onClientElementStreamIn", root, streamIn)

addEventHandler("onClientVehicleEnter", root,
function()
	 for p, v in ipairs(getElementByType("player")) do 
	    for k  , blip in ipairs()) do
	        destroyElement(blip)
        end
	end
end)

When someone enters a vehicle, the blip of that specific vehicle should be disabled. Other vehicle blips should still appear ofcourse. When the person leaves the vehicle, the blip should appear again. It doesn't work somehow, could someone help me with this?

Edited by Dimos7
Link to comment
34 minutes ago, Dimos7 said:

for k , blip in ipairs()) do

That's nonsense.

Try it like this:

addEventHandler("onClientVehicleEnter", root,
function()
	for k,v in ipairs(getAttachedElements(source))do
		if(getElementType(v) == "blip")then
			destroyElement(v)
		end
	end
end)

Also I believe you want to call your streamIn function from onClientVehicleExit event handler too.

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...