format(string, 256, "SELECT Name FROM Users WHERE Clan = %d", GetPlayerClan(playerid, g_SQL));
mysql_query(g_SQL, string);
for(new i=0; i<GetMaxMembers(GetPlayerClan(playerid, g_SQL), g_SQL); i++)
{
new name[25], s[48];
cache_get_field_content(i, "Name", name);
if(IsPlayerConnected(GetPlayerId(name)))
{
switch(i)
{
case 0..14:
{
format(s, 24+24, "%s\t%s\t{00FF2F}Online\n", name, GetRankName(GetPlayerClan(playerid, g_SQL), GetPlayerRank(GetPlayerId(name), g_SQL), g_SQL));
strcat(members, s);
}
case 15..28:
{
format(s, 24+24, "%s\t%s\t{00FF2F}Online\n", name, GetRankName(GetPlayerClan(playerid, g_SQL), GetPlayerRank(GetPlayerId(name), g_SQL), g_SQL));
strcat(members2, s);
}
}
}
else switch(i)
{
case 0..14:
{
format(s, 24+24, "%s\t%s\t{FF0000}Offline\n", name, GetRankName(GetPlayerClan(playerid, g_SQL), GetOfflineRank(name, g_SQL), g_SQL));
strcat(members, s);
}
case 15..28:
{
format(s, 24+24, "%s\t%s\t{FF0000}Offline\n", name, GetRankName(GetPlayerClan(playerid, g_SQL), GetOfflineRank(name, g_SQL), g_SQL));
strcat(members2, s);
}
}
}
ShowPlayerDialog(playerid, 13, DIALOG_STYLE_TABLIST, "Clan Members", members, "Next", "Cancel");
// global:
new Cache: gPlayer_ClanMembers[MAX_PLAYERS];
// OnPlayerConnect:
gPlayer_ClanMembers[playerid] = Cache: 0;
// wherever you execute the query
new Query[50];
mysql_format(g_SQL, Query, sizeof Query, "SELECT Name,Rank FROM Users WHERE Clan = %d", GetPlayerClan(playerid, g_SQL)); // better a variable that stores player's clan
mysql_tquery(g_SQL, Query, "OnClanMembersLoad", "i", playerid);
// the specified callback
forward OnClanMembersLoad(playerid);
public OnClanMembersLoad(playerid)
{
new rows = cache_get_row_count();
if (!rows) return ... // error that there are no members
else if (rows > 15)
{
gPlayer_ClanMembers[playerid] = cache_save();
rows = 15;
// load the first 15 results and store the rest in memory
}
new name[25], rank[25], s[48], targetid;
members[0] = EOS; // reset
for (new i; i != rows; i++)
{
cache_get_row(i, 0, name);
cache_get_row(i, 1, rank);
sscanf(name, "r", targetid);
format(s, sizeof s, "%s\t%s\t%s\n", name, rank, targetid != INVALID_PLAYER_ID ? ("{00FF2F}Online") : ("{FF0000}Offline"));
strcat(members, s);
}
}
ShowPlayerDialog(playerid, 13, DIALOG_STYLE_TABLIST, "Clan Members", members, rows > 15 ? ("Next") : ("Close"), "Cancel");
// OnDialogResponse (dialogid 13):
if (!response)
{
cache_delete(gPlayer_ClanMembers[playerid]);
gPlayer_ClanMembers[playerid] = Cache: 0;
}
else
{
if (cache_is_valid(gPlayer_ClanMembers[playerid]))
{
cache_set_active(gPlayer_ClanMembers[playerid]);
new rows = cache_get_row_count(), name[25], rank[25], s[48], targetid;
members[0] = EOS; // reset
for (new i = 14; i != rows; i++) // 15 first (rowid 0-14) have been loaded and we want the rest
{
cache_get_row(i, 0, name);
cache_get_row(i, 1, rank);
sscanf(name, "r", targetid);
format(s, sizeof s, "%s\t%s\t%s\n", name, rank, targetid != INVALID_PLAYER_ID ? ("{00FF2F}Online") : ("{FF0000}Offline"));
strcat(members, s);
}
ShowPlayerDialog(playerid, 13, DIALOG_STYLE_TABLIST, "Clan Members", members, "Close", "Cancel");
cache_set_active(Cache: 0);
cache_delete(gPlayer_ClanMembers[playerid]);
gPlayer_ClanMembers[playerid] = Cache: 0;
}
}
ShowPlayerDialog(playerid, 13, DIALOG_STYLE_TABLIST, "Clan Members", members, rows > 15 ? ("Next") : ("Close"), "Cancel");
ShowPlayerDialog(playerid, 13, DIALOG_STYLE_TABLIST, "Clan Members", members, cache_is_valid(gPlayer_ClanMembers[playerid]) ? ("Next") : ("Close"), "Cancel");
for (new i = 14; i != rows; i++)
for (new i = 15; i != rows; i++)
I also commented that 15 first rows were shown that are row IDs 0 to 14 and started the iteration variable from 14 when it should be from 15. Change (from dialog response):
pawn Код:
pawn Код:
|
// global:
new Cache: gPlayer_ClanMembers[MAX_PLAYERS], gPlayer_ClanMembers@Page[MAX_PLAYERS];
// OnPlayerConnect:
gPlayer_ClanMembers[playerid] = Cache: 0;
gPlayer_ClanMembers@Page[playerid] = 0;
// wherever you execute the query
new Query[50];
mysql_format(g_SQL, Query, sizeof Query, "SELECT Name,Rank FROM Users WHERE Clan = %d", GetPlayerClan(playerid, g_SQL)); // better a variable that stores player's clan
mysql_tquery(g_SQL, Query, "OnClanMembersLoad", "i", playerid);
// the specified callback
forward OnClanMembersLoad(playerid);
public OnClanMembersLoad(playerid)
{
new rows = cache_get_row_count();
if (!rows) return ... // error that there are no members
else if (rows > 15)
{
gPlayer_ClanMembers[playerid] = cache_save();
rows = 15;
gPlayer_ClanMembers@Page[playerid] = 1; // viewing 1st page
// load the first 15 results and store the rest in memory
}
new name[25], rank[25], s[48], targetid;
members[0] = EOS; // reset
for (new i; i != rows; i++)
{
cache_get_row(i, 0, name);
cache_get_row(i, 1, rank);
sscanf(name, "r", targetid);
format(s, sizeof s, "%s\t%s\t%s\n", name, rank, targetid != INVALID_PLAYER_ID ? ("{00FF2F}Online") : ("{FF0000}Offline"));
strcat(members, s);
}
}
ShowPlayerDialog(playerid, 13, DIALOG_STYLE_TABLIST, "Clan Members", members, cache_is_valid(gPlayer_ClanMembers[playerid]) ? ("Next") : ("Close"), "Cancel");
// OnDialogResponse (dialogid 13):
if (!response)
{
cache_delete(gPlayer_ClanMembers[playerid]);
gPlayer_ClanMembers[playerid] = Cache: 0;
gPlayer_ClanMembers@Page[playerid] = 0;
}
else
{
if (cache_is_valid(gPlayer_ClanMembers[playerid]))
{
cache_set_active(gPlayer_ClanMembers[playerid]);
new rows = cache_get_row_count(), results = ++gPlayer_ClanMembers@Page[playerid] * 15;
if (rows > results) // if there are more rows, set the max rows for the current page (goes like 15, 30, 45, 60 etc.)
{
rows = results;
}
else gPlayer_ClanMembers@Page[playerid] = 0; // otherwise this is the last page, reset so we can delete the cache afterwards
new name[25], rank[25], s[48], targetid;
members[0] = EOS; // reset
for (new i = (results - 15); i != rows; i++) // 1 page = 15 results | page * 15 is the max rows
{
cache_get_row(i, 0, name);
cache_get_row(i, 1, rank);
sscanf(name, "r", targetid);
format(s, sizeof s, "%s\t%s\t%s\n", name, rank, targetid != INVALID_PLAYER_ID ? ("{00FF2F}Online") : ("{FF0000}Offline"));
strcat(members, s);
}
ShowPlayerDialog(playerid, 13, DIALOG_STYLE_TABLIST, "Clan Members", members, !gPlayer_ClanMembers@Page[playerid] ? ("Close") : ("Next"), "Cancel");
if (!gPlayer_ClanMembers@Page[playerid])
{
cache_set_active(Cache: 0);
cache_delete(gPlayer_ClanMembers[playerid]);
gPlayer_ClanMembers[playerid] = Cache: 0;
}
}
}