if (strcmp(tmp1, "color", true) == 0)
{
new color, colorstr[30];
if (!AdminCheck(playerid, 4)) return SendClientMessage(playerid, ERRORCOLOR, "Usage: /gang [create|invite|kick|join|quit|setrank]");
if (!sscanf(tmp2, "is[30]", id, colorstr))
{
if (strlen(colorstr) != 6) return SendClientMessage(playerid, ERRORCOLOR, "Invalid color code.");
strcat(tmp2, "FF");
}
if (sscanf(tmp2, "ix", id, color)) return SendClientMessage(playerid, ERRORCOLOR, "Usage: /gang color [gangid] [colorcode]");
format(tmp1, sizeof(tmp1), "SELECT * FROM `Gangs` WHERE `id` = %d", id);
result = db_query(Database, tmp1);
if (db_num_rows(result) == 0)
{
db_free_result(result);
return SendClientMessage(playerid, ERRORCOLOR, "Invalid gangid.");
}
db_free_result(result);
format(tmp1, sizeof(tmp1), "UPDATE `Gangs` SET `color` = %d WHERE `id` = %d", color, id);
db_query(Database, tmp1);
format(tmp1, sizeof(tmp1), "SELECT * FROM `Gangmembers` WHERE `gangid` = %d", id);
result = db_query(Database, tmp1);
new rows = db_num_rows(result);
while (0 < rows)
{
db_get_field_assoc(result, "userid", tmp1, sizeof(tmp1));
new pid = GetPlayerID(GetNameFromUserID(strval(tmp1)));
if (IsPlayerConnected(pid)) { SetPlayerColor(pid, color); pcolor[pid] = color; }
db_next_row(result);
rows--;
}
db_free_result(result);
SendMessageToGang(id, "{8B72F2}Your gang color has changed.");
return 1;
}
new rows = db_num_rows(result); //Suppose that rows is now 3. (rows = 3)
while (0 < rows) //(0 is of course less than 3, so the loop runs until 0 < 0 occurs.)
{
db_get_field_assoc(result, "userid", tmp1, sizeof(tmp1));
new pid = GetPlayerID(GetNameFromUserID(strval(tmp1)));
if (IsPlayerConnected(pid)) { SetPlayerColor(pid, color); pcolor[pid] = color; }
db_next_row(result);
rows--; //The value of rows keeps on decreasing.
}
It's just clear mathematical logic. (0 < rows) is equal to (rows > 0).
|