Jump to content

[HELP] Get player car info


Cacaroto

Recommended Posts

Posted (edited)

So I was scripting a HUD and almost everything is fine (everything okay for local player), but when a player die I want to show up in the HUD the car stats of the vehicle im spectating but it doesn't work, here i post the code:

 

function drawSpeedo()
    if isPedInVehicle(getLocalPlayer()) or isPedInVehicle(getVehicleOccupant(getCameraTarget(localPlayer))) then
        if isPedDead(localPlayer) then
            specHealth = getElementHealth(getCameraTarget(localPlayer))
            sHealth = (math.max(specHealth - 250, 0)/750)*100
            colorR = sHealth > 50 and (255/100)*(100 - sHealth*2) + 255 or 255
            colorG = sHealth > 50 and 255 or (255/100)*(sHealth*2)

            sx, sy, sz = getElementVelocity (getCameraTarget(localPlayer))
            spectSpeed = math.floor(((sx^2 + sy^2 + sz^2)^(0.5))*180)

            dxDrawText(spectSpeed.." km/h", (1680/1920)*sX, (940/1080)*sY, (1804/1920)*sX, (966/1080)*sY, tocolor(255, 255, 255, 255), (1/1920)*sX, font, "center", "top", false, false, false, false, false)
            dxDrawRectangle((1620/1920)*sX, (990/1080)*sY, (((specHealth/10)*2.5)/1920)*sX, (7/1080)*sY, tocolor(colorR, colorG, 0, 255), false)
            dxDrawCircle (((1620+(specHealth/10)*2.5)/1920)*sX, (993/1080)*sY, 7, 0, 360, tocolor(colorR, colorG, 0, 255), tocolor(colorR, colorG, 0, 255), 32, 1, false)

            nitro = getVehicleUpgradeOnSlot(getCameraTarget(localPlayer), 8 )
            nosLevel = getVehicleNitroLevel(getCameraTarget(localPlayer))*100 or 0
            nosColor = isVehicleNitroActivated(getCameraTarget(localPlayer)) and colorTable[ "using" ] or isVehicleNitroRecharging(getCameraTarget(localPlayer)) and colorTable[ "chargin" ] or colorTable[ "stock" ]
            dxDrawRectangle((1620/1920)*sX, (1020/1080)*sY, (((nosLevel*250)/100)/1920)*sX, (7/1080)*sY, nosColor, false)
            dxDrawCircle (((1620+(nosLevel*2.5))/1920)*sX, (1023/1080)*sY, 7, 0, 360, nosColor, nosColor, 32, 1, false)
        else
            vehHealth = getElementHealth(getPedOccupiedVehicle(localPlayer))
            health = (math.max(vehHealth - 250, 0)/750)*100
            colorR = health > 50 and (255/100)*(100 - health*2) + 255 or 255
            colorG = health > 50 and 255 or (255/100)*(health*2)

            sx, sy, sz = getElementVelocity (getPedOccupiedVehicle(getLocalPlayer()))
            vehSpeed = math.floor(((sx^2 + sy^2 + sz^2)^(0.5))*180)

            dxDrawText(vehSpeed.." km/h", (1680/1920)*sX, (940/1080)*sY, (1804/1920)*sX, (966/1080)*sY, tocolor(255, 255, 255, 255), (1/1920)*sX, font, "center", "top", false, false, false, false, false)
            dxDrawRectangle((1620/1920)*sX, (990/1080)*sY, (((vehHealth/10)*2.5)/1920)*sX, (7/1080)*sY, tocolor(colorR, colorG, 0, 255), false)
            dxDrawCircle (((1620+(vehHealth/10)*2.5)/1920)*sX, (993/1080)*sY, 7, 0, 360, tocolor(colorR, colorG, 0, 255), tocolor(colorR, colorG, 0, 255), 32, 1, false)

            nitro = getVehicleUpgradeOnSlot(getPedOccupiedVehicle(localPlayer), 8 )
            nosLevel = getVehicleNitroLevel(getPedOccupiedVehicle(localPlayer))*100 or 0
            nosColor = isVehicleNitroActivated(getPedOccupiedVehicle(localPlayer)) and colorTable[ "using" ] or isVehicleNitroRecharging( getPedOccupiedVehicle(getLocalPlayer()) ) and colorTable[ "chargin" ] or colorTable[ "stock" ]
            dxDrawRectangle((1620/1920)*sX, (1020/1080)*sY, (((nosLevel*250)/100)/1920)*sX, (7/1080)*sY, nosColor, false)
            dxDrawCircle (((1620+(nosLevel*2.5))/1920)*sX, (1023/1080)*sY, 7, 0, 360, nosColor, nosColor, 32, 1, false)
        end
    end
