|
| 1 | + |
| 2 | +local font = dxCreateFont('client/arial.ttf', 10, true, 'default') or 'default' -- fallback to default |
| 3 | + |
| 4 | +HealthBarBorderVertices = |
| 5 | +{ |
| 6 | + {x=0, y=0, z=0, c=tocolor(0, 0, 0, 255)}, |
| 7 | + {x=0, y=0, z=0, c=tocolor(0, 0, 0, 255)}, |
| 8 | + {x=0, y=0, z=0, c=tocolor(0, 0, 0, 255)}, |
| 9 | + {x=0, y=0, z=0, c=tocolor(0, 0, 0, 255)} |
| 10 | +} |
| 11 | + |
| 12 | +HealthBarBackgroundVertices = |
| 13 | +{ |
| 14 | + {x=0, y=0, z=0, c=tocolor(75, 11, 20, 255)}, |
| 15 | + {x=0, y=0, z=0, c=tocolor(75, 11, 20, 255)}, |
| 16 | + {x=0, y=0, z=0, c=tocolor(75, 11, 20, 255)}, |
| 17 | + {x=0, y=0, z=0, c=tocolor(75, 11, 20, 255)} |
| 18 | +} |
| 19 | + |
| 20 | +HealthBarInnerVertices = |
| 21 | +{ |
| 22 | + {x=0, y=0, z=0, c=tocolor(185, 34, 40, 255)}, |
| 23 | + {x=0, y=0, z=0, c=tocolor(185, 34, 40, 255)}, |
| 24 | + {x=0, y=0, z=0, c=tocolor(185, 34, 40, 255)}, |
| 25 | + {x=0, y=0, z=0, c=tocolor(185, 34, 40, 255)} |
| 26 | +} |
| 27 | + |
| 28 | +function applyColorAlpha(color,alpha) |
| 29 | + if color < 0 then |
| 30 | + color = 0x100000000+color |
| 31 | + end |
| 32 | + local rgb = color%0x1000000 |
| 33 | + local a = (color-rgb)/0x1000000*alpha |
| 34 | + a = a-a%1 |
| 35 | + return rgb+a*0x1000000 |
| 36 | +end |
| 37 | + |
| 38 | +function drawNameTag(position, nameText, health, armor, distance) |
| 39 | + position.z = (distance * 0.025) + position.z + 0.3 |
| 40 | + |
| 41 | + local screenCoordsX, screenCoordsY = getScreenFromWorldPosition(position.x, position.y, position.z) |
| 42 | + |
| 43 | + if not screenCoordsX then |
| 44 | + return |
| 45 | + end |
| 46 | + |
| 47 | + local rect = {left = screenCoordsX, top = screenCoordsY, right = screenCoordsX+1, bottom = screenCoordsY+1} |
| 48 | + local textSizeX, textSizeY = dxGetTextSize(nameText, 0, 1, 1, font) |
| 49 | + |
| 50 | + rect.left = rect.left - (textSizeX/2) |
| 51 | + |
| 52 | + --doOutline(nameText, 1, 1, rect.left, rect.top) |
| 53 | + dxDrawText( |
| 54 | + nameText, rect.left + 1, rect.top, rect.right, rect.bottom, |
| 55 | + tocolor( 0, 0, 0, 255 ), 1, 1, |
| 56 | + |
| 57 | + font, "left", "top", false, false, |
| 58 | + false, false, false, |
| 59 | + 0, 0, 0 |
| 60 | + ) |
| 61 | + |
| 62 | + dxDrawText( |
| 63 | + nameText, rect.left - 1, rect.top, rect.right, rect.bottom, |
| 64 | + tocolor( 0, 0, 0, 255 ), 1, 1, |
| 65 | + |
| 66 | + font, "left", "top", false, false, |
| 67 | + false, false, false, |
| 68 | + 0, 0, 0 |
| 69 | + ) |
| 70 | + |
| 71 | + dxDrawText( |
| 72 | + nameText, rect.left, rect.top - 1, rect.right, rect.bottom, |
| 73 | + tocolor( 0, 0, 0, 255 ), 1, 1, |
| 74 | + |
| 75 | + font, "left", "top", false, false, |
| 76 | + false, false, false, |
| 77 | + 0, 0, 0 |
| 78 | + ) |
| 79 | + |
| 80 | + dxDrawText( |
| 81 | + nameText, rect.left, rect.top +1, rect.right, rect.bottom, |
| 82 | + tocolor( 0, 0, 0, 255 ), 1, 1, |
| 83 | + |
| 84 | + font, "left", "top", false, false, |
| 85 | + false, false, false, |
| 86 | + 0, 0, 0 |
| 87 | + ) |
| 88 | + |
| 89 | + dxDrawText( |
| 90 | + nameText, rect.left, rect.top, rect.right, rect.bottom, |
| 91 | + tocolor( 255, 255, 255, 255 ), 1, 1, |
| 92 | + |
| 93 | + font, "left", "top", false, false, |
| 94 | + false, false, false, |
| 95 | + 0, 0, 0 |
| 96 | + ) |
| 97 | + |
| 98 | + HealthBarBorderVertices[1].x = screenCoordsX - 20 -- Top left |
| 99 | + HealthBarBorderVertices[1].y = screenCoordsY + 18 |
| 100 | + HealthBarBorderVertices[2].x = screenCoordsX - 20 -- Bottom left |
| 101 | + HealthBarBorderVertices[2].y = screenCoordsY + 24 |
| 102 | + HealthBarBorderVertices[3].x = screenCoordsX + 21 -- Bottom right |
| 103 | + HealthBarBorderVertices[3].y = screenCoordsY + 24 |
| 104 | + HealthBarBorderVertices[4].x = screenCoordsX + 21 -- Top Right |
| 105 | + HealthBarBorderVertices[4].y = screenCoordsY + 18 |
| 106 | + |
| 107 | + HealthBarInnerVertices[1].x = screenCoordsX - 19 -- Top left |
| 108 | + HealthBarInnerVertices[1].y = screenCoordsY + 19 |
| 109 | + HealthBarInnerVertices[2].x = screenCoordsX - 19 -- Bottom left |
| 110 | + HealthBarInnerVertices[2].y = screenCoordsY + 23 |
| 111 | + HealthBarInnerVertices[3].x = screenCoordsX + 19 -- Bottom right |
| 112 | + HealthBarInnerVertices[3].y = screenCoordsY + 23 |
| 113 | + HealthBarInnerVertices[4].x = screenCoordsX + 19 -- Top Right |
| 114 | + HealthBarInnerVertices[4].y = screenCoordsY + 19 |
| 115 | + |
| 116 | + HealthBarBackgroundVertices[1].x = HealthBarInnerVertices[1].x |
| 117 | + HealthBarBackgroundVertices[1].y = HealthBarInnerVertices[1].y |
| 118 | + HealthBarBackgroundVertices[2].x = HealthBarInnerVertices[2].x |
| 119 | + HealthBarBackgroundVertices[2].y = HealthBarInnerVertices[2].y |
| 120 | + HealthBarBackgroundVertices[3].x = HealthBarInnerVertices[3].x |
| 121 | + HealthBarBackgroundVertices[3].y = HealthBarInnerVertices[3].y |
| 122 | + HealthBarBackgroundVertices[4].x = HealthBarInnerVertices[4].x |
| 123 | + HealthBarBackgroundVertices[4].y = HealthBarInnerVertices[4].y |
| 124 | + |
| 125 | + if health > 100 then |
| 126 | + health = 100 |
| 127 | + end |
| 128 | + health = health / 2.6 |
| 129 | + health = health - 19 |
| 130 | + |
| 131 | + HealthBarInnerVertices[3].x = screenCoordsX + health -- Bottom right |
| 132 | + HealthBarInnerVertices[4].x = screenCoordsX + health -- Top Right |
| 133 | + |
| 134 | + if armor > 0 then |
| 135 | + for i = 1,4 do |
| 136 | + HealthBarBorderVertices[i].y = HealthBarBorderVertices[i].y + 8 |
| 137 | + HealthBarBackgroundVertices[i].y = HealthBarBackgroundVertices[i].y + 8 |
| 138 | + HealthBarInnerVertices[i].y = HealthBarInnerVertices[i].y + 8 |
| 139 | + end |
| 140 | + end |
| 141 | + |
| 142 | + local healthBarBordersDxVertices = {} |
| 143 | + local healthBarBackgroundDxVertices = {} |
| 144 | + local healthBarInnerDxVertices = {} |
| 145 | + for i = 1,4 do |
| 146 | + table.insert(healthBarBordersDxVertices, {HealthBarBorderVertices[i].x, HealthBarBorderVertices[i].y, HealthBarBorderVertices[i].c}) |
| 147 | + table.insert(healthBarBackgroundDxVertices, {HealthBarBackgroundVertices[i].x, HealthBarBackgroundVertices[i].y, HealthBarBackgroundVertices[i].c}) |
| 148 | + table.insert(healthBarInnerDxVertices, {HealthBarInnerVertices[i].x, HealthBarInnerVertices[i].y, HealthBarInnerVertices[i].c}) |
| 149 | + end |
| 150 | + |
| 151 | + dxDrawPrimitive("trianglefan", false, unpack(healthBarBordersDxVertices)) |
| 152 | + dxDrawPrimitive("trianglefan", false, unpack(healthBarBackgroundDxVertices)) |
| 153 | + dxDrawPrimitive("trianglefan", false, unpack(healthBarInnerDxVertices)) |
| 154 | + |
| 155 | + -- Armor Bar |
| 156 | + if armor > 0 then |
| 157 | + for i = 1,4 do |
| 158 | + HealthBarBorderVertices[i].y = HealthBarBorderVertices[i].y - 8 |
| 159 | + HealthBarBackgroundVertices[i].y = HealthBarBackgroundVertices[i].y - 8 |
| 160 | + HealthBarInnerVertices[i].y = HealthBarInnerVertices[i].y - 8 |
| 161 | + end |
| 162 | + |
| 163 | + for i = 1,4 do |
| 164 | + HealthBarInnerVertices[i].c = tocolor(200, 200, 200, 255) |
| 165 | + HealthBarBackgroundVertices[i].c = tocolor(40, 40, 40, 255) |
| 166 | + end |
| 167 | + |
| 168 | + if armor > 100 then |
| 169 | + armor = 100 |
| 170 | + end |
| 171 | + armor = armor / 2.6 |
| 172 | + armor = armor - 19 |
| 173 | + |
| 174 | + HealthBarInnerVertices[3].x = screenCoordsX + armor -- Bottom right |
| 175 | + HealthBarInnerVertices[4].x = screenCoordsX + armor -- Top Right |
| 176 | + |
| 177 | + local armorBarBordersDxVertices = {} |
| 178 | + local armorBarBackgroundDxVertices = {} |
| 179 | + local armorBarInnerDxVertices = {} |
| 180 | + for i = 1,4 do |
| 181 | + table.insert(armorBarBordersDxVertices, {HealthBarBorderVertices[i].x, HealthBarBorderVertices[i].y, HealthBarBorderVertices[i].c}) |
| 182 | + table.insert(armorBarBackgroundDxVertices, {HealthBarBackgroundVertices[i].x, HealthBarBackgroundVertices[i].y, HealthBarBackgroundVertices[i].c}) |
| 183 | + table.insert(armorBarInnerDxVertices, {HealthBarInnerVertices[i].x, HealthBarInnerVertices[i].y, HealthBarInnerVertices[i].c}) |
| 184 | + end |
| 185 | + |
| 186 | + dxDrawPrimitive("trianglefan", false, unpack(armorBarBordersDxVertices)) |
| 187 | + dxDrawPrimitive("trianglefan", false, unpack(armorBarBackgroundDxVertices)) |
| 188 | + dxDrawPrimitive("trianglefan", false, unpack(armorBarInnerDxVertices)) |
| 189 | + |
| 190 | + for i = 1,4 do |
| 191 | + HealthBarInnerVertices[i].c = tocolor(185, 34, 40, 255) |
| 192 | + HealthBarBackgroundVertices[i].c = tocolor(75, 11, 20, 255) |
| 193 | + end |
| 194 | + end |
| 195 | +end |
| 196 | + |
| 197 | +addEventHandler( "onClientRender", root, |
| 198 | + function() |
| 199 | + local playerPosX, playerPosY, playerPosZ = getElementPosition(localPlayer) |
| 200 | + for k, player in pairs( getElementsByType("player") ) do |
| 201 | + if player ~= localPlayer and isElementOnScreen( player ) then |
| 202 | + --local fPosX, fPosY, fPosZ = getElementPosition(player) |
| 203 | + local fPosX, fPosY, fPosZ = getPedBonePosition(player, 8) |
| 204 | + local distance = getDistanceBetweenPoints3D(playerPosX, playerPosY, playerPosZ, fPosX, fPosY, fPosZ) |
| 205 | + if distance < 45 then |
| 206 | + local cx,cy,cz = getCameraMatrix(localPlayer) |
| 207 | + if isLineOfSightClear(cx,cy,cz, fPosX, fPosY, fPosZ, true, true, false, true, true, false, false) then |
| 208 | + drawNameTag({x = fPosX, y = fPosY, z = fPosZ}, getPlayerName(player) .. " (" .. getElemID(player) .. ")", getElementHealth(player), getPedArmor(player), distance) |
| 209 | + end |
| 210 | + end |
| 211 | + end |
| 212 | + end |
| 213 | + end |
| 214 | +) |
0 commit comments