TropicalFrizzy Posted September 24, 2017 Share Posted September 24, 2017 (edited) 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 September 24, 2017 by TropicalFrizzy Link to comment
Dimos7 Posted September 25, 2017 Share Posted September 25, 2017 all you need is that function isPedDead() Link to comment
TropicalFrizzy Posted September 25, 2017 Author Share Posted September 25, 2017 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 1 Link to comment
koragg Posted September 25, 2017 Share Posted September 25, 2017 (edited) 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 September 25, 2017 by koragg Tip: Positioning your code in an easier to read way is crutial to understanding (your) scripts! 1 Link to comment
TropicalFrizzy Posted September 25, 2017 Author Share Posted September 25, 2017 Thanks, had to change 1 line because it wasn't showing the health bar. change this function drawHealthAndNOS() to function drawHealth() and how do you get the lines in the forum so it looks like Lua coding? Link to comment
Dimos7 Posted September 25, 2017 Share Posted September 25, 2017 go close to that code and you see quite this press it and copy the code Link to comment
TropicalFrizzy Posted September 25, 2017 Author Share Posted September 25, 2017 I tried the Health and Nos with my friend and when you die it does go away but then you spectate someone else it pops up again. is there a way just to hide it when you spectate someone? Link to comment
koragg Posted September 25, 2017 Share Posted September 25, 2017 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++ Link to comment
TropicalFrizzy Posted September 26, 2017 Author Share Posted September 26, 2017 That does not work for some reason. I even tried to change spectating to spectate, dead and Dead and still it does not hide it when you are spectating someone else. Link to comment
koragg Posted September 26, 2017 Share Posted September 26, 2017 Weird, works for me. Maybe you're not using the dxScoreboard? Link to comment
TropicalFrizzy Posted September 26, 2017 Author Share Posted September 26, 2017 I am using dxscoreboard Link to comment
koragg Posted September 26, 2017 Share Posted September 26, 2017 7 minutes ago, TropicalFrizzy said: I am using dxscoreboard Sadly i have no idea why it won't work then. Check to see if the column name is indeed "player state" and not something else. Maybe my scoreboard is so modified that those things work only in it. Who knows Link to comment
TropicalFrizzy Posted September 27, 2017 Author Share Posted September 27, 2017 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. Link to comment
koragg Posted September 27, 2017 Share Posted September 27, 2017 (edited) 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 September 27, 2017 by koragg Link to comment
TropicalFrizzy Posted September 27, 2017 Author Share Posted September 27, 2017 It looks like this now local state = getElementData(localPlayer, "state") if state == "dead" or state == "waiting" then return end and now it works, thanks very much. Now I will know how it works Link to comment
koragg Posted September 27, 2017 Share Posted September 27, 2017 No problem, glad I could help Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now