end
addEventHandler("onClientRender", root, drawSpeedo)

 

Edited by Cacaroto
Posted (edited)
function drawSpeedo()

	if isPedDead(localPlayer) then 
		Player = getCameraTarget ()
	else
		Player = localPlayer
	end

    if isPedInVehicle(Player) then
		veh = getPedOccupiedVehicle(Player)
		if isElement(veh) then
			specHealth = getElementHealth(veh)
			sHealth = (math.max(specHealth - 250, 0)/750)*100
			colorR = sHealth > 50 and (255/100)*(100 - sHealth*2) + 255 or 255
			colorG = sHealth > 50 and 255 or (255/100)*(sHealth*2)

			sx, sy, sz = getElementVelocity (veh)
			spectSpeed = math.floor(((sx^2 + sy^2 + sz^2)^(0.5))*180)

			dxDrawText(spectSpeed.." km/h", (1680/1920)*sX, (940/1080)*sY, (1804/1920)*sX, (966/1080)*sY, tocolor(255, 255, 255, 255), (1/1920)*sX, font, "center", "top", false, false, false, false, false)
			dxDrawRectangle((1620/1920)*sX, (990/1080)*sY, (((specHealth/10)*2.5)/1920)*sX, (7/1080)*sY, tocolor(colorR, colorG, 0, 255), false)
			dxDrawCircle (((1620+(specHealth/10)*2.5)/1920)*sX, (993/1080)*sY, 7, 0, 360, tocolor(colorR, colorG, 0, 255), tocolor(colorR, colorG, 0, 255), 32, 1, false)

			if getVehicleUpgradeOnSlot(veh, 8 ) then
				nosLevel = getVehicleNitroLevel(veh)*100 or 0
				nosColor = isVehicleNitroActivated(veh) and colorTable[ "using" ] or isVehicleNitroRecharging(veh) and colorTable[ "chargin" ] or colorTable[ "stock" ]
				dxDrawRectangle((1620/1920)*sX, (1020/1080)*sY, (((nosLevel*250)/100)/1920)*sX, (7/1080)*sY, nosColor, false)
				dxDrawCircle (((1620+(nosLevel*2.5))/1920)*sX, (1023/1080)*sY, 7, 0, 360, nosColor, nosColor, 32, 1, false)
			end
		end
    end
end
addEventHandler("onClientRender", root, drawSpeedo)

I dont test it but i think is cool xD

