String formatting a darkRPVar

Hello, I have asked a question similar to this before but I didn’t want to reopen that old thread so I am making a new one. I was wondering how I can format a darkRPVar string. I am making a custom agenda hud and I don’t know how I can format the string returned from LocalPlayer():getDarkRPVar(“agenda”). I checked the original darkrp files but it looks like they made their agenda hud long enough that they don’t have to worry about making it multiple lines. How can I format the string returned? I have been playing around with surface.getsize() but im not sure how to insert a
inside the string that I cannot even see.

You should read up on concatenation

I know what concatenation is, but the agenda DarkRPVar returns a string that I cannot see or change… It’s stored in the actual


LocalPlayer():getDarkRPVar("agenda")

… I don’t understand how I can concat in a string that I cannot actually manipulate or change.

From what little I understand about DarkRP I’m assuming that ply:getDarkRPVar(“agenda”) returns a string. You can concat strings with other strings to make even bigger strings. Simple.

Right, but it returns a string in it’s entirety. How could I concat INSIDE the string? I want to insert a
after the surface.getsize hit’s a certain character length. Here is an image so you can better understand what I am trying to do.

You can do stringVar:length, and if it is over x amount then you simply insert a n

I would do it like this



local function FmtTextToWidth(str,chars_per_line)
    local lines = {}
    local line = 1
    local line_length = 0
    str:gsub("(%a+)",function(s)
        lines[line] = lines[line] or {}
        if line_length + #s <= chars_per_line then --Word can fit on this line
            table.insert(lines[line],s)
	    line_lenth = line_length + #s
        elseif #s > chars_per_line then --Word can't fit on any line, format it
	    lines[line+1] = {string.format("%." .. chars_per_line-3 .. "s...",s)}
	    line = line + 2
	    line_length = 0
        else
            line = line + 1
            line_length = #s
	    lines[line] = {}
	    table.insert(lines[line],s)
        end
    end) --Get words
    for k,v in pairs(lines) do
        lines[k] = table.concat(v," ")
    end
    return table.concat(lines,"
")
end


*note, this will trim words, so “this is a string” will appear as “this is a string”

I use this:


local TextCut = function(str, font, width, cut)
	surface.SetFont(font);
	
	if (surface.GetTextSize(str) > width) then
		while (surface.GetTextSize(str .. cut) > width) do
			str = str:sub(1, #str - 1);
		end
		
		str = str .. cut;
	end
	
	return str;
end

to cut strings short if they’re longer than a the specified width. I’m sure if you had at least half a brain cell you’d be able to utilise it to add a newline instead.

:snip: I need to read better