SA-MP Forums Archive
MySQL Question - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL Question (/showthread.php?tid=656407)



MySQL Question - IdonTmiss - 15.07.2018

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[])
{

}



Re: MySQL Question - IdonTmiss - 15.07.2018

Anyone?


Re: MySQL Question - Iguman - 15.07.2018

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.


Re: MySQL Question - IdonTmiss - 15.07.2018

Works, thanks a lot