setname bug -
Tanush123 - 19.08.2011
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;
}
Re: setname bug -
Bakr - 19.08.2011
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.
Re: setname bug -
Tanush123 - 19.08.2011
im new with mysql, how i do that :S
Re: setname bug -
Bakr - 19.08.2011
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
}
Re: setname bug -
Tanush123 - 19.08.2011
in // do i put SendClientMessage(playerid,red,"ERROR: That name is Used!"); ??
Re: setname bug -
Bakr - 19.08.2011
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.
Re: setname bug -
Tanush123 - 21.08.2011
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;
}
Re: setname bug -
Scenario - 21.08.2011
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...
Re: setname bug -
Machida - 21.08.2011
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 "
Re: setname bug -
Tanush123 - 21.08.2011
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
Re: setname bug -
Scenario - 21.08.2011
http://dev.mysql.com/ has all you need.
Re: setname bug -
Tanush123 - 21.08.2011
link doesnt work
Re: setname bug -
Scenario - 21.08.2011
Quote:
Originally Posted by Tanush123
link doesnt work 
|
Oh sorry. I posted the wrong domain extension.
Check it now:
http://dev.mysql.com
Re: setname bug -
Tanush123 - 21.08.2011
arr i cant find samp in that -_-, i just only need help with Setname
Re: setname bug -
Pinguinn - 21.08.2011
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
Re: setname bug -
Scenario - 21.08.2011
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.