Align - iLearner - 28.09.2016
Hello, i am trying to show a dialog, DIALOG_STYLE_MSGBOX, but its not aligned...
here's the format:
PHP код:
format(ganglist, sizeof(ganglist), "%s%d. {%s}%s {FFFFFF}- Score : %d \t\t\t\t{23ffaa}Gang Kills: %d \tGang Deaths: %d\n" /* stuff here, but we dont care */;
How can i align kills / deaths ?
Re: Align -
Konstantinos - 28.09.2016
Don't use that style but DIALOG_STYLE_TABLIST or DIALOG_STYLE_TABLIST_HEADERS. Keep only one \t to separate them and it will align itself. The limit is 4 columns so you can pretty much organize them as "rank (position-name of gang) - score - kills - deaths".
Re: Align - iLearner - 28.09.2016
My current command is like this:
PHP код:
COMMAND:topgang(playerid, params[])
{
new query[128];
mysql_format(connection, query, sizeof(query), "SELECT * FROM `cnr_gang` ORDER BY `score` DESC LIMIT 20");
mysql_query(connection, query, true);
new ganglist[2500], count = cache_num_rows(), TempColor[7], TempName[30];
if(count != 0)
{
for(new i = 0; i < count; i++)
{
cache_get_field_content(i, "color", TempColor);
cache_get_field_content(i, "name", TempName);
new gangkills = cache_get_field_content_int(0, "Kills");
new gangdeaths = cache_get_field_content_int(0, "Deaths");
format(ganglist, sizeof(ganglist), "%s%d. {%s}%s {FFFFFF}- Score : %d \t\t\t\t{23ffaa}Gang Kills: %d \tGang Deaths: %d\n", ganglist, (i+1), TempColor, TempName, cache_get_field_content_int(i, "score"), gangkills, gangdeaths);
}
format(ganglist, sizeof(ganglist), "%s\n* This top list updated every %d minutes", ganglist, AUTOSAVE);
ShowPlayerDialog(playerid, DIALOG_UNUSED, DIALOG_STYLE_MSGBOX, "Top Gangs", ganglist, "Close", "");
}
else
SendClientMessage(playerid, -1, "{FF0000}There's no gangs present!");
return 1;
}
So can i do it like:
PHP код:
format(ganglist, sizeof(ganglist), "%s\n Gang Name\tGang Score\tGang Kills\tGang Deaths\n\",ganglist);
PHP код:
format(ganglist, sizeof(ganglist), "%s {%s}%s \t{FFFFFF}%d\t{23ffaa}%d \t%d\n\", ganglist, TempColor, TempName, cache_get_field_content_int(i, "score"), gangkills, gangdeaths);
format(ganglist, sizeof(ganglist), "%s\n* This top list updated every %d minutes", ganglist, AUTOSAVE);
PHP код:
ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_TABLIST_HEADERS, "Top Gangs",ganglist, "Select", "Cancel");
?
Re: Align -
Konstantinos - 28.09.2016
The first thing I noticed is that you don't delete the cache and you may experience memory leaks. Threaded queries are always recommended as well.
When retrieving kills/deaths you have rowid as 0 instead of "i" so it will get the data of the first gang returned. Colors are integers so you can save them as such and when load them you can color embedding as:
pawn Код:
"{%06x} ...", color >>> 8, ...
---
Yes, like that but the headers should be outside:
pawn Код:
ganglist = "Gang Name\tGang Score\tGang Kills\tGang Deaths\n";
for (new i = 0; i < count; i++)
{
cache_get_field_content(i, "color", TempColor);
cache_get_field_content(i, "name", TempName);
format(ganglist, sizeof(ganglist), "%s{%s}%s\t{FFFFFF}%d\t{23ffaa}%d\t%d\n", ganglist, TempColor, TempName, cache_get_field_content_int(i, "score"), cache_get_field_content_int(i, "Kills"), cache_get_field_content_int(i, "Deaths"));
}
---
Since you select them from the database, why don't you update score, kills and deaths directly so it will always be updated and not like 30 minutes you mention.
Re: Align - iLearner - 28.09.2016
Thanks, it works.