Jump to content

hitElement ou thePlayer?


Recommended Posts

fiz o seguinte script, porém da erro no getPedOccupiedVehicle, no getElementData e no removeEventHandler. Alguém sabe dizer qual o erro?

function entrega2(hitElement, matchingDimension )
    local v = getPedOccupiedVehicle(hitElement) 
    if getElementData(v,"Carregado") == true then
        setElementFrozen(v,true)
        outputChatBox("Espere o veículo ser descarregado!",hitElement,0,0,150)
        setElementData(v,"Carregado",false)
        destroyElement(finalm2)
        destroyElement(blip2)
        setTimer(function (hitElement, matchingDimension )
            if isElementFrozen(hitElement) == true then
                setElementFrozen(hitElement,false)
                givePlayerMoney(hitElement,math.random(1500,3500))
                removeEventHandler("onVehicleExit",source,remove2)
            end
        end,3500,1,hitElement) 
        removeEventHandler("onMarkerHit",source,entrega2) 
    end
end

 

Link to comment
  • Other Languages Moderators

Faltou verificar se hitElement é um jogador.

function entrega2 (hitElement, matchingDimension)
	if (hitElement and getElementType (hitElement) == "player") then
		local v = getPedOccupiedVehicle (hitElement) 
		if getElementData (v, "Carregado") == true then
			setElementFrozen (v, true)
			outputChatBox ("Espere o veículo ser descarregado!", hitElement, 0, 0, 150)
			setElementData (v, "Carregado", false)
			destroyElement (finalm2)
			destroyElement (blip2)
			setTimer (function (theHitElement, theSource)
				if isElementFrozen (theHitElement) then
					setElementFrozen (theHitElement, false)
					givePlayerMoney (theHitElement, math.random (1500,3500))
					removeEventHandler ("onVehicleExit", theSource, remove2)
				end
			end, 3500, 1, hitElement, source)
			removeEventHandler ("onMarkerHit", source, entrega2)
		end
	end
end

 

  • Thanks 1
Link to comment

Tente:

function entrega2(hitElement, matchingDimension )
	if getElementType(hitElement) ~= "player" then return end
	local v = getPedOccupiedVehicle(hitElement)
	if v and getElementData(v,"Carregado") == true then
		setElementFrozen(v,true)
		outputChatBox("Espere o veículo ser descarregado!",hitElement,0,0,150)
		setElementData(v,"Carregado",false)
		destroyElement(finalm2) -- se "finalm2" for a marker deste evento source vai causar erro
		destroyElement(blip2)
		setTimer(function (marker)
			if not (isElement(hitElement)) then return end
			if isElementFrozen(v) then
				setElementFrozen(v,false)
				givePlayerMoney(hitElement,math.random(1500,3500))
				removeEventHandler("onVehicleExit",marker,remove2) -- certifique-se que a função 'remove2' esteja definida
			end
		end,3500,1,source)
		removeEventHandler("onMarkerHit",source,entrega2) 
	end
end

 

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