Posts: 31
Threads: 9
Joined: Jul 2018
Example:
PHP код:
bool:IsPlayerOnline(playerid)
{
if(IsPlayerConnected(playerid) && IsPlayerLogged[playerid])
return true;
return false;
}
stock GetName(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
return name;
}
CMD:offunlockacc(playerid, params[])
{
new name[MAX_PLAYER_NAME];
if(sscanf(params, "s[24]", name)) return SCM(playerid, COLOR_RED, "USAGE: /offunlockacc [full player name]");
if(strlen(name) < 4 || strlen(name) > MAX_PLAYER_NAME) return SCM(playerid, COLOR_RED, "ERROR: Incorrect name length.");
for(new i = 0; i < MAX_PLAYERS; i++) // Better use foreach
{
if(IsPlayerOnline(i))
{
if(!strcmp(GetName(i), name))
{
SCM(playerid, COLOR_RED, "ERROR: That user is online.");
return 1;
}
}
}
new query[256], string[128];
mysql_format(Database, query, sizeof(query), "SELECT * FROM `Users` WHERE `Name`='%s' LIMIT 1;", name);
new Cache:result = mysql_query(Database, query);
if(cache_num_rows()) // User was found
{
mysql_format(Database, query, sizeof(query), "UPDATE `Users` SET `pLocked`='0' WHERE `Name`='%s';", name);
mysql_tquery(Database, query);
format(string, sizeof(string), "You have unlocked account: %s", name);
SCM(playerid, COLOR_GREEN, string);
}
else
{
format(string, sizeof(string), "ERROR: User with name ' %s ' couldn't be found in database.", name);
SCM(playerid, COLOR_RED, string);
}
cache_delete(result);
return 1;
}
Untested.