Jump to content

Why not working the dx element?


Turbe$Z

Recommended Posts

 

local screenW, screenH = guiGetScreenSize()

function ahudd()
        dxDrawImage(screenW * 0.8424, screenH * 0.6289, screenW * 0.1194, screenH * 0.0256, "nbgg.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
        dxDrawImage(screenW * 0.8444, screenH * 0.6322, screenW * 0.1153, screenH * 0.0189, "nn.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
        dxDrawText("Jármű épség:", (screenW * 0.8424) + 1, (screenH * 0.6289) + 1, (screenW * 0.9618) + 1, (screenH * 0.6544) + 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false)
        dxDrawText("Jármű épség:", screenW * 0.8424, screenH * 0.6289, screenW * 0.9618, screenH * 0.6544, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false)
end

function asdxd()
	local playerVehicle = getPedOccupiedVehicle ( localPlayer )
	if playerVehicle then
		local vehicleHealth = getElementHealth ( playerVehicle ) / 10
		addEventHandler("onClientRender", root, ahudd)
	else
		removeEventHandler("onClientRender", root, ahudd)
	end
end
addEventHandler("onClientRender", root, asdxd)

fileDelete("client.lua")

why not working? :( 

i want, when the player get in a vehicle, show the dx element, and when get out, hide the dx element, and if player in a vehicle, the dx element show just for her

Link to comment

Use the onClientVehicleEnter event. Something like this:

addEventHandler("onClientVehicleEnter", root,
	function(plr)
		if plr == localPlayer then
			addEventHandler("onClientRender", root, draw)
		end
	end
)


function draw()
	local veh = getPedOccupiedVehicle(localPlayer)
	if veh then
		ahudd()
	else
		removeEventHandler("onClientRender", root, draw)
	end
end

 

  • Like 1
Link to comment
3 minutes ago, Tails said:

Use the onClientVehicleEnter event. Something like this:


addEventHandler("onClientVehicleEnter", root,
	function(plr)
		if plr == localPlayer then
			addEventHandler("onClientRender", root, draw)
		end
	end
)


function draw()
	local veh = getPedOccupiedVehicle(localPlayer)
	if veh then
		ahudd()
	else
		removeEventHandler("onClientRender", root, draw)
	end
end

 

Thank you! :D

  • Like 1
Link to comment

That code will not work if you warp on a vehicle. Just use getPedOccupiedVehicle(localPlayer) inside the function 'ahudd':

local screenW, screenH = guiGetScreenSize()

function ahudd()
	if getPedOccupiedVehicle ( localPlayer ) then
	  dxDrawImage(screenW * 0.8424, screenH * 0.6289, screenW * 0.1194, screenH * 0.0256, "nbgg.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
	  dxDrawImage(screenW * 0.8444, screenH * 0.6322, screenW * 0.1153, screenH * 0.0189, "nn.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
	  dxDrawText("Jármű épség:", (screenW * 0.8424) + 1, (screenH * 0.6289) + 1, (screenW * 0.9618) + 1, (screenH * 0.6544) + 1, tocolor(0, 0, 0, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false)
	  dxDrawText("Jármű épség:", screenW * 0.8424, screenH * 0.6289, screenW * 0.9618, screenH * 0.6544, tocolor(255, 255, 255, 255), 1.00, "default-bold", "center", "center", false, false, false, false, false)
	end
end

addEventHandler( "onClientResourceStart", resourceRoot, 
	function()
		addEventHandler("onClientRender", root, ahudd)
	end
)

if fileExists("client.lua") then
	fileDelete("client.lua")
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...