Jump to content

[HELP] Want to make the Vehicle and Nitro disappear i


TropicalFrizzy

Recommended Posts

Hi, I found this script on MTA Community https://community.multitheftauto.com/index.php?p=resources&s=details&id=9045

I would like to make some changes to it,

I have tried many ways to do this but I keep on failing, I'm a beginner on the Lua scripting.

I was wondering if someone could help me out. I want to make this Health and Nitros to disappear when a player has died. I am trying to make a DM race server.

Edited by TropicalFrizzy
Link to comment

Would it be something like this? 

function isPedDead()
            if isPedDead then Dead = showPlayerHudComponent(thePlayer "source, nitroShow",false)
            else
            getElementHealth(player) if Health then showPlayerHudComponent(thePlayer "source, nitroShow",true)
        end
    end
end

  • Haha 1
Link to comment

I used the same resource in my server since the design is so simplistic yet awesome looking. Try this for your case (also fixed up code a bit since it wasn't positioned correctly):

local sx, sy = guiGetScreenSize()
local px, py = 1600, 900
local x, y =  (sx/px), (sy/py)

function drawHealthAndNOS()
	local playerVehicle = getPedOccupiedVehicle(localPlayer)
	if playerVehicle then
		local vehicleHealth = getElementHealth ( playerVehicle )
		local vehicleSpeed = getElementVelocity ( playerVehicle )
		if isPedDead(localPlayer) then
			return
		end
		dxDrawLine(x*1293, y*802, x*1590, y*802, tocolor(0, 0, 0, 255), 3, true)
		dxDrawLine(x*1293, y*886, x*1590, y*886, tocolor(0, 0, 0, 255), 3, true)
		dxDrawLine(x*1293, y*801, x*1293, y*887, tocolor(0, 0, 0, 255), 3, true)
		dxDrawLine(x*1590, y*800, x*1590, y*886, tocolor(0, 0, 0, 255), 3, true)
		dxDrawRectangle(x*1294, y*803, x*297, y*83, tocolor(0, 0, 0, 170), true) -- Rahmen
		dxDrawRectangle(x*1454, y*814, x*126, y*23, tocolor(44, 44, 44, 255), true) -- Health
		dxDrawRectangle(x*1454, y*814, x*126/1000*vehicleHealth, y*23, tocolor(59, 141, 0, 255), true) -- Health
		dxDrawText((math.floor(vehicleHealth/10)).."% Health", x*1440, y*810, x*1604, y*842, tocolor(255, 255, 255, 255), 1.30, "default-bold", "center", "center", false, false, true, false, false) -- Health
		sx, sy, sz = getElementVelocity (getPedOccupiedVehicle(localPlayer)) -- Speed
		vehiclekmh = math.floor(((sx^2 + sy^2 + sz^2)^(0.5))*180) -- Speed
		dxDrawText(""..tostring(vehiclekmh).." kmh", x*1358, y*857, x*1522, y*877, tocolor(255, 255, 255, 255), 1.20, "default-bold", "center", "center", false, false, true, false, false) -- Speed
	end
end
addEventHandler("onClientRender", root, drawHealth)

function nitroShow()
	if isPedInVehicle(localPlayer) then
		local car = getPedOccupiedVehicle(localPlayer)
		local nitro = getVehicleNitroLevel(car)
		if isPedDead(localPlayer) then
			return
		end
		if nitro ~= false and nitro ~= nil and nitro > 0 then
			dxDrawRectangle(x*1305, y*814, x*126, y*23, tocolor(44, 44, 44, 255), true) -- Nos Show
			dxDrawRectangle(x*1305, y*814, x*126/10*10*nitro, y*23, tocolor(0, 70, 149, 255), true) -- Nos Show
			dxDrawText((math.floor(nitro/1*100)).."% Nitro", x*1290, y*810, x*1454, y*842, tocolor(255, 255, 255, 255), 1.30, "default-bold", "center", "center", false, false, true, false, false) -- Nos Show
		else
			dxDrawText("No Nitro", x*1290, y*810, x*1454, y*842, tocolor(255, 255, 255, 255), 1.30, "default-bold", "center", "center", false, false, true, false, false) -- Nos Hide
		end
	end
end
addEventHandler("onClientRender", root, nitroShow)

 

Edited by koragg
Tip: Positioning your code in an easier to read way is crutial to understanding (your) scripts!
  • Thanks 1
Link to comment

Here you go. By the way instead of removing it when you're spectating you can make it update the health and nitro level of the person you're spectating so it shows their values. Anyway, code to remove both if you're spectating below, let me know if you want to sync it instead and I'll be glad to help you out (it's ready for me, just copy-paste xd).

local sx, sy = guiGetScreenSize()
local px, py = 1600, 900
local x, y =  (sx/px), (sy/py)

function drawHealthAndNOS()
	local playerVehicle = getPedOccupiedVehicle(localPlayer)
	if playerVehicle then
		local vehicleHealth = getElementHealth(playerVehicle)
		local vehicleSpeed = getElementVelocity(playerVehicle)
		if isPedDead(localPlayer) then
			return
		end
		local state = getElementData(localPlayer, "player state")
		if state == "spectating" then
			return
		end
		dxDrawLine(x*1293, y*802, x*1590, y*802, tocolor(0, 0, 0, 255), 3, true)
		dxDrawLine(x*1293, y*886, x*1590, y*886, tocolor(0, 0, 0, 255), 3, true)
		dxDrawLine(x*1293, y*801, x*1293, y*887, tocolor(0, 0, 0, 255), 3, true)
		dxDrawLine(x*1590, y*800, x*1590, y*886, tocolor(0, 0, 0, 255), 3, true)
		dxDrawRectangle(x*1294, y*803, x*297, y*83, tocolor(0, 0, 0, 170), true) -- Rahmen
		dxDrawRectangle(x*1454, y*814, x*126, y*23, tocolor(44, 44, 44, 255), true) -- Health
		dxDrawRectangle(x*1454, y*814, x*126/1000*vehicleHealth, y*23, tocolor(59, 141, 0, 255), true) -- Health
		dxDrawText((math.floor(vehicleHealth/10)).."% Health", x*1440, y*810, x*1604, y*842, tocolor(255, 255, 255, 255), 1.30, "default-bold", "center", "center", false, false, true, false, false) -- Health
		sx, sy, sz = getElementVelocity (getPedOccupiedVehicle(localPlayer)) -- Speed
		vehiclekmh = math.floor(((sx^2 + sy^2 + sz^2)^(0.5))*180) -- Speed
		dxDrawText(""..tostring(vehiclekmh).." kmh", x*1358, y*857, x*1522, y*877, tocolor(255, 255, 255, 255), 1.20, "default-bold", "center", "center", false, false, true, false, false) -- Speed
	end
end
addEventHandler("onClientRender", root, drawHealthAndNOS)

function nitroShow()
	if isPedInVehicle(localPlayer) then
		local car = getPedOccupiedVehicle(localPlayer)
		local nitro = getVehicleNitroLevel(car)
		if isPedDead(localPlayer) then
			return
		end
		local state = getElementData(localPlayer, "player state")
		if state == "spectating" then
			return
		end
		if nitro ~= false and nitro ~= nil and nitro > 0 then
			dxDrawRectangle(x*1305, y*814, x*126, y*23, tocolor(44, 44, 44, 255), true) -- Nos Show
			dxDrawRectangle(x*1305, y*814, x*126/10*10*nitro, y*23, tocolor(0, 70, 149, 255), true) -- Nos Show
			dxDrawText((math.floor(nitro/1*100)).."% Nitro", x*1290, y*810, x*1454, y*842, tocolor(255, 255, 255, 255), 1.30, "default-bold", "center", "center", false, false, true, false, false) -- Nos Show
		else
			dxDrawText("No Nitro", x*1290, y*810, x*1454, y*842, tocolor(255, 255, 255, 255), 1.30, "default-bold", "center", "center", false, false, true, false, false) -- Nos Hide
		end
	end
end
addEventHandler("onClientRender", root, nitroShow)

And in the post window there are two opposite arrows in the control bar at the top. Something like '<>'. Click that and paste your code there so it looks like in Notepad++ :P

Link to comment
23 minutes ago, TropicalFrizzy said:

I "fixed it" I changed the "player state" to "state" and == "spectating" to "dead" and it hides it when a player is dead. but if someone joins the server and is in a "waiting" state it shows up for them can I just add =="dead", "waiting" ?? and could I have the sync I want to see how it works anyway, please. 

You can do like this:

local state = getElementData(localPlayer, "player state")
		if state == "dead" or state == "waiting" then
			return
		end

Here's how to sync it (lines 6-10):

function nitroShow()
	if isPedInVehicle(localPlayer) then
		local target = getCameraTarget()
		local car = getPedOccupiedVehicle(localPlayer)
		local nitro = getVehicleNitroLevel(car)
		if target and getElementType(target) == "vehicle" then
			nitro = getVehicleNitroLevel(getVehicleOccupant(target))
		elseif target and getElementType(target) == "player" then
			nitro = getVehicleNitroLevel(target)
		end
		if isPedDead(localPlayer) then
			return
		end
		if nitro ~= false and nitro ~= nil and nitro > 0 then
			dxDrawRectangle(x*1305, y*814, x*126, y*23, tocolor(44, 44, 44, 255), true) -- Nos Show
			dxDrawRectangle(x*1305, y*814, x*126/10*10*nitro, y*23, tocolor(0, 70, 149, 255), true) -- Nos Show
			dxDrawText((math.floor(nitro/1*100)).."% Nitro", x*1290, y*810, x*1454, y*842, tocolor(255, 255, 255, 255), 1.30, "default-bold", "center", "center", false, false, true, false, false) -- Nos Show
		else
			dxDrawText("No Nitro", x*1290, y*810, x*1454, y*842, tocolor(255, 255, 255, 255), 1.30, "default-bold", "center", "center", false, false, true, false, false) -- Nos Hide
		end
	end
end
addEventHandler("onClientRender", root, nitroShow)

 

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