Zuher Laith Posted January 23, 2016 Share Posted January 23, 2016 Hello Everyone .. In DxLibrary https://wiki.multitheftauto.com/wiki/Resource:DxLibrary I Want to make a Custom font that enabled on All Tools. To be More Clear .. In dxgui\elements\dx_text.lua local font1_segoeui = guiCreateFont("segoeui.ttf", 9) self.font = font1_segoeui The Default Settings Are .. self.font = "default" self.scale = 1 * 'self.scale' is the Size of the Text. * segoeui.ttf Added to META File. So what i'am doing is Editing the DxLibrary. When i tried that , the GUI Lagged & The Text didn't showed up. and no Error Given. am i missing something ? or the whole code is wrong ? .. Link to comment
tosfera Posted January 23, 2016 Share Posted January 23, 2016 You should always make sure that your returned element from guiCreateFont is an actual element. If it failed to create and you have overwritten the default font, it'll start to lag like spacing cows and eventually crash your client. Add a new if-statement after local font1_segoeui = ... to see if it isn't false. if it it, recreate it with the same line and proceed. Link to comment
Zuher Laith Posted January 23, 2016 Author Share Posted January 23, 2016 Add a new if-statement after local font1_segoeui = ... to see if it isn't false. if it it, recreate it with the same line and proceed. local myFont = guiCreateFont( "Font.ttf", 2 ) if myFont = false then local myFont = guiCreateFont( "Font.ttf", 2 ) end The GUI Started not Showing up, No Error Given. The Full Code: function dxText:create ( x, y, width, height, text, parent ) if not (x and y and width and height) then return; end local self = setmetatable({}, {__index = self}) local myFont = guiCreateFont( "Font.ttf", 2 ) if myFont = false then local myFont = guiCreateFont( "Font.ttf", 2 ) end self.type = "text" self.text = text or ""; self.x = x self.y = y self.width = width self.height = height self.font = "default" self.scale = 1 self.alignX = "left" self.alignY = "top" self.clip = false self.wordbreak = false self.color = {255, 255, 255, 255} self.visible = true self.render = true if parent then self.render = false self.parent = parent table.insert(parent.children, self) end table.insert(dxObjects, self) return self end dxText.new = dxText.create; Link to comment
tosfera Posted January 23, 2016 Share Posted January 23, 2016 Comparing values uses 2x = as in "==", not "=". Link to comment
Zuher Laith Posted January 23, 2016 Author Share Posted January 23, 2016 Comparing values uses 2x = as in "==", not "=". Same problem .. local myFont = guiCreateFont( "Font.ttf", 2 ) if myFont == false then local myFont = guiCreateFont( "Font.ttf", 2 ) end Link to comment
Zuher Laith Posted January 24, 2016 Author Share Posted January 24, 2016 Still Unsolved .. Any one have an idea about this ? Link to comment
Castillo Posted January 24, 2016 Share Posted January 24, 2016 Comparing values uses 2x = as in "==", not "=". Same problem .. local myFont = guiCreateFont( "Font.ttf", 2 ) if myFont == false then local myFont = guiCreateFont( "Font.ttf", 2 ) end "myFont" is defined as a local variable, it doesn't exist outside that 'if' condition. Link to comment
Zuher Laith Posted January 24, 2016 Author Share Posted January 24, 2016 "myFont" is defined as a local variable, it doesn't exist outside that 'if' condition. Thanks for The Tip .. It's Very helpful but still not the Solution for My Problem .. function dxText:create ( x, y, width, height, text, parent ) if not (x and y and width and height) then return; end local self = setmetatable({}, {__index = self}) myFont = guiCreateFont( "Font.ttf", 2 ) if myFont == false then myFont = guiCreateFont( "Font.ttf", 2 ) end self.type = "text" self.text = text or ""; self.x = x self.y = y self.width = width self.height = height self.font = myFont --self.scale = 1 self.alignX = "left" self.alignY = "top" self.clip = false self.wordbreak = false self.color = {255, 255, 255, 255} self.visible = true self.render = true if parent then self.render = false self.parent = parent table.insert(parent.children, self) end table.insert(dxObjects, self) return self end Link to comment
Castillo Posted January 24, 2016 Share Posted January 24, 2016 Post the code where the texts are drawn. Link to comment
Zuher Laith Posted January 25, 2016 Author Share Posted January 25, 2016 Post the code where the texts are drawn. Here it is .. gui = {}; -- Business Window gui.b = {label = {}, tab = {}, edit = {}, button = {}}; local width, height = 524, 300; local x = screen_width/2 - width/2; local y = screen_height/2 - height/2; gui.b.window = dxWindow(x, y, width, height, "اسم الوظيفة", false); gui.b.window.visible = false; gui.b.window:setTitleColor(125, 0, 0); gui.b.tab_panel = dxTabPanel(5, 50, 511, 231, gui.b.window); gui.b.tab.info = dxTab("المعلومات", gui.b.tab_panel); gui.b.label.id = dxText(10, 20, 81, 16, "الرقم: #", gui.b.tab.info); gui.b.label.name = dxText(10, 70, 241, 16, "الاسم:", gui.b.tab.info); gui.b.label.owner = dxText(10, 120, 231, 16, "المالك: ", gui.b.tab.info); gui.b.label.cost = dxText(10, 170, 191, 16, "السعر: ", gui.b.tab.info); gui.b.label.payout = dxText(290, 20, 211, 16, "الراتب: ", gui.b.tab.info); gui.b.label.payout_time = dxText(290, 70, 211, 16, "الدفع كل:", gui.b.tab.info); gui.b.label.location = dxText(290, 120, 211, 16, "الموقع:", gui.b.tab.info); gui.b.label.bank = dxText(290, 170, 211, 16, "البنك:", gui.b.tab.info); gui.b.label.id:setAlignX("left", false); gui.b.label.id:setAlignY("center"); gui.b.label.name:setAlignX("left", false); gui.b.label.name:setAlignY("center"); gui.b.label.owner:setAlignX("left", false); gui.b.label.owner:setAlignY("center"); gui.b.label.cost:setAlignX("left", false); gui.b.label.cost:setAlignY("center"); gui.b.label.payout:setAlignX("left", false); gui.b.label.payout:setAlignY("center"); gui.b.label.payout_time:setAlignX("left", false); gui.b.label.payout_time:setAlignY("center"); gui.b.label.location:setAlignX("left", false); gui.b.label.location:setAlignY("center"); gui.b.label.bank:setAlignX("left", false); gui.b.label.bank:setAlignY("center"); PS: You may find some arabic letters , don't give them attention. Link to comment
Castillo Posted January 25, 2016 Share Posted January 25, 2016 I mean the code where the dxTexts are drawn, the dxLibrary. Link to comment
Zuher Laith Posted January 26, 2016 Author Share Posted January 26, 2016 I mean the code where the dxTexts are drawn, the dxLibrary. Sorry for late respond. The Full for dx_text.lua: dxText = class ( 'dxText', dxGUI ) function dxText:create ( x, y, width, height, text, parent ) if not (x and y and width and height) then return; end local self = setmetatable({}, {__index = self}) self.type = "text" self.text = text or ""; self.x = x self.y = y self.width = width self.height = height self.font = "default" self.scale = 1 self.alignX = "left" self.alignY = "top" self.clip = false self.wordbreak = false self.color = {255, 255, 255, 255} self.visible = true self.render = true if parent then self.render = false self.parent = parent table.insert(parent.children, self) end table.insert(dxObjects, self) return self end dxText.new = dxText.create; function dxText:setAlignX ( alignX ) if (not alignX) then return; end self.alignX = alignX end function dxText:getAlignX ( ) return self.alignX end function dxText:setAlignY ( alignY ) if (not alignY) then return; end self.alignY = alignY end function dxText:getAlignY ( ) return self.alignY end function dxText:setClip ( clip ) self.clip = clip end function dxText:getClip ( ) return self.clip end function dxText:setWordbreak ( wordbreak ) self.wordbreak = wordbreak end function dxText:getWordbreak ( ) return self.wordbreak end function dxText:draw ( ) --dxDrawRectangle(self.x, self.y, self.width, self.height, tocolor(0, 0, 0, 150)) dxDrawText(self.text, self.x, self.y, self.x + self.width, self.y + self.height, tocolor(unpack(self.color)), self.scale, self.font, self.alignX, self.alignY, self.clip, self.wordbreak, false) end Link to comment
Zuher Laith Posted January 26, 2016 Author Share Posted January 26, 2016 Use 'dxCreateFont'. Still The Same Problem .. function dxText:create ( x, y, width, height, text, parent ) if not (x and y and width and height) then return; end local self = setmetatable({}, {__index = self}) local myFont = dxCreateFont( "Font.ttf", 2 ) self.type = "text" self.text = text or ""; self.x = x self.y = y self.width = width self.height = height self.font = myFont --self.scale = 1 self.alignX = "left" self.alignY = "top" self.clip = false self.wordbreak = false self.color = {255, 255, 255, 255} self.visible = true self.render = true if parent then self.render = false self.parent = parent table.insert(parent.children, self) end table.insert(dxObjects, self) return self end dxText.new = dxText.create; Debug Script Error: WARNING: business\dxgui\dxgui\elements\dx_text.lua:73: Bad argument @ 'dxDrawText' [Expected dx-font at argument 8, got boolean Link to comment
Castillo Posted January 26, 2016 Share Posted January 26, 2016 Is the font being created? Add: outputChatBox ( tostring ( myFont ) ) after dxCreateFont. Link to comment
Zuher Laith Posted January 27, 2016 Author Share Posted January 27, 2016 Is the font being created?Add: outputChatBox ( tostring ( myFont ) ) after dxCreateFont. The OutputChatBox Send "false" to chat. Here is an Image Preview The Lua Code: function dxText:create ( x, y, width, height, text, parent ) if not (x and y and width and height) then return; end local self = setmetatable({}, {__index = self}) local myFont = dxCreateFont( "Font.ttf", 2 ) outputChatBox ( tostring ( myFont ) ) self.type = "text" self.text = text or ""; self.x = x self.y = y self.width = width self.height = height self.font = myFont --self.scale = 1 self.alignX = "left" self.alignY = "top" self.clip = false self.wordbreak = false self.color = {255, 255, 255, 255} self.visible = true self.render = true if parent then self.render = false self.parent = parent table.insert(parent.children, self) end table.insert(dxObjects, self) return self end Link to comment
tosfera Posted January 27, 2016 Share Posted January 27, 2016 The lagging part is because it's trying to render an element each frame and it returns an error. That comes up to fps * error for each second. If you're running at 60 fps normally, it'll try to output 60 errors a second and lag your ass so hard that you're forced to stop the resource or close the window. The fact that the font has been returned as false gives you some shady information. You're getting a false which tells us that either the file couldn't be loaded or there were some wrong parameters. Let's go over everything you've done in the code. local myFont = dxCreateFont ( "Font.ttf", 2 ) You're using Font.ttf as a file, is it in the meta.xml? is the filename also a capital F? are you sure you want to have it as 2 in font size. That's 2 pixels.. something for ants. outputChatBox ( tostring ( myFont ) ) This returned false, try to add a try-catch on a dirty way by doing this; local myFont = dxCreateFont ( "Font.ttf", 2 ) if ( not myFont ) then myFont = dxCreateFont ( "Font.ttf", 2 ) end If that doesn't work, there might be something wrong with the memory free for MTA. Use DxGetStatus to see if you have any value in VideoMemoryFreeForMTA. If this returns false or 0, you're not going to get this to work. To built that into your entire system, you can add an if-statement like this; local myFont = nil; if ( dxGetStatus().VideoMemoryFreeForMTA > 0 ) then myFont = dxCreateFont ( "Font.ttf", 2 ); if ( not myFont ) then myFont = dxCreateFont ( "Font.ttf", 2 ); if ( not myFont ) then myFont = "default"; end end else myFont = "default"; end Link to comment
Zuher Laith Posted January 27, 2016 Author Share Posted January 27, 2016 @tosfera There is Some Responding .. debugscript Give's "File Not Found" . File Name: "Font.ttf" META #1 (Main) * Check Line 53 "JR10" name = "Business System" version = "1.3.0" type = "script" /> META #2 (Dx Library Meta) * Check Line 33 true client="1.4.0" server="1.4.0" /> -- Shared --> So Here's The Basic Script Map: Image Link to comment
tosfera Posted January 28, 2016 Share Posted January 28, 2016 try to make it a "type='client'" @ the file element. Link to comment
Zuher Laith Posted January 28, 2016 Author Share Posted January 28, 2016 try to make it a "type='client'" @ the file element. Well .. "dxgui/dxgui/elements/Font.ttf" type="client" /> I guess Nothing wrong here right ? maybe i'am putting the font in wrong path or something ? .. Link to comment
tosfera Posted January 28, 2016 Share Posted January 28, 2016 OH, you said something quite good there. You have to include the entire path to the file in your script. Try to change the path to the file entirely ( "dxgui/dxgui/elements/Font.ttf", why 2x dxgui though? ) like this; local myFont = nil; if ( dxGetStatus().VideoMemoryFreeForMTA > 0 ) then myFont = dxCreateFont ( "dxgui/dxgui/elements/Font.ttf", 2 ); if ( not myFont ) then myFont = dxCreateFont ( "dxgui/dxgui/elements/Font.ttf", 2 ); if ( not myFont ) then myFont = "default"; end end else myFont = "default"; end Link to comment
Zuher Laith Posted January 28, 2016 Author Share Posted January 28, 2016 @tosfera i changed the font size to 9 , never mind. On debug script , here is the error: WARNING: business\dxgui\dxgui\elements\dx_text.lua:82: Bad argument @ 'dxDrawText' [Expected dx-font at argument 8, got nil and here is the Code that have an error: function dxText:draw ( ) dxDrawText(self.text, self.x, self.y, self.x + self.width, self.y + self.height, tocolor(unpack(self.color)), self.scale, self.font, self.alignX, self.alignY, self.clip, self.wordbreak, false) end & here's a Look of the Full Code of dx_text.lua: dxText = class ( 'dxText', dxGUI ) function dxText:create ( x, y, width, height, text, parent ) if not (x and y and width and height) then return; end local self = setmetatable({}, {__index = self}) self.type = "text" self.text = text or ""; self.x = x self.y = y self.width = width self.height = height myFont = nil; if ( dxGetStatus().VideoMemoryFreeForMTA > 0 ) then myFont = dxCreateFont ( "dxgui/dxgui/elements/Font.ttf", 9 ); if ( not myFont ) then myFont = dxCreateFont ( "dxgui/dxgui/elements/Font.ttf", 9 ); if ( not myFont ) then myFont = "default"; end end else myFont = "default"; end outputChatBox ( tostring ( myFont ) ) self.font = myFonts --self.scale = 1 self.alignX = "left" self.alignY = "top" self.clip = false self.wordbreak = false self.color = {255, 255, 255, 255} self.visible = true self.render = true if parent then self.render = false self.parent = parent table.insert(parent.children, self) end table.insert(dxObjects, self) return self end dxText.new = dxText.create; dxText.new = dxText.create; function dxText:setAlignX ( alignX ) if (not alignX) then return; end self.alignX = alignX end function dxText:getAlignX ( ) return self.alignX end function dxText:setAlignY ( alignY ) if (not alignY) then return; end self.alignY = alignY end function dxText:getAlignY ( ) return self.alignY end function dxText:setClip ( clip ) self.clip = clip end function dxText:getClip ( ) return self.clip end function dxText:setWordbreak ( wordbreak ) self.wordbreak = wordbreak end function dxText:getWordbreak ( ) return self.wordbreak end function dxText:draw ( ) --dxDrawRectangle(self.x, self.y, self.width, self.height, tocolor(0, 0, 0, 150)) dxDrawText(self.text, self.x, self.y, self.x + self.width, self.y + self.height, tocolor(unpack(self.color)), self.scale, self.font, self.alignX, self.alignY, self.clip, self.wordbreak, false) end outputChatBox Give's a Value's or Something .. userdata: 09A8D928 userdata: 09A89008 userdata: 09A93170 userdata: 09A8AF98 userdata: 09A8CE88 userdata: 09B9FAB8 userdata: 09B97C28 userdata: 09BA6D68 userdata: 09BA2740 userdata: 09B9F018 userdata: 09B99A50 userdata: 09B9DCE0 userdata: 09B9B5A8 userdata: 09B9E2A8 userdata: 09B9A9F0 userdata: 09B99C80 userdata: 09B99D70 Link to comment
Dealman Posted January 28, 2016 Share Posted January 28, 2016 Always double-check your code for typos. outputChatBox ( tostring ( myFont ) ) self.font = myFonts myFont does not equal myFonts Link to comment
Zuher Laith Posted January 28, 2016 Author Share Posted January 28, 2016 @Dealman LOL Didn't Noticed That because of the Notepad ++ .. @tosfera You're Awesome .. Thanks for Help ! Problem Solved. 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