Mefisto_PL Posted May 20, 2012 Share Posted May 20, 2012 Hello , I want to change font in killmessages and change dxDrawText to dxDrawColorText, but when I change the font, it doesn't shows any text.. When I change dxDrawText to dxDrawColorText , text change position.. It's fragment of code. local myFont = dxCreateFont("font.otf", 14) addEventHandler ( "onClientRender", getRootElement(), function() for self,_ in pairs(visibleText) do while true do if self.bDestroyed then visibleText[self] = nil break end local l,t,r,b --If we arent using a bounding box if not self.tBoundingBox then --Decide if we use relative or absolute local p_screenX,p_screenY = 1,1 if self.bRelativePosition then p_screenX,p_screenY = g_screenX,g_screenY end local fX,fY = (self.fX)*p_screenX,(self.fY)*p_screenY if self.bHorizontalAlign == "left" then l = fX r = fX + g_screenX elseif self.bHorizontalAlign == "right" then l = fX - g_screenX r = fX else l = fX - g_screenX r = fX + g_screenX end if self.bVerticalAlign == "top" then t = fY b = fY + g_screenY elseif self.bVerticalAlign == "bottom" then t = fY - g_screenY b = fY else t = fY - g_screenY b = fY + g_screenY end elseif type(self.tBoundingBox) == "table" then local b_screenX,b_screenY = 1,1 if self.bRelativeBoundingBox then b_screenX,b_screenY = g_screenX,g_screenY end l,t,r,b = self.tBoundingBox[1],self.tBoundingBox[2],self.tBoundingBox[3],self.tBoundingBox[4] l = l*b_screenX t = t*b_screenY r = r*b_screenX b = b*b_screenY end local type,att1,att2,att3,att4,att5 = self:type() if type == "border" or type == "stroke" then att2 = att2 or 0 att3 = att3 or 0 att4 = att4 or 0 att5 = att5 or self.tColor[4] outlinesize = att1 or 2 outlinesize = math.min(self.fScale,outlinesize) --Make sure the outline size isnt thicker than the size of the label if outlinesize > 0 then for offsetX=-outlinesize,outlinesize,outlinesize do for offsetY=-outlinesize,outlinesize,outlinesize do if not (offsetX == 0 and offsetY == 0) then dxDrawColorText(self.strText, l + offsetX, t + offsetY, r + offsetX, b + offsetY, tocolor(att2, att3, att4, att5), self.fScale, myFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI ) end end end end elseif type == "shadow" then local shadowDist = att1 att2 = att2 or 0 att3 = att3 or 0 att4 = att4 or 0 att5 = att5 or self.tColor[4] string.gsub(self.strText, '#%x%x%x%x%x%x', '') dxDrawColorText(self.strText, l + shadowDist, t + shadowDist, r + shadowDist, b + shadowDist, tocolor(att2, att3, att4, att5), self.fScale, myFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI ) end dxDrawColorText ( self.strText, l, t, r, b, tocolor(unpack(self.tColor)), self.fScale, myFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI ) break end end end ) if addEvent ( "updateDisplays", true ) then addEventHandler ( "updateDisplays", getRootElement(), function(self) setmetatable( self, dxText_mt ) --Remove any old ones with the same id for text,_ in pairs(visibleText) do if text.id == self.id then visibleText[text] = nil end end if self.bVisible and not self.bDestroyed then visibleText[self] = true end end ) end function dxDrawColorText(str, ax, ay, bx, by, color, scale, font, alignX, alignY) bx, by, color, scale, font = bx or ax, by or ay, color or tocolor(255,255,255,255), scale or 1, font or "default" if alignX then if alignX == "center" then ax = ax + (bx - ax - dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font))/2 elseif alignX == "right" then ax = bx - dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font) end end if alignY then if alignY == "center" then ay = ay + (by - ay - dxGetFontHeight(scale, font))/2 elseif alignY == "bottom" then ay = by - dxGetFontHeight(scale, font) end end local alpha = string.format("%08X", color):sub(1,2) 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(getColorFromString("#"..col..alpha)) end if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) ax = ax + w color = tocolor(getColorFromString("#"..col..alpha)) end last = e + 1 s, e, cap, col = str:find(pat, last) end if last <= #str then cap = str:sub(last) dxDrawText(cap, ax, ay, ax + dxGetTextWidth(cap, scale, font), by, color, scale, font) end end Link to comment
Jaysds1 Posted May 20, 2012 Share Posted May 20, 2012 (edited) try this: local visibleText = {} addEventHandler ( "onClientRender",root,function() local myFont = dxCreateFont("font.otf", 14) for self,_ in pairs(visibleText) do while true do if self.bDestroyed then visibleText[self] = nil break end local l,t,r,b --If we arent using a bounding box if not self.tBoundingBox then --Decide if we use relative or absolute local p_screenX,p_screenY = 1,1 if self.bRelativePosition then p_screenX,p_screenY = g_screenX,g_screenY end local fX,fY = (self.fX)*p_screenX,(self.fY)*p_screenY if self.bHorizontalAlign == "left" then l = fX r = fX + g_screenX elseif self.bHorizontalAlign == "right" then l = fX - g_screenX r = fX else l = fX - g_screenX r = fX + g_screenX end if self.bVerticalAlign == "top" then t = fY b = fY + g_screenY elseif self.bVerticalAlign == "bottom" then t = fY - g_screenY b = fY else t = fY - g_screenY b = fY + g_screenY end elseif type(self.tBoundingBox) == "table" then local b_screenX,b_screenY = 1,1 if self.bRelativeBoundingBox then b_screenX,b_screenY = g_screenX,g_screenY end l,t,r,b = self.tBoundingBox[1],self.tBoundingBox[2],self.tBoundingBox[3],self.tBoundingBox[4] l = l*b_screenX t = t*b_screenY r = r*b_screenX b = b*b_screenY end local type,att1,att2,att3,att4,att5 = self:type() if type == "border" or type == "stroke" then att2 = att2 or 0 att3 = att3 or 0 att4 = att4 or 0 att5 = att5 or self.tColor[4] outlinesize = att1 or 2 outlinesize = math.min(self.fScale,outlinesize) --Make sure the outline size isnt thicker than the size of the label if outlinesize > 0 then for offsetX=-outlinesize,outlinesize,outlinesize do for offsetY=-outlinesize,outlinesize,outlinesize do if not (offsetX == 0 and offsetY == 0) then dxDrawColorText(self.strText, l + offsetX, t + offsetY, r + offsetX, b + offsetY, tocolor(att2, att3, att4, att5), self.fScale, myFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI ) end end end end elseif type == "shadow" then local shadowDist = att1 att2 = att2 or 0 att3 = att3 or 0 att4 = att4 or 0 att5 = att5 or self.tColor[4] string.gsub(self.strText, '#%x%x%x%x%x%x', '') dxDrawColorText(self.strText, l + shadowDist, t + shadowDist, r + shadowDist, b + shadowDist, tocolor(att2, att3, att4, att5), self.fScale, myFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI ) end dxDrawColorText ( self.strText, l, t, r, b, tocolor(unpack(self.tColor)), self.fScale, myFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI ) break end end end ) addEvent ( "updateDisplays", true ) then addEventHandler ( "updateDisplays", getRootElement(),function(self) setmetatable( self, dxText_mt ) --Remove any old ones with the same id for text,_ in pairs(visibleText) do if text.id == self.id then visibleText[text] = nil end end if self.bVisible and not self.bDestroyed then visibleText[self] = true end end) function dxDrawColorText(str, ax, ay, bx, by, color, scale, font, alignX, alignY) bx, by, color, scale, font = bx or ax, by or ay, color or tocolor(255,255,255,255), scale or 1, font or "default" if alignX then if alignX == "center" then ax = ax + (bx - ax - dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font))/2 elseif alignX == "right" then ax = bx - dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font) end end if alignY then if alignY == "center" then ay = ay + (by - ay - dxGetFontHeight(scale, font))/2 elseif alignY == "bottom" then ay = by - dxGetFontHeight(scale, font) end end local alpha = string.format("%08X", color):sub(1,2) 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(getColorFromString("#"..col..alpha)) end if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) ax = ax + w color = tocolor(getColorFromString("#"..col..alpha)) end last = e + 1 s, e, cap, col = str:find(pat, last) end if last <= #str then cap = str:sub(last) dxDrawText(cap, ax, ay, ax + dxGetTextWidth(cap, scale, font), by, color, scale, font) end end EDITED it Edited May 21, 2012 by Guest Link to comment
Mefisto_PL Posted May 21, 2012 Author Share Posted May 21, 2012 don't working . : / ///EDIT Working , but the problem isn't fixed Link to comment
Jaysds1 Posted May 21, 2012 Share Posted May 21, 2012 try it again, I've edited it, BTW, When's this triggered? Link to comment
Mefisto_PL Posted May 21, 2012 Author Share Posted May 21, 2012 I don't send full code, I send what I changed . Link to comment
Mefisto_PL Posted May 21, 2012 Author Share Posted May 21, 2012 code work.. thanks.. but it doesn't change the font and the position doesn't changed. Link to comment
TwiX! Posted May 22, 2012 Share Posted May 22, 2012 (edited) fail, wrong topic Edited May 25, 2012 by Guest Link to comment
Mefisto_PL Posted May 25, 2012 Author Share Posted May 25, 2012 (edited) @UP Okey, I understand Edited May 26, 2012 by Guest Link to comment
TwiX! Posted May 25, 2012 Share Posted May 25, 2012 local visibleText = {} local myFont = dxCreateFont("font.otf", 14) addEventHandler ( "onClientRender",root,function() for self,_ in pairs(visibleText) do while true do if self.bDestroyed then visibleText[self] = nil break end local l,t,r,b --If we arent using a bounding box if not self.tBoundingBox then --Decide if we use relative or absolute local p_screenX,p_screenY = 1,1 if self.bRelativePosition then p_screenX,p_screenY = g_screenX,g_screenY end local fX,fY = (self.fX)*p_screenX,(self.fY)*p_screenY if self.bHorizontalAlign == "left" then l = fX r = fX + g_screenX elseif self.bHorizontalAlign == "right" then l = fX - g_screenX r = fX else l = fX - g_screenX r = fX + g_screenX end if self.bVerticalAlign == "top" then t = fY b = fY + g_screenY elseif self.bVerticalAlign == "bottom" then t = fY - g_screenY b = fY else t = fY - g_screenY b = fY + g_screenY end elseif type(self.tBoundingBox) == "table" then local b_screenX,b_screenY = 1,1 if self.bRelativeBoundingBox then b_screenX,b_screenY = g_screenX,g_screenY end l,t,r,b = self.tBoundingBox[1],self.tBoundingBox[2],self.tBoundingBox[3],self.tBoundingBox[4] l = l*b_screenX t = t*b_screenY r = r*b_screenX b = b*b_screenY end local type,att1,att2,att3,att4,att5 = self:type() if type == "border" or type == "stroke" then att2 = att2 or 0 att3 = att3 or 0 att4 = att4 or 0 att5 = att5 or self.tColor[4] outlinesize = att1 or 2 outlinesize = math.min(self.fScale,outlinesize) --Make sure the outline size isnt thicker than the size of the label if outlinesize > 0 then for offsetX=-outlinesize,outlinesize,outlinesize do for offsetY=-outlinesize,outlinesize,outlinesize do if not (offsetX == 0 and offsetY == 0) then dxDrawText(string.gsub(self.strText, '#%x%x%x%x%x%x', ''), l + offsetX, t + offsetY, r + offsetX, b + offsetY, tocolor(att2, att3, att4, att5), self.fScale, myFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI ) end end end end elseif type == "shadow" then local shadowDist = att1 att2 = att2 or 0 att3 = att3 or 0 att4 = att4 or 0 att5 = att5 or self.tColor[4] dxDrawText(string.gsub(self.strText, '#%x%x%x%x%x%x', ''), l + shadowDist, t + shadowDist, r + shadowDist, b + shadowDist, tocolor(att2, att3, att4, att5), self.fScale, myFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI ) end dxDrawColorText ( self.strText, l, t, r, b, tocolor(unpack(self.tColor)), self.fScale, myFont, self.bHorizontalAlign, self.bVerticalAlign, self.bClip, self.bWordWrap, self.bPostGUI ) break end end end ) addEvent ( "updateDisplays", true ) then addEventHandler ( "updateDisplays", getRootElement(),function(self) setmetatable( self, dxText_mt ) --Remove any old ones with the same id for text,_ in pairs(visibleText) do if text.id == self.id then visibleText[text] = nil end end if self.bVisible and not self.bDestroyed then visibleText[self] = true end end) function dxDrawColorText(str, ax, ay, bx, by, color, scale, font,alignX,alignY,clip, wordBreak, postGUI) if not str then return false end str = " "..str ax= ax - dxGetTextWidth(" ", 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 s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font,alignX,alignY,clip, wordBreak, postGUI) ax = ax + w color = tocolor(tonumber("0x"..string.sub(col, 1, 2)), tonumber("0x"..string.sub(col, 3, 4)), tonumber("0x"..string.sub(col, 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, ay, ax + w, by, color, scale, font,alignX,alignY,clip, wordBreak, postGUI) end end Link to comment
Anderl Posted May 26, 2012 Share Posted May 26, 2012 As far as I know, custom DX functions doesn't support custom fonts. You should use dxDrawText as it has now colorCoded parameter. Link to comment
Anderl Posted May 26, 2012 Share Posted May 26, 2012 It's for 1.3.1 onwards only. https://nightly.multitheftauto.com/mtasa-1.4-unstable-4151-20120526-net41D4.exe Is that hard to download 1.4 Development? Link to comment
Alpha Posted May 26, 2012 Share Posted May 26, 2012 Depends on what he's going to do, if he has a server, then he can't use it. If he's making a resource he can't release it for 1.3. So yes it's hard to use it now. Link to comment
Mefisto_PL Posted May 26, 2012 Author Share Posted May 26, 2012 I fix that. Nicks is on normal positions + shows nicks colors , but I want to change this stupid font :c 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