Jump to content

HELP Textlib DayZ!


Hades4

Recommended Posts

 

Hello, I'm going to get straight to the point. I have an error in my dayl textlib what the textlib does is that it creates functions to create dx faster, the problem that when I get into a vehicle this error throws me

textlib.Lua:339:attemp to index local "str" (a number value)



Issue:

local w = dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font, true)

Textlib.Lua:

 

function dxDrawingColorText(str, ax, ay, bx, by, color, alpha, scale, font, alignX, alignY)

  if alignX then
    if alignX == "center" then
      local w = dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font, true)
      ax = ax + (bx-ax)/2 - w/2
    elseif alignX == "right" then
      local w = dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font, true)
      ax = bx - w
    end
  end

  if alignY then
    if alignY == "center" then
      local h = dxGetFontHeight(scale, font)
      ay = ay + (by-ay)/2 - h/2
    elseif alignY == "bottom" then
      local h = dxGetFontHeight(scale, font)
      ay = by - h
    end
  end

  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)), 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(tonumber("0x"..col:sub(1, 2)), tonumber("0x"..col:sub(3, 4)), tonumber("0x"..col:sub(5, 6)), alpha)
    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)
  end
end

menu_Client.Lua:

addEventHandler("onClientRender", getRootElement(),function()
    local boxSpace = dxGetFontHeight(1,"default-bold")+dxGetFontHeight(1,"default-bold")*0.1
    local veh = getPedOccupiedVehicle (getLocalPlayer())
    if veh then
        disableMenu()
    else
        for id, value in pairs(theTableMenuScroll) do
            if id == numberMenuScroll then
                r1menu,g1menu,b1menu = 109,163,61
            else
                r1menu,g1menu,b1menu = 19,19,19
            end
            dxDrawRectangle ( 0, 250+id*boxSpace, screenWidth*0.2, boxSpace, tocolor (r1menu,g1menu,b1menu,180) )
            dxDrawingColorTextMenuScroll(value[1],6, 250+id*boxSpace, 6, 250+(id+1)*boxSpace, tocolor(value[2],value[3],value[4],170),170, 1, "default-bold", "center", "center")
        end
    end
    if newbieShow == false then return end
    local x,y,z = getElementPosition(newbiePosition)
    local x,y = getScreenFromWorldPosition (x,y,z)
	local length = dxGetTextWidth(newbieText,1,"default-bold")
		if x == false or y == false or z == false then return end
		dxDrawingColorText(newbieHead,x-length/2-screenWidth*0.01,y, x+length/2+screenWidth*0.01, y+screenHeight*0.03, tocolor(100, 255, 100, 200),0.5, 1.1, "default-bold", "center", "center")
		dxDrawingColorText(newbieText,x-length/2-screenWidth*0.01,y+screenHeight*0.03, x+length/2+screenWidth*0.01, y+screenHeight*0.07, tocolor(100, 255, 100, 200),0.5, 1, "default-bold", "center", "center")  

end)

 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...