setname bug
#1

Well when i use that command and type a name that is used, for some reason it still changes name... help
pawn Код:
COMMAND:setname(playerid, params[])
{
    new name[32];
    if(Logged[playerid] == 0)return SendClientMessage(playerid,orange,"Please login before using this command.");
    if(sscanf(params,"s",name))return SendClientMessage(playerid,orange,"Usage: /setname [new name]");
    if(strlen(name) < 3) return SendClientMessage(playerid,orange,"Your name cannot be less than 3 characters.");
    if(strlen(name) > 32) return SendClientMessage(playerid,orange,"Your name cannot be more than 32 characters.");
    GetPlayerName(playerid,Nam,sizeof(Nam));
    format(str,sizeof(str),"UPDATE accounts SET Name = '%s' WHERE Name = '%s'",name,Nam);
    mysql_query(str);
    format(str,sizeof(str),"You have changed your name to {FF0000}%s.",name);
    SendClientMessage(playerid,-1,str);
    SetPlayerName(playerid,name);
    return 1;
}
Reply
#2

That is because you never check if the name is taken in the first place, you just instantly update the information in the database. Run a query to check if the new name is already in the database and if it is return an error to the user.
Reply
#3

im new with mysql, how i do that :S
Reply
#4

pawn Код:
format( str, sizeof( str ), "SELECT something FROM `accounts` WHERE Name = '%s'", name );
mysql_query( str );
mysql_store_result( );
if( mysql_num_rows( ) != 0 )
{
   // Someone else already has the name
}
Reply
#5

in // do i put SendClientMessage(playerid,red,"ERROR: That name is Used!"); ??
Reply
#6

It's up to you, whatever you want to happen. You may also want to add the 'return 1;' statement as well after sending the message, so it stops the rest of the code from executing afterwards.
Reply
#7

Well actually well i tested it and put used name, it still changes
pawn Код:
COMMAND:setname(playerid, params[])
{
    new name[32];
    if(Logged[playerid] == 0)return SendClientMessage(playerid,orange,"Please login before using this command.");
    if(sscanf(params,"s",name))return SendClientMessage(playerid,orange,"Usage: /setname [new name]");
    if(strlen(name) < 3) return SendClientMessage(playerid,orange,"Your name cannot be less than 3 characters.");
    if(strlen(name) > 32) return SendClientMessage(playerid,orange,"Your name cannot be more than 32 characters.");
    GetPlayerName(playerid,Nam,sizeof(Nam));
    format( str, sizeof( str ), "SELECT something FROM `accounts` WHERE Name = '%s'", name );
    mysql_query( str );
    mysql_store_result( );
    if( mysql_num_rows( ) != 0 )
    {
        SendClientMessage(playerid,red,"ERROR: That Name is already Used by someone!");
    }
    format(str,sizeof(str),"You have changed your name to {FF0000}%s.",name);
    SendClientMessage(playerid,-1,str);
    SetPlayerName(playerid,name);
    return 1;
}
Reply
#8

pawn Код:
format( str, sizeof( str ), "SELECT something FROM `accounts` WHERE Name = '%s'", name );
You didn't even change the query to work with your server...
Reply
#9

Make i loop through all players to check if the name is already used.
If not then set the name, else shows "THe name is already is used "
Reply
#10

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
pawn Код:
format( str, sizeof( str ), "SELECT something FROM `accounts` WHERE Name = '%s'", name );
You didn't even change the query to work with your server...
Can ya help me by showing the full command edited cause im a noob in mysql, and the guy that post after this guy. I will do the thing u say if this doesnt work
Reply
#11

http://dev.mysql.com/ has all you need.
Reply
#12

link doesnt work
Reply
#13

Quote:
Originally Posted by Tanush123
Посмотреть сообщение
link doesnt work
Oh sorry. I posted the wrong domain extension.

Check it now: http://dev.mysql.com
Reply
#14

arr i cant find samp in that -_-, i just only need help with Setname
Reply
#15

Quote:
Originally Posted by Tanush123
Посмотреть сообщение
arr i cant find samp in that -_-, i just only need help with Setname
The mysql functions are exactly the same? ;o
Reply
#16

Quote:
Originally Posted by Tanush123
Посмотреть сообщение
arr i cant find samp in that -_-, i just only need help with Setname
You aren't supposed to find anything related to SA-MP on that website. It helps you understand how MySQL works and what syntax's perform which operations.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)