Cadu12 Posted April 6, 2011 Posted April 6, 2011 I have 2 bugged If i have 2 colored it makes left If i dont have colored it makes right here is image: http://img593.imageshack.us/g/mtascreen ... 32140.png/ http://img21.imageshack.us/g/mtascreen2 ... 24847.png/ and here is code: function dxDrawColorText(str, ax, ay, bx, by, color, scale, font) local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find(pat, 1) local last = 1 while s do if cap == "" and col then color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), 255) end if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax+100, ay, ax + w, by, color, scale, font, "center", "bottom", false, false, false ) ax = ax + w color = tocolor(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), 255) end last = e + 1 s, e, cap, col = str:find(pat, last) end if last <= #str then cap = str:sub(last) local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax+100, ay, ax + w, by, color, scale, font, "center", "bottom", false, false, false ) end end local sx, sy = guiGetScreenSize() function drawPlayerTags() for i,v in ipairs(getElementsByType("player")) do if not v == getLocalPlayer() then local name = getPlayerName(v) local x, y, z = getCameraMatrix() local px,py = getScreenFromWorldPosition(x,y,z+0.3,0.06) local rx, ry, rz = getPedBonePosition(v, 3) local dist = getDistanceBetweenPoints3D(x, y, z, rx, ry, rz) if isLineOfSightClear(x, y, z, rx, ry, rz, true, false, false, true, false, false, false) and dist <= 45 then local r,g,b = getPlayerNametagColor(v) local cx, cy = getScreenFromWorldPosition(rx, ry, rz) if not cx or not cy then return end local nameW = dxGetTextWidth(name, 2, "default") local nameH = dxGetFontHeight(2, "default") local nameX, nameY = cx-(nameW/2), cy-(nameH*2) dxDrawColorText(name, nameX, nameY, sx, sy-300, tocolor(r, g, b, 255), 2, "default") end end end end addEventHandler("onClientRender",getRootElement(),drawPlayerTags)
MTA Team qaisjp Posted April 6, 2011 MTA Team Posted April 6, 2011 This is because the HEX values are also counted, I think. Use string.gsub and see if that works.
Cadu12 Posted April 6, 2011 Author Posted April 6, 2011 No, if i remove hex colors, the nametag will be remove color
#Paper Posted April 6, 2011 Posted April 6, 2011 I did try to use this code, but the nametag still be white...
MTA Team qaisjp Posted April 6, 2011 MTA Team Posted April 6, 2011 When using dxTextGetWidth in the message variable do string.gsub - So the text width is without the hex, although the hex is actually still there.
Castillo Posted April 6, 2011 Posted April 6, 2011 Actually, qais, i done that before giving him that code and didn't worked.
Cadu12 Posted April 6, 2011 Author Posted April 6, 2011 Right is fixed now, but left is bugged, here is image: http://img819.imageshack.us/g/mtascreen ... 82815.png/ here is code: local name = getPlayerName(player) local vehicleE = getPedOccupiedVehicle(player) local rx, ry, rz = getElementPosition ( vehicleE ) local cx, cy = getScreenFromWorldPosition(rx, ry, rz) local nameW = dxGetTextWidth(name, 2, "default") local nameH = dxGetFontHeight(2, "default") local nameX, nameY = cx-(nameW/2), cy-(nameH*2) if nametagscolored[player] == nil then name = string.format("#%02X%02X%02X", r, g, b) .. getPlayerName(player) vehicleE = getPedOccupiedVehicle(player) rx, ry, rz = getElementPosition ( vehicleE ) cx, cy = getScreenFromWorldPosition(rx, ry, rz) nameW = dxGetTextWidth(name, 2, "default") nameH = dxGetFontHeight(2, "default") nameX, nameY = cx-(nameW/2), cy-(nameH*2) dxDrawColorText( name, nameX, nameY, sx, sy, tocolor(r, g, b, 255), 2, "default", textscale*NAMETAG_TEXTSIZE) else dxDrawColorText( name, nameX, nameY, sx, sy, tocolor(r, g, b, 255), 2, "default", textscale*NAMETAG_TEXTSIZE) end
Castillo Posted April 6, 2011 Posted April 6, 2011 Yeah, that's the same problem i had when doing it.
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