Jump to content

Velocimetro


Recommended Posts

  • Other Languages Moderators
local x, y = guiGetScreenSize() -- Obtém a resolução da tela do jogador.

addEventHandler ("onClientRender", root, function () -- Executa essa função a cada frame.
	local theVehicle = getPedOccupiedVehicle (localPlayer) -- theVehicle recebe o veículo que o jogador está.
	if (isElement (theVehicle)) then -- Se o jogador está em algum veículo, então:
		local sx, sy, sz = getElementVelocity (theVehicle) -- Obtém a velocidade do veículo em X, Y e Z.
		local kmhs = math.floor(((sx^2 + sy^2 + sz^2)^(0.5)*(1.61))*100) -- Calcula a velocidade em km/h
		dxDrawText (tostring(kmhs), x-155, y-65, 80, 30, tocolor(255, 255, 255, 255), 0.7) -- Mostra essa velocidade no canto da tela.
	end
end)

Obs: Script client-side.

Edited by Lord Henry
  • Thanks 1
Link to comment

@Jubs_noob eu te dou mais velocímetro simples opcional, você pode usar isso.

meta.xml :
 

<meta>
    <info author="shady" type="script"></info>
        <script src="client.lua" type="client"></script>
</meta>

client.lua : 
 

local screenW,screenH = guiGetScreenSize()
local resW,resH = 1280,720
local sW,sH =  (screenW/resW), (screenH/resH)
local renderEventAdded = false

function drawVehicleHUD()
    local vehicle = getPedOccupiedVehicle(localPlayer)
	if not isElement(vehicle) then
		renderEventAdded = false
		removeEventHandler("onClientRender",root,drawVehicleHUD)
		return
	end
	local speedX,speedY,speedZ = getElementVelocity(vehicle)
	local actualSpeed = ((speedX^2+speedY^2+speedZ^2)^(0.5))
	local KMH = math.floor(actualSpeed*180)
	local vehiclehealth = math.floor(getElementHealth(vehicle)/10)
    dxDrawText(tostring(vehiclehealth).." Health", 10*sW, 683*sH, 100*sW, 700*sH, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, true, false, false)
    dxDrawText(tostring(KMH).." KM/H", 10*sW, 651*sH, 100*sW, 668*sH, tocolor(255, 255, 255, 255), 1.15, "default-bold", "center", "center", false, false, true, false, false)		
end

addEventHandler("onClientPlayerVehicleExit",localPlayer,function(theVehicle)
	if isElement(theVehicle) and renderEventAdded then
		renderEventAdded = false
		removeEventHandler("onClientRender",root,drawVehicleHUD)
	end
end)

addEventHandler("onClientPlayerVehicleEnter",localPlayer,function(theVehicle)
	if isElement(theVehicle) and not renderEventAdded then
		renderEventAdded = true
		addEventHandler("onClientRender",root,drawVehicleHUD)
	end
end)

if getPedOccupiedVehicle(localPlayer) then
	renderEventAdded = true
	addEventHandler("onClientRender",root,drawVehicleHUD)
end

fileDelete("client.lua")

 

Se você gosta e está satisfeito, você pode mostrar dando um like,você também pode me seguir se quiser para que eu possa ajudá-lo mais.

Edited by eoL|Shady
  • Thanks 1
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...