by Spike » Sun Feb 02, 2014 5:23 pm
small note, strlen only works for centering strings when the font is a fixed width. also, it does not understand colour codes so you might want to strip those first.
If you're writing csqc/menu code, the following builtin is a better option, but is not supported in ssqc (where fonts are not known).
float(string text, float usecolours, optional vector fontsize) stringwidth = #327;
Calculates the width of the text in virtual pixels. If usecolours is 1, markup that does not affect the displayed string width will be ignored (so generally pass 1 for that).
If the fontsize is not specified, '8 8 0' will be assumed.
.