MySQL Question
#1

Well I want to make an "offunlockacc" command, that gets and then sets column "pLocked" to 0, while the user is offline

pawn Код:
cmd:offunlockacc(playerid, params[])
{

}
Reply
#2

Anyone?
Reply
#3

Example:

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

Untested.
Reply
#4

Works, thanks a lot
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)