Edited by RekZ
Posted
function drawSpeedo()

	if isPedDead(localPlayer) then 
		Player = getCameraTarget()
	else
		Player = localPlayer
	end
	
	if isElement(Player) then
		if isPedInVehicle(Player) then
			veh = getPedOccupiedVehicle(Player)
			if isElement(veh) then
				specHealth = getElementHealth(veh)
				sHealth = (math.max(specHealth - 250, 0)/750)*100
				colorR = sHealth > 50 and (255/100)*(100 - sHealth*2) + 255 or 255
				colorG = sHealth > 50 and 255 or (255/100)*(sHealth*2)

				sx, sy, sz = getElementVelocity (veh)
				spectSpeed = math.floor(((sx^2 + sy^2 + sz^2)^(0.5))*180)

				dxDrawText(spectSpeed.." km/h", (1680/1920)*sX, (940/1080)*sY, (1804/1920)*sX, (966/1080)*sY, tocolor(255, 255, 255, 255), (1/1920)*sX, font, "center", "top", false, false, false, false, false)
				dxDrawRectangle((1620/1920)*sX, (990/1080)*sY, (((specHealth/10)*2.5)/1920)*sX, (7/1080)*sY, tocolor(colorR, colorG, 0, 255), false)
				dxDrawCircle (((1620+(specHealth/10)*2.5)/1920)*sX, (993/1080)*sY, 7, 0, 360, tocolor(colorR, colorG, 0, 255), tocolor(colorR, colorG, 0, 255), 32, 1, false)

				if getVehicleUpgradeOnSlot(veh, 8 ) then
					nosLevel = ( (getVehicleNitroLevel(veh) or 0) *100 )
					nosColor = (isVehicleNitroActivated(veh) and colorTable[ "using" ]) or (isVehicleNitroRecharging(veh) and (colorTable[ "chargin" ] or colorTable[ "stock" ]) )
					--nosColor = tocolor(255, 255, 255, 255)
					dxDrawRectangle((1620/1920)*sX, (1020/1080)*sY, (((nosLevel*250)/100)/1920)*sX, (7/1080)*sY, nosColor, false)
					dxDrawCircle (((1620+(nosLevel*2.5))/1920)*sX, (1023/1080)*sY, 7, 0, 360, nosColor, nosColor, 32, 1, false)
				end
			end
		end
    end
	
end
addEventHandler("onClientRender", root, drawSpeedo)

Test it now, for me work fine, i test it in my server

Posted (edited)
function drawSpeedo()
	
	if ( getCameraTarget() or isPedDead(localPlayer) ) then
		Spect = getCameraTarget()
	else
		Spect = getPedOccupiedVehicle(localPlayer)
	end
	
	if isElement(Spect) and getElementType(Spect) == "vehicle" then
		specHealth = getElementHealth(Spect)
		sHealth = (math.max(specHealth - 250, 0)/750)*100
		colorR = sHealth > 50 and (255/100)*(100 - sHealth*2) + 255 or 255
		colorG = sHealth > 50 and 255 or (255/100)*(sHealth*2)

		sx, sy, sz = getElementVelocity (Spect)
		spectSpeed = math.floor(((sx^2 + sy^2 + sz^2)^(0.5))*180)

		dxDrawText(spectSpeed.." km/h", (1680/1920)*sX, (940/1080)*sY, (1804/1920)*sX, (966/1080)*sY, tocolor(255, 255, 255, 255), (1/1920)*sX, font, "center", "top", false, false, false, false, false)
		dxDrawRectangle((1620/1920)*sX, (990/1080)*sY, (((specHealth/10)*2.5)/1920)*sX, (7/1080)*sY, tocolor(colorR, colorG, 0, 255), false)
		dxDrawCircle (((1620+(specHealth/10)*2.5)/1920)*sX, (993/1080)*sY, 7, 0, 360, tocolor(colorR, colorG, 0, 255), tocolor(colorR, colorG, 0, 255), 32, 1, false)

		if getVehicleUpgradeOnSlot(Spect,8) then
			nosLevel = ( (getVehicleNitroLevel(Spect) or 0) *100 )
			nosColor = (isVehicleNitroActivated(Spect) and colorTable[ "using" ]) or (isVehicleNitroRecharging(Spect) and (colorTable[ "chargin" ] or colorTable[ "stock" ]) )
			--nosColor = tocolor(255, 255, 255, 255)
			dxDrawRectangle((1620/1920)*sX, (1020/1080)*sY, (((nosLevel*250)/100)/1920)*sX, (7/1080)*sY, nosColor, false)
			dxDrawCircle (((1620+(nosLevel*2.5))/1920)*sX, (1023/1080)*sY, 7, 0, 360, nosColor, nosColor, 32, 1, false)
		end
	end
	
end
addEventHandler("onClientRender", getRootElement(), drawSpeedo)

Sorry i remember the race dont spect the player, spect the vehicle xD now yes is functional

Edited by RekZ
Posted (edited)

Thanks so much! It works really fine! But there's a problem with nos, when a player pickups the nos the bar doesnt appear until he uses it, i don't know how to fix it

Edited by Cacaroto

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