oban command
#1

The server crash when i enter right player name, why?
PHP код:
COMMAND:oban(playeridparams[])
{
    if(
playerData[playerid][playerLoggedIn])
    {
        if(
playerData[playerid][playerLevel] >= 4)
        {
            new 
otherPlayerreason;
            if(
sscanf(params"us[250]"otherPlayerreason)) return SendClientMessage(playerid, -1"{FF0000}[ERROR] {FFFFFF}Usage: /oban <playername> <reason>");
            {
                new 
mysql[250], value[100][50], row[200];
//                new rows = mysql_num_rows();
                
format(mysqlsizeof(mysql), "SELECT * FROM `playerdata` WHERE `playerName` = '%s'"otherPlayer);
                
mysql_query(mysql);
                
mysql_store_result();
                if(
mysql_num_rows())
                {
                    
mysql_fetch_row(row"|"connection);
                     
explode(rowvalue"|");
                    new 
mysql1[250];
                    
format(mysql1sizeof(mysql1), "SELECT * FROM `playerdata` WHERE `playerName` = '%s'"otherPlayer);
                    
mysql_query(mysql1);
                    
mysql_fetch_row(value[4], "playerIP");
                    new 
banreason[350], msg[250], msg1[250];
                    
format(banreasonsizeof(banreason), "INSERT INTO `playerbans` (`banned_by`, `banned_for`, `player_banned`, `player_ip`) VALUES ('%s', '%s', '%s', '%s')"GetName(playerid), reasonotherPlayerplayerIP);
                    
mysql_query(banreason);
                    
format(msgsizeof(msg), "{33AA33}[ADMIN] Adminstrator %s(%i) has offline banned %s. {FFFF00}[REASON: %s]"GetName(playerid), playeridotherPlayer);
                    
SendClientMessageToAll(-1msg);
                    
format(msg1sizeof(msg1), "{33AA33}[ADMIN]{FFFFFF} You've offline banned %s for %s."otherPlayerreason);
                    
SendClientMessage(playerid, -1msg1);
                }
                else
                {
                    
SendClientMessage(playerid, -1"{FF0000}[ERROR]{FFFFFF} That player doesn't exist in the database.");
                }
            }
        }
    }
    else
    {
        
SendClientMessage(playerid, -1"{FF0000}[ERROR] {FFFFFF}You must be logged in to use commands.");
    }
    return 
1;

Reply
#2

are you mostafa osama on ********? i'm SeanDenz, if you are, please PM me.
Reply
#3

Quote:
Originally Posted by SeanDenZYR
Посмотреть сообщение
are you mostafa osama on ********? i'm SeanDenz, if you are, please PM me.
I'm not
Reply
#4

I edited it into this
PHP код:
 if(sscanf(params"s[50]s[50]"otherPlayerreason)) return SendClientMessage(playerid, -1"{FF0000}[ERROR] {FFFFFF}Usage: /oban <playername> <reason>"); 
PHP код:
COMMAND:oban(playeridparams[])
{
    if(
playerData[playerid][playerLoggedIn])
    {
        if(
playerData[playerid][playerLevel] >= 4)
        {
            new 
otherPlayerreason;
            if(
sscanf(params"s[50]s[50]"otherPlayerreason)) return SendClientMessage(playerid, -1"{FF0000}[ERROR] {FFFFFF}Usage: /oban <playername> <reason>");
            {
                new 
mysql[250], value[100][50], row[200];

                
format(mysqlsizeof(mysql), "SELECT * FROM `playerdata` WHERE `playerName` = '%s'"otherPlayer);
                
mysql_query(mysql);
                
mysql_store_result();
                if(
mysql_num_rows())
                {
                    
mysql_fetch_row(row"|"connection);
                     
explode(rowvalue"|");
                    new 
mysql1[250];
                    
format(mysql1sizeof(mysql1), "SELECT * FROM `playerdata` WHERE `playerName` = '%s'"otherPlayer);
                    
mysql_query(mysql1);
                    
mysql_fetch_row(value[4], "playerIP");
                    new 
banreason[350], msg[250], msg1[250];
                    
format(banreasonsizeof(banreason), "INSERT INTO `playerbans` (`banned_by`, `banned_for`, `player_banned`, `player_ip`) VALUES ('%s', '%s', '%s', '%s')"GetName(playerid), reasonotherPlayerplayerIP);
                    
mysql_query(banreason);
                    
format(msgsizeof(msg), "{33AA33}[ADMIN] Adminstrator %s(%i) has offline banned %s. {FFFF00}[REASON: %s]"GetName(playerid), playeridotherPlayer);
                    
SendClientMessageToAll(-1msg);
                    
format(msg1sizeof(msg1), "{33AA33}[ADMIN]{FFFFFF} You've offline banned %s for %s."otherPlayerreason);
                    
SendClientMessage(playerid, -1msg1);

                }
                else
                {
                    
SendClientMessage(playerid, -1"{FF0000}[ERROR]{FFFFFF} That player doesn't exist in the database.");
                }
            }
        }
    }
    else
    {
        
SendClientMessage(playerid, -1"{FF0000}[ERROR] {FFFFFF}You must be logged in to use commands.");
    }
    return 
1;

Reply
#5

otherPlayer variable needs to be a string so, otherPlayer[24]
Reply
#6

PHP код:
new otherplayer[MAX_PLAYER_NAME+1]; 
Reply
#7

I edited it into this it now dont crash the server but the ip is not given correctly
PHP код:
COMMAND:oban(playeridparams[])
{
    if(
playerData[playerid][playerLoggedIn])
    {
        if(
playerData[playerid][playerLevel] >= 4)
        {
            new 
otherPlayer[50], reason[50];
            if(
sscanf(params"s[50]s[50]"otherPlayerreason)) return SendClientMessage(playerid, -1"{FF0000}[ERROR] {FFFFFF}Usage: /oban <playername> <reason>");
            {
                new 
mysql[150], value[100][50], row[200];
                
format(mysqlsizeof(mysql), "SELECT * FROM `playerdata` WHERE `playerName` = '%s'"otherPlayer);
                
mysql_query(mysql);
                
mysql_store_result();


                if(
mysql_num_rows())
                {
                    
mysql_fetch_row(row"|"connection);
                     
explode(rowvalue"|");
                    
mysql_fetch_row(value[4], "playerIP");
                    new 
str[150];
                    
format(strsizeof(str), "SELECT * FROM `playerbans` WHERE `player_banned` = '%s'"otherPlayer);
                    
mysql_query(str);
                    
mysql_store_result();
                    if(
mysql_num_rows())
                    {
                        
SendClientMessage(playerid, -1"{FF0000}[ERROR]{FFFFFF} This player is already banned.");
                        
mysql_free_result();
                    }
                    else
                    {
                        new 
banreason[350], msg[250], msg1[250];
                        
format(banreasonsizeof(banreason), "INSERT INTO `playerbans` (`banned_by`, `banned_for`, `player_banned`, `player_ip`) VALUES ('%s', '%s', '%s', '%s')"GetName(playerid), reasonotherPlayerplayerIP);
                        
mysql_query(banreason);
                        
format(msgsizeof(msg), "{33AA33}[ADMIN] Adminstrator %s(%i) has offline banned %s. {FFFF00}[REASON: %s]"GetName(playerid), playeridotherPlayerreason);
                        
SendClientMessageToAll(-1msg);
                        
format(msg1sizeof(msg1), "{33AA33}[ADMIN]{FFFFFF} You've offline banned %s for %s."otherPlayerreason);
                        
SendClientMessage(playerid, -1msg1);

                        
mysql_free_result();
                    }
                    
mysql_free_result();
                }
                else
                {
                    
SendClientMessage(playerid, -1"{FF0000}[ERROR]{FFFFFF} That player doesn't exist in the database.");
                }
            }
        }
        else
        {
            
SendClientMessage(playerid, -1"{FF0000}[ERROR]{FFFFFF} You're not authorized to use this command.");
        }
    }
    else
    {
        
SendClientMessage(playerid, -1"{FF0000}[ERROR] {FFFFFF}You must be logged in to use commands.");
    }
    return 
1;

Reply
#8

In the sscanf;

Код:
if(sscanf(params, "s[50]s[50]", otherPlayer, reason)) return SendClientMessage(playerid, -1, "{FF0000}[ERROR] {FFFFFF}Usage: /oban <playername> <reason>");
Why is the "otherPlayer" variable so large? It only has to be 24 since player names can only go up to 24 characters long.
Reply
#9

Quote:
Originally Posted by Stev
Посмотреть сообщение
In the sscanf;

Код:
if(sscanf(params, "s[50]s[50]", otherPlayer, reason)) return SendClientMessage(playerid, -1, "{FF0000}[ERROR] {FFFFFF}Usage: /oban <playername> <reason>");
Why is the "otherPlayer" variable so large? It only has to be 24 since player names can only go up to 24 characters long.
Ok I edited into 24 but why the ip is not given correctly at the mysql tables?
Reply
#10

PHP код:
COMMAND:oban(playeridparams[])
{
    if(
playerData[playerid][playerLoggedIn])
    {
        if(
playerData[playerid][playerLevel] >= 4)
        {
            new 
otherPlayer[24], reason[50];
            if(
sscanf(params"s[24]s[50]"otherPlayerreason)) return SendClientMessage(playerid, -1"{FF0000}[ERROR] {FFFFFF}Usage: /oban <playername> <reason>");
            {
                new 
mysql[150], value[100][50], row[200];
                
format(mysqlsizeof(mysql), "SELECT * FROM `playerdata` WHERE `playerName` = '%s'"otherPlayer);
                
mysql_query(mysql);
                
mysql_store_result();
                if(
mysql_num_rows())
                {
                    
mysql_fetch_row(row"|"connection);
                     
explode(rowvalue"|");
                    
mysql_fetch_row(value[4], "playerIP");
                    new 
str[150];
                    
format(strsizeof(str), "SELECT * FROM `playerbans` WHERE `player_banned` = '%s'"otherPlayer);
                    
mysql_query(str);
                    
mysql_store_result();
                    if(
mysql_num_rows())
                    {
                        
SendClientMessage(playerid, -1"{FF0000}[ERROR]{FFFFFF} This player is already banned.");
                        
mysql_free_result();
                    }
                    else
                    {
                        new 
banreason[350], msg[250], msg1[250];
                        
format(banreasonsizeof(banreason), "INSERT INTO `playerbans` (`banned_by`, `banned_for`, `player_banned`, `player_ip`) VALUES ('%s', '%s', '%s', '%s')"GetName(playerid), reasonotherPlayerplayerIP);
                        
mysql_query(banreason);
                        
format(msgsizeof(msg), "{33AA33}[ADMIN] Adminstrator %s(%i) has offline banned %s. {FFFF00}[REASON: %s]"GetName(playerid), playeridotherPlayerreason);
                        
SendClientMessageToAll(-1msg);
                        
format(msg1sizeof(msg1), "{33AA33}[ADMIN]{FFFFFF} You've offline banned %s for %s."otherPlayerreason);
                        
SendClientMessage(playerid, -1msg1);
                        
mysql_free_result();
                    }
                    
mysql_free_result();
                }
                else
                {
                    
SendClientMessage(playerid, -1"{FF0000}[ERROR]{FFFFFF} That player doesn't exist in the database.");
                }
            }
        }
        else
        {
            
SendClientMessage(playerid, -1"{FF0000}[ERROR]{FFFFFF} You're not authorized to use this command.");
        }
    }
    else
    {
        
SendClientMessage(playerid, -1"{FF0000}[ERROR] {FFFFFF}You must be logged in to use commands.");
    }
    return 
1;

Quote:

format(banreason, sizeof(banreason), "INSERT INTO `playerbans` (`banned_by`, `banned_for`, `player_banned`, `player_ip`) VALUES ('%s', '%s', '%s', '%s')", GetName(playerid), reason, otherPlayer, playerIP);

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)