Jump to content

Spawnar no carro mais proximo sem um piloto


Recommended Posts


function irCarroProximo(thePlayer, cmd)
	-- checar permissao de staff aqui

	local x,y,z = getElementPosition(thePlayer)
	local int, dim = getElementInterior(thePlayer), getElementDimension(thePlayer)
	local closestVehicle = nil
	local smallestDistance = nil

	for k, vehicle in ipairs(getElementsByType("vehicle")) do
		local vx,vy,vz = getElementPosition(vehicle)
		local vint, vdim = getElementInterior(vehicle), getElementDimension(vehicle)

		-- verificar se tao no mesmo mundo
		if vint == int and vdim == dim then

			-- verificar se n tem ngm dentro
			if not getVehicleController(vehicle) then

				-- verificar posicao
				local dist = getDistanceBetweenPoints3D(x,y,z, vx,vy,vz)
				if (smallestDistance == nil) or (dist < smallestDistance) then
					smallestDistance = dist
					closestVehicle = vehicle
				end
			end
		end
	end

	if not closestVehicle then
		outputChatBox("Nenhum veículo desocupado foi encontrado", thePlayer, 255,0,0)
		return
	end

	local vx,vy,vz = getElementPosition(closestVehicle)
	setElementPosition(thePlayer, vx, vy, vz +3)
	outputChatBox("Teleportado para o veículo mais próximo#ffffff "..vx..", "..vy..", "..vz, thePlayer, 0,255,0, true)
end
addCommandHandler("ircarroproximo", irCarroProximo, false, false)

se tiver alguma dúvida não hesite @SciptNovato

Edited by FernandoMTA
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...