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


… 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
        lines[line] = lines[line] or {}
        if line_length + #s <= chars_per_line then --Word can fit on this line
	    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
            line = line + 1
            line_length = #s
	    lines[line] = {}
    end) --Get words
    for k,v in pairs(lines) do
        lines[k] = table.concat(v," ")
    return table.concat(lines,"

*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)
	if (surface.GetTextSize(str) > width) then
		while (surface.GetTextSize(str .. cut) > width) do
			str = str:sub(1, #str - 1);
		str = str .. cut;
	return str;

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