The query is running only once.
It never re-formats to re-call the query to re-check if the name is available.
EDIT: You probably wont understand what I mean, so I'll explain it with comments.
pawn Код:
case DIALOG_FAIL_LOGIN:
{
if( !response ) return SetTimerEx("KickTimer", 50, false, "i", playerid);
if( response )
{
new Query[106], name[24], string[66], character = 1, DBResult:Result;
format(name, sizeof(name), "%s_%d", GetName(playerid), character);
format(Query, sizeof(Query), "SELECT * FROM `USERS` WHERE `NAME` = '%s'", name);
// Let's say the query is now this
// SELECT * FROM `USERS` WHERE `NAME` = 'Example_1'
Result = db_query(HDF, Query);
if(db_num_rows(Result)) // If the name exists
{
do
{
character++;
format(name, sizeof(name), "%s_%d", GetName(playerid), character);
// You're adding the new number to the name.
// But where are you adding it to the query?
format(string, sizeof(string), "Skipping name '%s' because is in use.", name), SendClientMessage(playerid, COLOR_NOTES2, string);
}
while(db_next_row(Result)); // It's always checking for Example_1
}
else
{
format(string, sizeof(string), "Found a valid name - '%s' - setting. . .", name), SendClientMessage(playerid, COLOR_NOTES, string);
SetPlayerName(playerid, name);
SendClientMessage(playerid, COLOR_NOTES, "INFO: You will need to register now to save your stats");
PlayerPlaySound(playerid,1057,0.0,0.0,0.0);
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "{64CC66}Registration.", "{FFFFFF}Welcome to the server!\nYour name is detected as {64CC66}unregistered{FFFFFF}.\nYou are required to register to proceed playing.\n{64CC66}Enter your password below to complete the registration.", "Register", "Leave");
}
db_free_result(Result);
}
}