Jump to content

sistema trancar somente pelo dono, bug de entrar na moto mesmo trancada


Recommended Posts

boa noite amigos, estou com um problema que não estou conseguindo cancelar para o player não entrar numa bike trancada

client:

--[[

---ACESSE: https://vikingsmodsmta.blogspot.com/

--]]

local types = {
	["Automobile"] = true,
	["Bike"] = true,
	["Plane"] = true,
	["Helicopter"] = true,
	["Boat"] = true,
	["Train"] = true,
	["Monster Truck"] = true,
	["Quad"] = true
}


function playSounds(sounds, bool)
	if not bool then bool = false end
	if sounds == "ov" then
		beltSound = playSound("files/".. sounds ..".mp3", bool)
	else
	    playSound("files/".. sounds ..".mp3", bool)
	end
end

function processLockUnlock(vehicle)
local locked = isVehicleLocked(vehicle)
	if isPedInVehicle(localPlayer) and getElementData(vehicle, "Owner") == localPlayer then
	playSounds("lockin")
	elseif locked and getElementData(vehicle, "Owner") == localPlayer then 
	playSounds("lockout")
	end
	if locked and getElementData(vehicle, "Owner") == localPlayer then
	triggerServerEvent("vehicleLock", localPlayer,localPlayer, vehicle, false)
	outputChatBox("#1066E7[B9R - Veiculo]: #FFFFFFVeiculo destrancado!", 255, 255, 255, true)
	elseif not locked and getElementData(vehicle, "Owner") == localPlayer then 
	triggerServerEvent("vehicleLock", localPlayer,localPlayer, vehicle, true)
	outputChatBox("#1066E7[B9R - Veiculo]: #FFFFFFVeiculo trancado!", 255, 255, 255, true)
	end
end

function setVehicleLockState() --Função trancar o carro
	if klikkTimer then return end
	if isTimer(klikkTimerRun) then return end
	klikkTimer = true
	klikkTimerRun = setTimer(function()
		klikkTimer = false
	end,1000,1)
	local vehicle = getPedOccupiedVehicle ( localPlayer )
	if vehicle and getElementData(vehicle, "Owner") == localPlayer then
		processLockUnlock(vehicle)
	else
		local int2 = getElementInterior(localPlayer)
		local dim2 = getElementDimension(localPlayer)
		local mx,my,mz = getElementPosition(localPlayer)
			for k,v in ipairs(getElementsByType("vehicle")) do
				local x,y,z = getElementPosition(v)
				local int = getElementInterior(v)
				local dim = getElementDimension(v)
				local dist = getDistanceBetweenPoints3D(x,y,z,mx,my,mz)
				if dist <= 10 and int2 == int and dim2 == dim then
					processLockUnlock(v)
					return
				end
			end
	end
end
bindKey("l", "down", setVehicleLockState)

addEventHandler("onClientPlayerVehicleEnter", localPlayer, function(vehicle, seat)
	if source == localPlayer then
		local vehicle = getPedOccupiedVehicle(localPlayer)		
		if getVehicleType(getPedOccupiedVehicle(localPlayer)) == "Bike" and locked then
			cancelEvent()
		end
	end
end)

source:

addEvent("vehicleLock",true)
addEventHandler("vehicleLock",getRootElement(),function(player,veh,value)
	setVehicleLocked(veh, value)
	veh:setData("veh:status", value)
end)

function vehicleStartExit(thePlayer, seat, jacked)
	if isVehicleLocked(getPedOccupiedVehicle(thePlayer)) then
		outputChatBox("#FFFFFF O seu veículo está fechado!", thePlayer, 255, 255, 255, true)
		cancelEvent()
	end

	if getElementData(thePlayer, "isFuelling") then 
		cancelEvent()
	elseif getVehicleType(getPedOccupiedVehicle(localPlayer)) == "Bike" and locked then
		cancelEvent()
	end
end
addEventHandler("onVehicleStartExit",getRootElement(),vehicleStartExit)

 

 

tentei cancelar o evento ao tenta entrar numa moto trancada, mas não esta dando certo, no demais esta tudo ok

Edited by Looktovask
Link to post
  • Looktovask changed the title to sistema trancar somente pelo dono, bug de entrar na moto mesmo trancada
  • Other Languages Moderators
addEventHandler ("onClientVehicleStartEnter", root, function (thePlayer)
    if (thePlayer == localPlayer) then
        if (isVehicleLocked (source)) then
            outputChatBox ("Veículo trancado.", 255, 0, 0)
            cancelEvent()
        end
    end
end)

 

Edited by Lord Henry
  • Thanks 1
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.

×
×
  • Create New...