Bean666 Posted March 4, 2021 Share Posted March 4, 2021 Hi, i got this hud from the community, it works perfect but if player has above 100 health, like he changed hp stats to higher number, the hud disappears like this: normal: What's causing this? Client.lua: --> Scripted by.: Bence Developer --> Blur --> Crash addEventHandler( "onClientMinimize", root, function() blurShader = nil end ) local screenSource = dxCreateScreenSource(screenX, screenY) blurShader = nil addEventHandler("onClientPreRender", root, function() blurShader = dxCreateShader("shaders/blur.fx") if (blurShader) then dxUpdateScreenSource(screenSource) dxSetShaderValue(blurShader, "ScreenSource", screenSource) dxSetShaderValue(blurShader, "BlurStrength", 3) dxSetShaderValue(blurShader, "UVSize", screenX, screenY) for k, v in ipairs(hudComponents) do if not hudClosed or (hudClosed and k < 2) then dxDrawImageSection ( v[1], v[2], v[3], v[4], v[1], v[2], v[3], v[4], blurShader) end end end end ) addEventHandler("onClientRender", root, function() if (hudClosed) then state = "down" else state = "up" end dxDrawImage(switchArrowPositions[1], switchArrowPositions[2], switchArrowPositions[3], switchArrowPositions[4], "images/arrow-"..state..".png") for k, v in ipairs(hudComponents) do if (k == 1) then dxDrawRectangle(v[1], v[2], 47*x, 47*y, tocolor(0, 0, 0, 225)) local avatarID = getElementData(localPlayer, "avatarID") or 1 dxDrawImage(v[1], v[2], 47*x, 47*y, "images/avatars/"..avatarID..".png") if (isMouseInPosition(v[1], v[2], 47*x, 47*y)) then dxDrawRectangle(v[1], v[2], 47*x, 47*y, tocolor(0, 0, 0, 175)) dxDrawText("Change", v[1], v[2], 47*x+v[1], 47*y+v[2], tocolor(250, 250, 250, 250), 1, roboto_9px, "center", "center") end dxDrawRectangle(v[1]+52*x, v[2], v[3]-52*x, v[4], tocolor(0, 0, 0, 225)) local playerName = getPlayerName(localPlayer) dxDrawText(playerName, v[1]+58*x, v[2]+4*y, v[3]-52*x, v[4], tocolor(250, 250, 250, 255), 1, roboto_13px, "left", "top", false, false, false, true) dxDrawRectangle(v[1]+58*x+((v[3]-66*x)/100)*0, v[2]+29*y, 2*x, 12*y, tocolor(255, 255, 255, 250)) dxDrawRectangle(v[1]+58*x+((v[3]-66*x)/100)*25, v[2]+29*y, 2*x, 12*y, tocolor(255, 255, 255, 250)) dxDrawRectangle(v[1]+58*x+((v[3]-66*x)/100)*50, v[2]+29*y, 2*x, 12*y, tocolor(255, 255, 255, 250)) dxDrawRectangle(v[1]+58*x+((v[3]-66*x)/100)*75, v[2]+29*y, 2*x, 12*y, tocolor(255, 255, 255, 250)) dxDrawRectangle(v[1]+58*x+((v[3]-66*x)/100)*100, v[2]+29*y, 2*x, 12*y, tocolor(255, 255, 255, 250)) local playerHealth = getElementHealth(localPlayer) local playerArmor = getPedArmor(localPlayer) local healthColor = getHealthColor(playerHealth) local armorColor = getArmorColor(playerArmor) dxDrawRectangle(v[1]+58*x, v[2]+31*y, (v[3]-66*x)/100*playerHealth, 8*y, tocolor(healthColor[1], healthColor[2], healthColor[3], 210)) dxDrawRectangle(v[1]+58*x, v[2]+31*y, (v[3]-66*x)/100*playerArmor, 8*y, tocolor(armorColor[1], armorColor[2], armorColor[3], 125)) local oxygenLevel = getPedOxygenLevel(localPlayer) if (isElementInWater(localPlayer)) then dxDrawRectangle(v[1]+58*x, v[2]+39*y, (v[3]-64*x)/1000*oxygenLevel, 2*y, tocolor(28, 56, 51, 255)) end end if not (hudClosed) then if (k == 2) then dxDrawRectangle(v[1], v[2], 47*x, 47*y, tocolor(0, 0, 0, 225)) dxDrawImage(v[1], v[2], 47*x, 47*y, "images/money.png") dxDrawRectangle(v[1]+52*x, v[2], v[3]-52*x, v[4], tocolor(0, 0, 0, 225)) local playerMoney = getPlayerMoney(localPlayer) dxDrawText("$"..formatNumber(playerMoney), v[1]+52*x, v[2], v[3]-52*x+v[1]+52*x, v[4]+v[2], tocolor(250, 250, 250, 250), 1, roboto_16px, "center", "center") elseif (k == 3) then dxDrawRectangle(v[1], v[2], 47*x, 47*y, tocolor(0, 0, 0, 225)) dxDrawImage(v[1], v[2], 47*x, 47*y, "images/weapon.png") dxDrawRectangle(v[1]+52*x, v[2], 52*x, v[4], tocolor(0, 0, 0, 225)) local totalAmmo = getPedTotalAmmo(localPlayer)-getPedAmmoInClip(localPlayer) local playerWeapon = getPedWeapon(localPlayer) if (playerWeapon == 0) then totalAmmo = "-" end dxDrawText(totalAmmo, v[1]+52*x, v[2], 52*x+v[1]+52*x, v[4]+v[2], tocolor(250, 250, 250, 255), 1, roboto_13px, "center", "center") dxDrawRectangle(v[1]+109*x, v[2], 47*x, v[4], tocolor(0, 0, 0, 225)) local ammo = getPedAmmoInClip (localPlayer) local playerWeapon = getPedWeapon(localPlayer) if (playerWeapon == 0) then ammo = "-" end dxDrawText(ammo, v[1]+109*x, v[2], 47*x+v[1]+109*x, v[4]+v[2], tocolor(250, 250, 250, 255), 1, roboto_13px, "center", "center") dxDrawRectangle(v[1]+160*x, v[2], 94*x, v[4], tocolor(0, 0, 0, 225)) local playerWeapon = getPedWeapon(localPlayer) dxDrawText(weaponNameByID[playerWeapon], v[1]+160*x, v[2], 94*x+v[1]+160*x, v[4]+v[2], tocolor(250, 250, 250, 255), 1, roboto_13px, "center", "center") elseif (k == 4) then dxDrawRectangle(v[1], v[2], 104*x, v[4], tocolor(0, 0, 0, 225)) local time = getRealTime() local hour = time.hour local minute = time.minute if (hour < 10) then hour = "0"..hour end if (minute < 10) then minute = "0"..minute end dxDrawText(""..hour..":"..minute.."", v[1], v[2], 104*x+v[1], v[4]+v[2], tocolor(250, 250, 250, 255), 1, roboto_12px, "center", "center") dxDrawRectangle(v[1]+109*x, v[2], 70*x, v[4], tocolor(0, 0, 0, 225)) local playerFPS = getElementData(localPlayer, "player:fps") or 60 local fpsColor = getFPSColor(playerFPS) dxDrawText(""..playerFPS.." FPS", v[1]+109*x, v[2], 70*x+v[1]+109*x, v[4]+v[2], tocolor(fpsColor[1], fpsColor[2], fpsColor[3], 255), 1, roboto_12px, "center", "center") dxDrawRectangle(v[1]+184*x, v[2], 70*x, v[4], tocolor(0, 0, 0, 225)) local playerPing = getPlayerPing(localPlayer) local pingColor = getPingColor(playerPing) dxDrawText(playerPing.." ms", v[1]+184*x, v[2], 70*x+v[1]+184*x, v[4]+v[2], tocolor(pingColor[1], pingColor[2], pingColor[3], 255), 1, roboto_12px, "center", "center") end end end end ) addEventHandler ( "onClientClick", root, function(button, state, absoluteX, absoluteY, worldX, worldY, worldZ, clickedElement) if (button == "left" and state == "down") then if (isMouseInPosition (switchArrowPositions[1], switchArrowPositions[2], switchArrowPositions[3], switchArrowPositions[4])) then hudClosed = not hudClosed end for k, v in ipairs(hudComponents) do if (k == 1) then if (isMouseInPosition(v[1], v[2], 47*x, 47*y)) then openChangeAvatarMenu() end end end end end ) function getHealthColor(health) if (health > 0) then if (health <= 100) and (health > 50) then return {238, 71, 71} elseif (health <= 50) and (health > 25) then return {235, 52, 52} elseif (health <= 25) and (health > 0) then return {176, 24, 24} end else return {198, 195, 195} end end function getArmorColor(armor) if (armor > 0) then if (armor <= 100) and (armor > 75) then return {20, 161, 204} elseif (armor <= 75) and (armor > 50) then return {20, 204, 84} elseif (armor <= 50) and (armor > 25) then return {204, 164, 20} elseif (armor <= 25) and (armor > 0) then return {204, 20, 20} end else return {20, 161, 204} end end function getFPSColor (fps) if (fps > 0) then if (fps <= 100) and (fps > 40) then return {255, 255, 255} elseif (fps <= 40) and (fps > 25) then return {255, 255, 255} elseif (fps <= 25) and (fps > 0) then return {255, 255, 255} end end end function getPingColor (ping) if (ping > 0) then if (ping <= 60) and (ping > 0) then return {255, 255, 255} elseif (ping <= 120) and (ping > 60) then return {255, 255, 255} elseif (ping > 120) then return {255, 255, 255} end end end another clientfile: --> Scripted by.: Bence Developer --> Screen screenX, screenY = guiGetScreenSize() x, y = screenX/1366, screenY/768 --> HUD Closed hudClosed = false --> Fonts roboto_8px = dxCreateFont("fonts/roboto.ttf", 8*x) roboto_9px = dxCreateFont("fonts/roboto.ttf", 9*x) roboto_12px = dxCreateFont("fonts/roboto.ttf", 12*x) roboto_13px = dxCreateFont("fonts/roboto.ttf", 13*x) roboto_16px = dxCreateFont("fonts/roboto.ttf", 16*x) roboto_20px = dxCreateFont("fonts/roboto.ttf", 20*x) --> Positions switchArrowPositions = {screenX-(311*x), 10*y, 47*x, 47*y} hudComponents = { {screenX-(264*x), 10*y, 254*x, 47*y}, {screenX-(264*x), 62*y, 254*x, 47*y}, {screenX-(264*x), 114*y, 254*x, 47*y}, {screenX-(264*x), 166*y, 254*x, 25*y}, } boxPositions = {screenX/2-225*x/2, screenY/2-125*y/2, 225*x, 125*y} --> Weapon names weaponNameByID = { [0] = "Fist", [1] = "B. Knuckle", [2] = "Golfclub", [3] = "Nightstick", [4] = "Knife", [5] = "Bat", [6] = "Shovel", [7] = "Poolstick", [8] = "Katana", [9] = "Chainsaw", [22] = "Colt 45", [23] = "Silenced", [24] = "Deagle", [25] = "Shotgun", [26] = "Sawed-off", [27] = "SPAZ-12", [28] = "Uzi", [29] = "MP5", [32] = "Tec-9", [30] = "AK-47", [31] = "M4", [33] = "Rifle", [34] = "Sniper", [35] = "Rocket L.", [36] = "HS. R. L.", [37] = "Flame T.", [38] = "Heavy MG", [16] = "Grenade", [17] = "Teargas", [18] = "Molotov", [39] = "Satchel", [41] = "Spraycan", [42] = "Fire Extin.", [43] = "Camera", [10] = "Dildo", [11] = "Dildo", [12] = "Vibrator", [14] = "Flower", [15] = "Cane", [44] = "Nightvision", [45] = "Infrared", [46] = "Parachute", [40] = "Detonator", } addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() setPlayerHudComponentVisible("all", false) setPlayerHudComponentVisible ("crosshair", true ) end ) addEventHandler("onClientResourceStop", getResourceRootElement(getThisResource()), function() setPlayerHudComponentVisible("all", true) if (blurShader) then blurShader = nil end end ) function showCursorBind () showCursor(not isCursorShowing()) end bindKey("K", "down", showCursorBind) --> Calculate FPS fpsTick = 0 addEventHandler("onClientPreRender", root, function() fpsTick = fpsTick + 1 end ) setTimer( function() setElementData(localPlayer, "player:fps", fpsTick) fpsTick = 0 end, 1000, 0 ) --> Usefull functions function isMouseInPosition (x, y, width, height) if (not isCursorShowing()) then return false end local cx, cy = getCursorPosition () local cx, cy = ( cx * screenX ), ( cy * screenY ) return ( ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) ) end function formatNumber(number) while true do number, k = string.gsub(number, "^(-?%d+)(%d%d%d)", '%1 %2') if k==0 then break end end return number end function dxDrawLinedRectangle( x, y, width, height, color, _width, postGUI ) _width = _width or 1 dxDrawLine ( x, y, x+width, y, color, _width, postGUI ) -- Top dxDrawLine ( x, y, x, y+height, color, _width, postGUI ) -- Left dxDrawLine ( x, y+height, x+width, y+height, color, _width, postGUI ) -- Bottom return dxDrawLine ( x+width, y, x+width, y+height, color, _width, postGUI ) -- Right end function roundedRectangle(x, y, w, h, borderColor, bgColor, postGUI) if (x and y and w and h) then if (not borderColor) then borderColor = tocolor(0, 0, 0, 200); end if (not bgColor) then bgColor = borderColor; end dxDrawRectangle(x, y, w, h, bgColor, postGUI); dxDrawRectangle(x + 2, y - 1, w - 4, 1, borderColor, postGUI); dxDrawRectangle(x + 2, y + h, w - 4, 1, borderColor, postGUI); dxDrawRectangle(x - 1, y + 2, 1, h - 4, borderColor, postGUI); dxDrawRectangle(x + w, y + 2, 1, h - 4, borderColor, postGUI); end end function dxDrawBorderedText (outline, text, left, top, right, bottom, color, scale, font, alignX, alignY, clip, wordBreak, postGUI, colorCoded, subPixelPositioning, fRotation, fRotationCenterX, fRotationCenterY) for oX = (outline * -1), outline do for oY = (outline * -1), outline do dxDrawText (text, left + oX, top + oY, right + oX, bottom + oY, tocolor(0, 0, 0, 255), scale, font, alignX, alignY, clip, wordBreak, postGUI, colorCoded, subPixelPositioning, fRotation, fRotationCenterX, fRotationCenterY) end end dxDrawText (text, left, top, right, bottom, color, scale, font, alignX, alignY, clip, wordBreak, postGUI, colorCoded, subPixelPositioning, fRotation, fRotationCenterX, fRotationCenterY) end Link to comment
Moderators Patrick Posted March 4, 2021 Moderators Share Posted March 4, 2021 Probably because getHealthColor function doesn't return a color if health > 100. Just remove '(health <= 100)' condition from the first IF. function getHealthColor(health) if (health > 0) then if (health > 50) then return {238, 71, 71} elseif (health <= 50) and (health > 25) then return {235, 52, 52} elseif (health <= 25) and (health > 0) then return {176, 24, 24} end else return {198, 195, 195} end end Link to comment
Bean666 Posted March 4, 2021 Author Share Posted March 4, 2021 4 minutes ago, Patrick said: Probably because getHealthColor function doesn't return a color if health > 100. Just remove '(health <= 100)' condition from the first IF. function getHealthColor(health) if (health > 0) then if (health > 50) then return {238, 71, 71} elseif (health <= 50) and (health > 25) then return {235, 52, 52} elseif (health <= 25) and (health > 0) then return {176, 24, 24} end else return {198, 195, 195} end end thanks! the only big flaw now of this script is whenever i restart it, we all crash hahahah idk the reason, but yeah it's all good. 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