Dead7ucky Posted May 31, 2017 Share Posted May 31, 2017 I have a problem in the script. Error attempt to perform arithmetic on local ''priceWidth" (a boolean value) string local hearderScale = math.min(1, (resolution.x - 60 - priceWidth) / hearderWidth) Link to comment
Hale Posted May 31, 2017 Share Posted May 31, 2017 Could you show us the entire function? Is the priceWidth variable declared at all? Link to comment
Dead7ucky Posted May 31, 2017 Author Share Posted May 31, 2017 25 minutes ago, Hale said: Could you show us the entire function? Is the priceWidth variable declared at all? Here is the complete code CarshopMenu = {} local renderTarget local MENU_OFFSET = Vector3(-7.5, -7, -0.7) local position = Vector3() local size = Vector2(1.5, 1.9) local rotation = 280 local resolution = size * 250 local headerHeight = 70 local barOffset = 20 local barHeight = 20 local labelHeight = 50 local barsList = { {locale = "carshop_label_speed", value = 0.7, param = "speed"}, {locale = "carshop_label_acceleration", value = 0.4, param = "acceleration"}, {locale = "carshop_label_control", value = 0.85, param = "control"} } local headerFont local labelFont local hasDriftHandling = false local themeColor = {0, 0, 0} local themeColorHex = "#FFFFFF" local function draw() dxSetRenderTarget(renderTarget) dxDrawRectangle(0, 0, resolution.x, resolution.y, tocolor(42, 40, 41)) dxDrawRectangle(0, 0, resolution.x, headerHeight, tocolor(32, 30, 31)) local priceText = "" if Carshop.currentVehicleInfo.price > 0 then priceText = "$" .. tostring(Carshop.currentVehicleInfo.price) else priceText = exports.dpLang:getString("price_free") end dxDrawText(priceText, 0, 0, resolution.x - 20, headerHeight, tocolor(themeColor[1], themeColor[2], themeColor[3]), 1, labelFont, "right", "center") local priceWidth = dxGetTextWidth(priceText, 1, labelFont) local headerText = Carshop.currentVehicleInfo.name local hearderWidth = dxGetTextWidth(headerText, 1, headerFont) local hearderScale = math.min(1, (resolution.x - 60 - priceWidth) / hearderWidth) dxDrawText(headerText, 20, 0, resolution.x - 20 - priceWidth, headerHeight, tocolor(255, 255, 255), hearderScale, headerFont, "left", "center", true) local buyButtonActive = true local buyButtonText = exports.dpLang:getString("carshop_buy_button") if Carshop.currentVehicleInfo.level > localPlayer:getData("level") then buyButtonActive = false --"Требуется уровень " .. buyButtonText = string.format(exports.dpLang:getString("carshop_required_level"), tostring(Carshop.currentVehicleInfo.level)) elseif Carshop.currentVehicleInfo.price > localPlayer:getData("money") then buyButtonActive = false buyButtonText = exports.dpLang:getString("carshop_no_money") end if not buyButtonActive then dxDrawRectangle(0, resolution.y - headerHeight, resolution.x, headerHeight, tocolor(32, 30, 31)) dxDrawText(buyButtonText, 20, resolution.y - headerHeight, resolution.x, resolution.y, tocolor(255, 255, 255, 150), 1, headerFont, "center", "center") else dxDrawRectangle(0, resolution.y - headerHeight, resolution.x, headerHeight, tocolor(themeColor[1], themeColor[2], themeColor[3])) dxDrawText(buyButtonText, 20, resolution.y - headerHeight, resolution.x, resolution.y, tocolor(255, 255, 255), 1, headerFont, "center", "center") end local y = headerHeight local barWidth = resolution.x - barOffset * 2 for i, bar in ipairs(barsList) do -- Подпись dxDrawText(bar.text, 0, y, resolution.x, y + labelHeight, tocolor(255, 255, 255), 1, labelFont, "center", "center") y = y + labelHeight dxDrawRectangle(barOffset, y, barWidth, barHeight, tocolor(65, 65, 65)) dxDrawRectangle(barOffset, y, barWidth * bar.value, barHeight, tocolor(themeColor[1], themeColor[2], themeColor[3])) bar.value = bar.value + (Carshop.currentVehicleInfo.specs[bar.param] - bar.value) * 0.2 y = y + barHeight * 2 end local labelText = exports.dpLang:getString("carshop_drift_label") local valueText = "" if Carshop.hasDriftHandling then valueText = exports.dpLang:getString("carshop_drift_label_yes") else valueText = exports.dpLang:getString("carshop_drift_label_no") end dxDrawText(labelText .. ": " .. themeColorHex .. valueText, 0, y, resolution.x, y + labelHeight, tocolor(255, 255, 255), 1, labelFont, "center", "center", false, false, false, true) dxSetRenderTarget() local halfHeight = Vector3(0, 0, size.y / 2) local rad = math.rad(rotation) local lookOffset = Vector3(math.cos(rad), math.sin(rad), 0) dxDrawMaterialLine3D( position + halfHeight, position - halfHeight, renderTarget, size.x, tocolor(255, 255, 255, 250), position + lookOffset ) end function CarshopMenu.start(basePosition) position = MENU_OFFSET + basePosition renderTarget = dxCreateRenderTarget(resolution.x, resolution.y, false) headerFont = exports.dpAssets:createFont("Roboto-Regular.ttf", 20) labelFont = exports.dpAssets:createFont("Roboto-Regular.ttf", 18) themeColor = {exports.dpUI:getThemeColor()} themeColorHex = tostring(exports.dpUtils:RGBToHex(unpack(themeColor))) for i, bar in ipairs(barsList) do bar.text = exports.dpLang:getString(bar.locale) end addEventHandler("onClientRender", root, draw) end function CarshopMenu.stop() if isElement(renderTarget) then destroyElement(renderTarget) end if isElement(headerFont) then destroyElement(headerFont) end if isElement(labelFont) then destroyElement(labelFont) end removeEventHandler("onClientRender", root, draw) end Link to comment
Hale Posted May 31, 2017 Share Posted May 31, 2017 Try debugging your function by adding: outputDebugString(priceText) after this: if Carshop.currentVehicleInfo.price > 0 then priceText = "$" .. tostring(Carshop.currentVehicleInfo.price) else priceText = exports.dpLang:getString("price_free") end One of those two declarements isn't working properly. Link to comment
Dead7ucky Posted May 31, 2017 Author Share Posted May 31, 2017 And also I think that this Warning Affects my problem. Warning:dpAssetst\client\exports.lua:33:Error creating font @ 'dxCreateFont' [assest/Fonts/Roboto-Regular.ttf] FULL CODE (EXPORTS.LUA) All Fonts are in the folder. local ASSETS_PATH = "assets/" local SHADERS_PATH = "shaders/" local TEXTURES_PATH = "textures/" local FONTS_PATH = "fonts/" local cache = { textures = {}, shaders = {}, fonts = {} } local function setupElementParent(element, resource) if not element or not resource then return false end element.parent = getResourceDynamicElementRoot(resource) return true end function createShader(name, ...) local element = dxCreateShader(ASSETS_PATH .. SHADERS_PATH .. tostring(name), ...) setupElementParent(element, sourceResource) return element end function createTexture(name, ...) local element = dxCreateTexture(ASSETS_PATH .. TEXTURES_PATH .. tostring(name), ...) setupElementParent(element, sourceResource) return element end function createFont(name, ...) local element = dxCreateFont(ASSETS_PATH .. FONTS_PATH .. tostring(name), ...) setupElementParent(element, sourceResource) return element end function createShaderCached(name, ...) if not name then return false end if cache.shaders[name] then return cache.shaders[name] end cache.shaders[name] = createShader(name, ...) setupElementParent(cache.shaders[name], sourceResource) return cache.shaders[name] end function createTextureCached(name, ...) if not name then return false end if cache.textures[name] then return cache.textures[name] end cache.textures[name] = createTexture(name, ...) setupElementParent(cache.textures[name], sourceResource) return cache.textures[name] end function createFontCached(name, ...) if not name then return false end if cache.fonts[name] then return cache.fonts[name] end cache.fonts[name] = createFont(name, ...) setupElementParent(cache.fonts[name], sourceResource) return cache.fonts[name] end Link to comment
Hale Posted May 31, 2017 Share Posted May 31, 2017 (edited) Is that exact font existing, and is it declared in meta.xml? EDIT: I'm not sure if you can export fonts like the way you did. Is this working in other scripts? Edited May 31, 2017 by Hale Link to comment
Dead7ucky Posted May 31, 2017 Author Share Posted May 31, 2017 7 minutes ago, Hale said: Is that exact font existing, and is it declared in meta.xml? Yes in meta.xml It is declared 10 minutes ago, Hale said: EDIT: I'm not sure if you can export fonts like the way you did. Is this working in other scripts? In other scripts everywhere similar warnings Link to comment
Hale Posted May 31, 2017 Share Posted May 31, 2017 Just now, Dead7ucky said: In other scripts everywhere similar warnings That means you cannot use those exports (if I'm not wrong), so you should replace this: exports.dpAssets:createFont with dxCreateFont. Link to comment
Dead7ucky Posted May 31, 2017 Author Share Posted May 31, 2017 (edited) 2 minutes ago, Hale said: That means you cannot use those exports (if I'm not wrong), so you should replace this: exports.dpAssets:createFont with dxCreateFont. Maybe you're downloading this mod and see for yourself what the problem is? Mod Located on GITHUB Edited May 31, 2017 by Dead7ucky UPD Link to comment
koragg Posted June 1, 2017 Share Posted June 1, 2017 (edited) Try this this to fix your boolean error: CarshopMenu = {} local renderTarget local MENU_OFFSET = Vector3(-7.5, -7, -0.7) local position = Vector3() local size = Vector2(1.5, 1.9) local rotation = 280 local resolution = size * 250 local headerHeight = 70 local barOffset = 20 local barHeight = 20 local labelHeight = 50 local barsList = { {locale = "carshop_label_speed", value = 0.7, param = "speed"}, {locale = "carshop_label_acceleration", value = 0.4, param = "acceleration"}, {locale = "carshop_label_control", value = 0.85, param = "control"} } local headerFont local labelFont local hasDriftHandling = false local themeColor = {0, 0, 0} local themeColorHex = "#FFFFFF" local function draw() dxSetRenderTarget(renderTarget) dxDrawRectangle(0, 0, resolution.x, resolution.y, tocolor(42, 40, 41)) dxDrawRectangle(0, 0, resolution.x, headerHeight, tocolor(32, 30, 31)) local priceText = "" if Carshop.currentVehicleInfo.price > 0 then priceText = "$" .. tostring(Carshop.currentVehicleInfo.price) else priceText = exports.dpLang:getString("price_free") end dxDrawText(priceText, 0, 0, resolution.x - 20, headerHeight, tocolor(themeColor[1], themeColor[2], themeColor[3]), 1, labelFont, "right", "center") local priceWidth = dxGetTextWidth(priceText, 1, labelFont) local headerText = Carshop.currentVehicleInfo.name local hearderWidth = dxGetTextWidth(headerText, 1, headerFont) local hearderScale = false if priceWidth then hearderScale = math.min(1, (resolution.x - 60 - priceWidth) / hearderWidth) dxDrawText(headerText, 20, 0, resolution.x - 20 - priceWidth, headerHeight, tocolor(255, 255, 255), hearderScale, headerFont, "left", "center", true) end local buyButtonActive = true local buyButtonText = exports.dpLang:getString("carshop_buy_button") if Carshop.currentVehicleInfo.level > localPlayer:getData("level") then buyButtonActive = false --"Требуется уровень " .. buyButtonText = string.format(exports.dpLang:getString("carshop_required_level"), tostring(Carshop.currentVehicleInfo.level)) elseif Carshop.currentVehicleInfo.price > localPlayer:getData("money") then buyButtonActive = false buyButtonText = exports.dpLang:getString("carshop_no_money") end if not buyButtonActive then dxDrawRectangle(0, resolution.y - headerHeight, resolution.x, headerHeight, tocolor(32, 30, 31)) dxDrawText(buyButtonText, 20, resolution.y - headerHeight, resolution.x, resolution.y, tocolor(255, 255, 255, 150), 1, headerFont, "center", "center") else dxDrawRectangle(0, resolution.y - headerHeight, resolution.x, headerHeight, tocolor(themeColor[1], themeColor[2], themeColor[3])) dxDrawText(buyButtonText, 20, resolution.y - headerHeight, resolution.x, resolution.y, tocolor(255, 255, 255), 1, headerFont, "center", "center") end local y = headerHeight local barWidth = resolution.x - barOffset * 2 for i, bar in ipairs(barsList) do -- Подпись dxDrawText(bar.text, 0, y, resolution.x, y + labelHeight, tocolor(255, 255, 255), 1, labelFont, "center", "center") y = y + labelHeight dxDrawRectangle(barOffset, y, barWidth, barHeight, tocolor(65, 65, 65)) dxDrawRectangle(barOffset, y, barWidth * bar.value, barHeight, tocolor(themeColor[1], themeColor[2], themeColor[3])) bar.value = bar.value + (Carshop.currentVehicleInfo.specs[bar.param] - bar.value) * 0.2 y = y + barHeight * 2 end local labelText = exports.dpLang:getString("carshop_drift_label") local valueText = "" if Carshop.hasDriftHandling then valueText = exports.dpLang:getString("carshop_drift_label_yes") else valueText = exports.dpLang:getString("carshop_drift_label_no") end dxDrawText(labelText .. ": " .. themeColorHex .. valueText, 0, y, resolution.x, y + labelHeight, tocolor(255, 255, 255), 1, labelFont, "center", "center", false, false, false, true) dxSetRenderTarget() local halfHeight = Vector3(0, 0, size.y / 2) local rad = math.rad(rotation) local lookOffset = Vector3(math.cos(rad), math.sin(rad), 0) dxDrawMaterialLine3D( position + halfHeight, position - halfHeight, renderTarget, size.x, tocolor(255, 255, 255, 250), position + lookOffset ) end function CarshopMenu.start(basePosition) position = MENU_OFFSET + basePosition renderTarget = dxCreateRenderTarget(resolution.x, resolution.y, false) headerFont = exports.dpAssets:createFont("Roboto-Regular.ttf", 20) labelFont = exports.dpAssets:createFont("Roboto-Regular.ttf", 18) themeColor = {exports.dpUI:getThemeColor()} themeColorHex = tostring(exports.dpUtils:RGBToHex(unpack(themeColor))) for i, bar in ipairs(barsList) do bar.text = exports.dpLang:getString(bar.locale) end addEventHandler("onClientRender", root, draw) end function CarshopMenu.stop() if isElement(renderTarget) then destroyElement(renderTarget) end if isElement(headerFont) then destroyElement(headerFont) end if isElement(labelFont) then destroyElement(labelFont) end removeEventHandler("onClientRender", root, draw) end Also, I don't see "labelFont" declared to an actual font anywhere. I mean at line 21 you do "local labelFont" but then you don't give it any value before using it at lines 38 and 40. Here's an example of how to import a custom font from a file inside any script: Digital = dxCreateFont("Digital.ttf", 21) --Custom font I added a check at line 45, that should fix the boolean error. Always when it gives boolean errors/warnings that means that the script is not sure if the thing given in the error message is there or not. It can be a file, variable, font, pretty much anything. Most times a simple "if" statement gets rid of the error. This way you tell the script explicitly to check if the wanted/needed thing is actually there or not. Hope something out of this post helps you out. Edited June 1, 2017 by koragg Next time please include [QUESTION] before the title of the topic if it's a question and try to describe the problem with a few words in the topic title. "Help Me Please" means nothing but "Problem with fonts" or "Help me fix boolean error" is far better. Link to comment
Dead7ucky Posted June 1, 2017 Author Share Posted June 1, 2017 1 hour ago, koragg said: Try this this to fix your boolean error: CarshopMenu = {}local renderTargetlocal MENU_OFFSET = Vector3(-7.5, -7, -0.7)local position = Vector3()local size = Vector2(1.5, 1.9)local rotation = 280local resolution = size * 250local headerHeight = 70local barOffset = 20local barHeight = 20local labelHeight = 50local barsList = { {locale = "carshop_label_speed", value = 0.7, param = "speed"}, {locale = "carshop_label_acceleration", value = 0.4, param = "acceleration"}, {locale = "carshop_label_control", value = 0.85, param = "control"}}local headerFontlocal labelFontlocal hasDriftHandling = falselocal themeColor = {0, 0, 0}local themeColorHex = "#FFFFFF"local function draw() dxSetRenderTarget(renderTarget) dxDrawRectangle(0, 0, resolution.x, resolution.y, tocolor(42, 40, 41)) dxDrawRectangle(0, 0, resolution.x, headerHeight, tocolor(32, 30, 31)) local priceText = "" if Carshop.currentVehicleInfo.price > 0 then priceText = "$" .. tostring(Carshop.currentVehicleInfo.price) else priceText = exports.dpLang:getString("price_free") end dxDrawText(priceText, 0, 0, resolution.x - 20, headerHeight, tocolor(themeColor[1], themeColor[2], themeColor[3]), 1, labelFont, "right", "center") local priceWidth = dxGetTextWidth(priceText, 1, labelFont) local headerText = Carshop.currentVehicleInfo.name local hearderWidth = dxGetTextWidth(headerText, 1, headerFont) local hearderScale = false if priceWidth then hearderScale = math.min(1, (resolution.x - 60 - priceWidth) / hearderWidth) dxDrawText(headerText, 20, 0, resolution.x - 20 - priceWidth, headerHeight, tocolor(255, 255, 255), hearderScale, headerFont, "left", "center", true) end local buyButtonActive = true local buyButtonText = exports.dpLang:getString("carshop_buy_button") if Carshop.currentVehicleInfo.level > localPlayer:getData("level") then buyButtonActive = false --"Требуется уровень " .. buyButtonText = string.format(exports.dpLang:getString("carshop_required_level"), tostring(Carshop.currentVehicleInfo.level)) elseif Carshop.currentVehicleInfo.price > localPlayer:getData("money") then buyButtonActive = false buyButtonText = exports.dpLang:getString("carshop_no_money") end if not buyButtonActive then dxDrawRectangle(0, resolution.y - headerHeight, resolution.x, headerHeight, tocolor(32, 30, 31)) dxDrawText(buyButtonText, 20, resolution.y - headerHeight, resolution.x, resolution.y, tocolor(255, 255, 255, 150), 1, headerFont, "center", "center") else dxDrawRectangle(0, resolution.y - headerHeight, resolution.x, headerHeight, tocolor(themeColor[1], themeColor[2], themeColor[3])) dxDrawText(buyButtonText, 20, resolution.y - headerHeight, resolution.x, resolution.y, tocolor(255, 255, 255), 1, headerFont, "center", "center") end local y = headerHeight local barWidth = resolution.x - barOffset * 2 for i, bar in ipairs(barsList) do -- Подпись dxDrawText(bar.text, 0, y, resolution.x, y + labelHeight, tocolor(255, 255, 255), 1, labelFont, "center", "center") y = y + labelHeight dxDrawRectangle(barOffset, y, barWidth, barHeight, tocolor(65, 65, 65)) dxDrawRectangle(barOffset, y, barWidth * bar.value, barHeight, tocolor(themeColor[1], themeColor[2], themeColor[3])) bar.value = bar.value + (Carshop.currentVehicleInfo.specs[bar.param] - bar.value) * 0.2 y = y + barHeight * 2 end local labelText = exports.dpLang:getString("carshop_drift_label") local valueText = "" if Carshop.hasDriftHandling then valueText = exports.dpLang:getString("carshop_drift_label_yes") else valueText = exports.dpLang:getString("carshop_drift_label_no") end dxDrawText(labelText .. ": " .. themeColorHex .. valueText, 0, y, resolution.x, y + labelHeight, tocolor(255, 255, 255), 1, labelFont, "center", "center", false, false, false, true) dxSetRenderTarget() local halfHeight = Vector3(0, 0, size.y / 2) local rad = math.rad(rotation) local lookOffset = Vector3(math.cos(rad), math.sin(rad), 0) dxDrawMaterialLine3D( position + halfHeight, position - halfHeight, renderTarget, size.x, tocolor(255, 255, 255, 250), position + lookOffset )endfunction CarshopMenu.start(basePosition) position = MENU_OFFSET + basePosition renderTarget = dxCreateRenderTarget(resolution.x, resolution.y, false) headerFont = exports.dpAssets:createFont("Roboto-Regular.ttf", 20) labelFont = exports.dpAssets:createFont("Roboto-Regular.ttf", 18) themeColor = {exports.dpUI:getThemeColor()} themeColorHex = tostring(exports.dpUtils:RGBToHex(unpack(themeColor))) for i, bar in ipairs(barsList) do bar.text = exports.dpLang:getString(bar.locale) end addEventHandler("onClientRender", root, draw)endfunction CarshopMenu.stop() if isElement(renderTarget) then destroyElement(renderTarget) end if isElement(headerFont) then destroyElement(headerFont) end if isElement(labelFont) then destroyElement(labelFont) end removeEventHandler("onClientRender", root, draw)end Also, I don't see "labelFont" declared to an actual font anywhere. I mean at line 21 you do "local labelFont" but then you don't give it any value before using it at lines 38 and 40. Here's an example of how to import a custom font from a file inside any script: Digital = dxCreateFont("Digital.ttf", 21) --Custom font I added a check at line 45, that should fix the boolean error. Always when it gives boolean errors/warnings that means that the script is not sure if the thing given in the error message is there or not. It can be a file, variable, font, pretty much anything. Most times a simple "if" statement gets rid of the error. This way you tell the script explicitly to check if the wanted/needed thing is actually there or not. Hope something out of this post helps you out. Now I know for sure that the problem in the exports.lua script. Due to incorrect imports, there is no text everywhere where the font Roboto-Regular.ttf is used 11 hours ago, Dead7ucky said: And also I think that this Warning Affects my problem. Warning:dpAssetst\client\exports.lua:33:Error creating font @ 'dxCreateFont' [assest/Fonts/Roboto-Regular.ttf] FULL CODE (EXPORTS.LUA) All Fonts are in the folder. local ASSETS_PATH = "assets/"local SHADERS_PATH = "shaders/"local TEXTURES_PATH = "textures/"local FONTS_PATH = "fonts/"local cache = { textures = {}, shaders = {}, fonts = {}}local function setupElementParent(element, resource) if not element or not resource then return false end element.parent = getResourceDynamicElementRoot(resource) return trueendfunction createShader(name, ...) local element = dxCreateShader(ASSETS_PATH .. SHADERS_PATH .. tostring(name), ...) setupElementParent(element, sourceResource) return elementendfunction createTexture(name, ...) local element = dxCreateTexture(ASSETS_PATH .. TEXTURES_PATH .. tostring(name), ...) setupElementParent(element, sourceResource) return element endfunction createFont(name, ...) local element = dxCreateFont(ASSETS_PATH .. FONTS_PATH .. tostring(name), ...) setupElementParent(element, sourceResource) return element endfunction createShaderCached(name, ...) if not name then return false end if cache.shaders[name] then return cache.shaders[name] end cache.shaders[name] = createShader(name, ...) setupElementParent(cache.shaders[name], sourceResource) return cache.shaders[name]endfunction createTextureCached(name, ...) if not name then return false end if cache.textures[name] then return cache.textures[name] end cache.textures[name] = createTexture(name, ...) setupElementParent(cache.textures[name], sourceResource) return cache.textures[name]endfunction createFontCached(name, ...) if not name then return false end if cache.fonts[name] then return cache.fonts[name] end cache.fonts[name] = createFont(name, ...) setupElementParent(cache.fonts[name], sourceResource) return cache.fonts[name]end Link to comment
koragg Posted June 1, 2017 Share Posted June 1, 2017 (edited) function createFont(name, size) local element = dxCreateFont(ASSETS_PATH .. FONTS_PATH .. tostring(name), tonumber(size)) setupElementParent(element, sourceResource) return element end Maybe it thinks that the size passed is a string? Replace the function in exports.la with the above and try. I made the second argument passed to always be a number (since that's what dxCreateFont wants). If not, give link to the fonts resource as I can't find it. Edited June 1, 2017 by koragg Link to comment
Dead7ucky Posted June 1, 2017 Author Share Posted June 1, 2017 26 minutes ago, koragg said: function createFont(name, size) local element = dxCreateFont(ASSETS_PATH .. FONTS_PATH .. tostring(name), tonumber(size)) setupElementParent(element, sourceResource) return element end Maybe it thinks that the size passed is a string? Replace the function in exports.la with the above and try. I made the second argument passed to always be a number (since that's what dxCreateFont wants). If not, give link to the fonts resource as I can't find it. Fonts located is here : \dpAssets\assets\fonts Link to comment
koragg Posted June 1, 2017 Share Posted June 1, 2017 31 minutes ago, Dead7ucky said: Fonts located is here : \dpAssets\assets\fonts I meant to give download link to the dpAssets resource Link to comment
Dead7ucky Posted June 1, 2017 Author Share Posted June 1, 2017 3 minutes ago, koragg said: I meant to give download link to the dpAssets resource Here Link to comment
koragg Posted June 2, 2017 Share Posted June 2, 2017 (edited) On 6/1/2017 at 12:25, Dead7ucky said: Here I just tried using this^ resource to change a font in my race lap counter text and it worked perfectly..hmm. There were no errors at all and everything was fine, text drawn, font changed. Your function "CarshopMenu.start" is not called anywhere? Atleast I don't see it being called anywhere. Try this (declared fonts as global variables at top of script {lines 20 and 21}) and see if it works as there's no problem with the dpAssets resource since I just tried it and it worked great for me. CarshopMenu = {} local renderTarget local MENU_OFFSET = Vector3(-7.5, -7, -0.7) local position = Vector3() local size = Vector2(1.5, 1.9) local rotation = 280 local resolution = size * 250 local headerHeight = 70 local barOffset = 20 local barHeight = 20 local labelHeight = 50 local barsList = { {locale = "carshop_label_speed", value = 0.7, param = "speed"}, {locale = "carshop_label_acceleration", value = 0.4, param = "acceleration"}, {locale = "carshop_label_control", value = 0.85, param = "control"} } local headerFont = exports.dpAssets:createFont("Roboto-Regular.ttf", 20) local labelFont = exports.dpAssets:createFont("Roboto-Regular.ttf", 18) local hasDriftHandling = false local themeColor = {0, 0, 0} local themeColorHex = "#FFFFFF" local function draw() dxSetRenderTarget(renderTarget) dxDrawRectangle(0, 0, resolution.x, resolution.y, tocolor(42, 40, 41)) dxDrawRectangle(0, 0, resolution.x, headerHeight, tocolor(32, 30, 31)) local priceText = "" if Carshop.currentVehicleInfo.price > 0 then priceText = "$" .. tostring(Carshop.currentVehicleInfo.price) else priceText = exports.dpLang:getString("price_free") end dxDrawText(priceText, 0, 0, resolution.x - 20, headerHeight, tocolor(themeColor[1], themeColor[2], themeColor[3]), 1, labelFont, "right", "center") local priceWidth = dxGetTextWidth(priceText, 1, labelFont) local headerText = Carshop.currentVehicleInfo.name local hearderWidth = dxGetTextWidth(headerText, 1, headerFont) local hearderScale = false if priceWidth then hearderScale = math.min(1, (resolution.x - 60 - priceWidth) / hearderWidth) dxDrawText(headerText, 20, 0, resolution.x - 20 - priceWidth, headerHeight, tocolor(255, 255, 255), hearderScale, headerFont, "left", "center", true) end local buyButtonActive = true local buyButtonText = exports.dpLang:getString("carshop_buy_button") if Carshop.currentVehicleInfo.level > localPlayer:getData("level") then buyButtonActive = false --"Требуется уровень " .. buyButtonText = string.format(exports.dpLang:getString("carshop_required_level"), tostring(Carshop.currentVehicleInfo.level)) elseif Carshop.currentVehicleInfo.price > localPlayer:getData("money") then buyButtonActive = false buyButtonText = exports.dpLang:getString("carshop_no_money") end if not buyButtonActive then dxDrawRectangle(0, resolution.y - headerHeight, resolution.x, headerHeight, tocolor(32, 30, 31)) dxDrawText(buyButtonText, 20, resolution.y - headerHeight, resolution.x, resolution.y, tocolor(255, 255, 255, 150), 1, headerFont, "center", "center") else dxDrawRectangle(0, resolution.y - headerHeight, resolution.x, headerHeight, tocolor(themeColor[1], themeColor[2], themeColor[3])) dxDrawText(buyButtonText, 20, resolution.y - headerHeight, resolution.x, resolution.y, tocolor(255, 255, 255), 1, headerFont, "center", "center") end local y = headerHeight local barWidth = resolution.x - barOffset * 2 for i, bar in ipairs(barsList) do -- Подпись dxDrawText(bar.text, 0, y, resolution.x, y + labelHeight, tocolor(255, 255, 255), 1, labelFont, "center", "center") y = y + labelHeight dxDrawRectangle(barOffset, y, barWidth, barHeight, tocolor(65, 65, 65)) dxDrawRectangle(barOffset, y, barWidth * bar.value, barHeight, tocolor(themeColor[1], themeColor[2], themeColor[3])) bar.value = bar.value + (Carshop.currentVehicleInfo.specs[bar.param] - bar.value) * 0.2 y = y + barHeight * 2 end local labelText = exports.dpLang:getString("carshop_drift_label") local valueText = "" if Carshop.hasDriftHandling then valueText = exports.dpLang:getString("carshop_drift_label_yes") else valueText = exports.dpLang:getString("carshop_drift_label_no") end dxDrawText(labelText .. ": " .. themeColorHex .. valueText, 0, y, resolution.x, y + labelHeight, tocolor(255, 255, 255), 1, labelFont, "center", "center", false, false, false, true) dxSetRenderTarget() local halfHeight = Vector3(0, 0, size.y / 2) local rad = math.rad(rotation) local lookOffset = Vector3(math.cos(rad), math.sin(rad), 0) dxDrawMaterialLine3D( position + halfHeight, position - halfHeight, renderTarget, size.x, tocolor(255, 255, 255, 250), position + lookOffset ) end function CarshopMenu.start(basePosition) position = MENU_OFFSET + basePosition renderTarget = dxCreateRenderTarget(resolution.x, resolution.y, false) themeColor = {exports.dpUI:getThemeColor()} themeColorHex = tostring(exports.dpUtils:RGBToHex(unpack(themeColor))) for i, bar in ipairs(barsList) do bar.text = exports.dpLang:getString(bar.locale) end addEventHandler("onClientRender", root, draw) end function CarshopMenu.stop() if isElement(renderTarget) then destroyElement(renderTarget) end if isElement(headerFont) then destroyElement(headerFont) end if isElement(labelFont) then destroyElement(labelFont) end removeEventHandler("onClientRender", root, draw) end Edited June 2, 2017 by koragg Link to comment
koragg Posted June 3, 2017 Share Posted June 3, 2017 Well imo the script i posted above should work ok since the one I tested it on is made the same way (fonts declared globally = when the resource starts). If not, i got no idea why 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