how could I make a function to calculate the length of the string and then inside `[ ]' to be able to center and align the text? (i.e. add left and right spaces for centering and the brackets should be one under the other)
I have a similar plugin that prints hud messages in about the same way, that's why I gave this example ( it's more beautifully arranged in this example and expresses exactly what I want )
I want a plugin or a stock function.
if there is a rank plugin that centers the text and brackets in the hud, it would be even nicer (I haven't found such a plugin so far)
( mine is similar but contains more information and is not a simple rank system )
I was thinking of a stock function because it is easier for me to manage the centering (it is possible to do the same for other functions as well)
p.s. I didn't know where to post for problems like this, so sorry if I didn't post in the right place
do you understand the difference now?
what i specified with that function is just an example that happens to be how i would display the hud
I can calculate the maximum length but I always encounter problems, apparently, the hud is oriented from right to left (which confuses me a bit)
I can center the whole format, but inside the brackets, for me it is more complicated
I want both the brackets ( [ ] ) and the format inside to be aligned
only that somehow the length of the name must not matter, for example, if the name is longer, spaces will be added until the brackets are one under the other
do you understand the difference now?
what i specified with that function is just an example that happens to be how i would display the hud
I can calculate the maximum length but I always encounter problems, apparently, the hud is oriented from right to left (which confuses me a bit)
I can center the whole format, but inside the brackets, for me it is more complicated
I want both the brackets ( [ ] ) and the format inside to be aligned
only that somehow the length of the name must not matter, for example, if the name is longer, spaces will be added until the brackets are one under the other
just put space til the space is equal between all brackets same as you did on the 2nd one "but i want it like this:"
did it work for you ?
I don't think that amxmodx can return a strings in a function
PHP Code:
L 11/13/2023 - 12:13:17: [AMXX] Displaying debug trace (plugin "fmt.amxx", version "1.0")
L 11/13/2023 - 12:13:17: [AMXX] Run time error 5: memory access
L 11/13/2023 - 12:13:17: [AMXX] [0] fmt.sma::FormatString2 (line 85)
L 11/13/2023 - 12:13:17: [AMXX] [1] fmt.sma::FormatString (line 22)
L 11/13/2023 - 12:13:17: [AMXX] [2] fmt.sma::srvcmd_f (line 14)
Edit:
the thing is that i can do what you did (adapted as i want)
that is, let's take for example what you said (designed to work)
to make it even more complicated (why not)
i also made an include dedicated to these functions of yours and some of mine )
i made it work in an array to keep everything in one place (something like this)
this is the include:
Spoiler
PHP Code:
#if defined _formatutils_included
#endinput
#endif
#define _formatutils_included
#include <amxmodx>
#include <amxmisc>
// Global max lengths for categories and values.
new global_maxlen_category;
new global_maxlen;
/**
* Updates a value in a specified array based on a given category.
* Searches for the category in the array and updates the corresponding value.
*
* @param categories Array of categories.
* @param values Array of values linked to categories.
* @param size Size of the arrays.
* @param key The category key to search for.
* @param format String format for the new value.
* @param ... Additional parameters for string formatting.
*/
stock UpdateValue(const categories[][], const values[][], size, const key[], const fmt[], any:...)
{
new Buffer[192];
vformat(Buffer, sizeof(Buffer) - 1, fmt, 6);
for (new i = 0; i < size; i++)
{
if (equal(categories[i], key))
{
format(values[i], 192, "%s", Buffer);
break;
}
}
}
/**
* Calculates the maximum lengths for categories and values from given arrays.
* Updates global variables for max lengths.
*
* @param Array1 First array (usually categories).
* @param Array2 Second array (usually values).
* @param numEntries Number of entries in the arrays.
*/
stock CalculateMaxLens(const Array1[][], const Array2[][], numEntries)
{
global_maxlen_category = 0;
global_maxlen = 0;
for (new i = 0; i < numEntries; i++)
{
global_maxlen_category = max(global_maxlen_category, strlen(Array1[i]));
global_maxlen = max(global_maxlen, strlen(Array2[i]));
}
/**
* Resets the global max lengths for categories and values.
*/
stock ResetMaxLens()
{
global_maxlen_category = 0;
global_maxlen = 0;
}
/**
* Formats a string by combining text from two different categories and values.
*
* @param text1 First text (category).
* @param text2 Second text (value).
* @param output Output buffer for the formatted string.
* @param len Length of the output buffer.
*/
stock FormatString(text1[], text2[], output[], len)
{
new part1[128];
new part2[128];
/**
* Formats the first part of the string (usually the category).
*
* @param text Text to format.
* @param output Output buffer for the formatted text.
* @param len Length of the output buffer.
*/
stock FormatString1(text[], output[], len)
{
new space = global_maxlen_category - strlen(text);
new formatted[128] = "";
for (new i = 0; i < space; i++)
strcat(formatted, " ", sizeof(formatted) - 1);
/**
* Formats the second part of the string (usually the value).
*
* @param text Text to format.
* @param output Output buffer for the formatted text.
* @param len Length of the output buffer.
*/
stock FormatString2(text[], output[], len)
{
new space = global_maxlen - strlen(text);
new formatted[128] = "";
for (new i = 0; i < space; i++)
strcat(formatted, " ", sizeof(formatted) - 1);
format(output, len, "%s%s]", text, formatted);
}
/**
* Resets a specified array. Sets each entry to an empty string.
*
* @param array The array to reset.
*/
stock ResetArray(array[][], size)
{
for (new i = 0; i < size; i++)
{
array[i][0] = '^0';
}
}
/**
* Adds a new category to an array.
* Searches for a free position in the array and adds the category.
*
* @param array The array to add the category to.
* @param category The category to add.
*/
stock AddCategory(array[][], size, const category[])
{
for (new i = 0; i < size; i++)
{
if (array[i][0] == '^0')
{
format(array[i], sizeof(array[]) - 1, category);
break;
}
}
}
/**
* Adds multiple categories to an array from a delimited string.
* It can handle multiple categories separated by a specified delimiter.
* If no delimiter is found, it treats the input as a single category.
*
* @param array The array to which the categories will be added.
* @param max_size The maximum number of categories that the array can hold.
* @param categories A string containing categories, separated by the delimiter.
* @param delimiter The character used to delimit categories in the 'categories' string.
*
* Usage:
* - To add multiple categories: AddCategory2(yourArray, MAX_CATEGORIES, "Cat1,Cat2,Cat3", ',');
* - To add a single category: AddCategory2(yourArray, MAX_CATEGORIES, "SingleCategory");
*
* Example:
* new yourArray[10][32]; // Array to store categories
* AddCategory2(yourArray, 10, "Player,Score,Level", ','); // Adding three categories
* // 'yourArray' now contains "Player", "Score", and "Level" as its first three elements.
*/
stock AddCategory2(array[][], max_size, const categories[], delimiter = ',')
{
new category[192];
new idx = 0, pos = 0;
/**
* Parses and extracts a substring from the input string based on a delimiter.
* The function finds the next section of the input string that is separated
* by the given delimiter and copies it to the output buffer.
*
* @param input The source string from which to extract the substring.
* @param output The destination buffer where the extracted substring is stored.
* @param size The maximum size of the output buffer.
* @param idx The starting index in the input string from where parsing begins.
* This index is updated to the position right after the extracted substring.
* @param delimiter The character used as a delimiter to separate substrings in the input.
*
* Usage:
* - To extract a substring: parsed("Cat1,Cat2,Cat3", output, sizeof(output) - 1, idx, ',');
* This will extract "Cat1" into 'output' if 'idx' is 0 initially.
* - 'idx' is updated to point after the extracted substring, ready for the next parse.
*
* Example:
* new output[32];
* new idx = 0;
* parsed("Player,Score,Level", output, sizeof(output), idx, ',');
* // 'output' now contains "Player", and 'idx' is updated to position after "Player,"
*/
stock parsed(const input[], output[], size, &idx, delimiter)
{
new start = idx, end = idx;
if (end - start < size)
{
new subStr[32];
strmid(subStr, input, start, end, 31);
format(output, size, "%s", subStr);
}
idx = (input[end] != '^0') ? end + 1 : end;
}
/**
* Extracts a substring from a source string.
*
* @param dest Destination buffer for the substring.
* @param source Source string.
* @param start Starting index for the substring in the source.
* @param end Ending index for the substring in the source.
* @param maxlength Maximum length of the destination buffer.
*/
stock strmid(dest[], const source[], start, end, maxlength)
{
for (new i = start; i < end && i - start < maxlength; i++)
{
dest[i - start] = source[i];
}
dest[end - start] = '^0';
}
very interesting, i will try something then
maybe i can use other spaces depending on the letters using ascii
Quote:
Originally Posted by Jhob94
First i felt bad for you, playing Riot games damages a person’s soul. Then i saw cheat engine.
Off Topic:
I've had Riot games since my friends wanted us to play valorant, i think i played for a max 30 min and then i uninstalled it =))
and the cheat engine is not only used for cheating, you can inform yourself, i don't even have to explain to you what i use it for.
however, i don't know what it has to do with this topic, did you want attention?