Setname
#1

pawn Код:
CMD:setname(playerid, params[])
    {
        new name[20];
        mysql_real_escape_string(name,escapename);
        GetPlayerName(playerid,Nam,sizeof(Nam));
        if(Logged[playerid] == 0)return SCM(playerid,orange,"Please login before using this command.");
        if(sscanf(params,"s",escapename))return SCM(playerid,grey,"USAGE: /setname [new name]");
        if(strlen(escapename) < 3) return SCM(playerid,orange,"Your name cannot be less than 3 characters.");
        if(strlen(escapename) > 20) return SCM(playerid,orange,"Your name cannot be more than 20 characters.");
        format(str,sizeof(str),"SELECT * FROM accounts WHERE Name = '%s'",escapename);
        mysql_query(str);
        mysql_store_result();
        if(mysql_num_rows() != 0)
        {
            mysql_free_result();
            return SCM(playerid,red,"ERROR: That Name is already Used by someone!");
        }
        if(mysql_num_rows() == 0)
        {
            if(strfind(escapename, "!", true) != -1 || strfind(escapename, "@", true) != -1 || strfind(escapename, "#", true) != -1 || strfind(escapename, "$", true) != -1 || strfind(escapename, "^", true) != -1 || strfind(escapename, "&", true) != -1 || strfind(escapename, "'", true) != -1)return SCM(playerid,red,"Please do not use symbols in your name.");
            if(strfind(escapename, " ", true) != -1)return SCM(playerid,red,"Don't use spaces in your name.");
            GetPlayerName(playerid,Nam,sizeof(Nam));
            format( str, sizeof( str ), "UPDATE accounts SET Name = '%s' WHERE Name = '%s'",escapename,Nam);
            mysql_query(str);
            //Achievement Change
            format(query,sizeof(query),"SELECT * FROM `Achievement` WHERE `Name` = '%s'",Nam);
            mysql_query(query);
            format(query,sizeof(query),"UPDATE `Achievement` SET `Name` = '%s' WHERE `Name` = '%s'",escapename,Nam);
            mysql_query(query);
            //Business Change
            format(str,sizeof(str),"SELECT * FROM `Business` WHERE `Owner` = '%s'",Nam);
            mysql_query(str);
            if(PlayerData[playerid][OwnBus] == 1)
            {
                format(str,sizeof(str),"UPDATE `Business` SET `Owner` = '%s'",pname);
                mysql_query(str);
            }
            //TcR Name
            if(strfind(escapename,"[TcR]",true) != -1)
            {
                format(str,sizeof(str),"SELECT `Name` FROM `clanmembers` WHERE `Name` = '%s'",Nam);
                mysql_query(str);
                mysql_store_result();
                if(mysql_num_rows() == 0)return SCM(playerid,red,"ERROR: Your not in the [TcR] Clan");
                if(mysql_num_rows() != 0) return format(str,sizeof(str),"UDPATE `clanmembers` SET `Name` = '%s' WHERE `Name` = '%s'",escapename,Nam) && mysql_query(str);
            }
            //Org Change
            format(str,sizeof(str),"SELECT * FROM orgs WHERE Orgid = %d",PlayerData[playerid][Member]);
            mysql_query(str);
            if(PlayerData[playerid][Leader] == 1)
            {
                GetPlayerName(playerid,Nam,sizeof(Nam));
                mysql_store_result();
                format(str,sizeof(str),"UPDATE orgs SET Leader = '%s' WHERE Orgid = '%d'",Nam,PlayerData[playerid][Member]);
                mysql_query(str);
                mysql_free_result();
                format(OrgInfo[PlayerData[playerid][Member]][LName],24,"%s",Nam);
                mysql_query(str);
            }
            format(str,sizeof(str),"You have changed your name to {FF0000}%s.",escapename);
            SCM(playerid,lightyellow,str);
            format(str,sizeof(str),"{FF0000}%s{FFFFFF} has changed his name to {8080FF}%s",Nam,escapename);
            SendClientMessageToAll(-1,str);
            SetPlayerName(playerid,escapename);
        }
        return 1;
    }
for some reason when i enter it will show unknown command sometimes or this name is used while it is not (i think its the //TcR Name problem
Reply
#2

Код:
UPDATE clanmembers SET `Name` = '%s' WHERE `Name` = '%s'
Reply
#3

for somereason i get unknown command sometimes or This Name is used by someone while it is not
pawn Код:
CMD:setname(playerid, params[])
    {
        new name[20];
        mysql_real_escape_string(name,escapename);
        GetPlayerName(playerid,Nam,sizeof(Nam));
        if(Logged[playerid] == 0)return SCM(playerid,orange,"Please login before using this command.");
        if(sscanf(params,"s",escapename))return SCM(playerid,grey,"USAGE: /setname [new name]");
        if(strlen(escapename) < 3) return SCM(playerid,orange,"Your name cannot be less than 3 characters.");
        if(strlen(escapename) > 20) return SCM(playerid,orange,"Your name cannot be more than 20 characters.");
        format(str,sizeof(str),"SELECT * FROM accounts WHERE Name = '%s'",escapename);
        mysql_query(str);
        mysql_store_result();
        if(mysql_num_rows() != 0)
        {
            mysql_free_result();
            return SCM(playerid,red,"ERROR: That Name is already Used by someone!");
        }
        if(mysql_num_rows() == 0)
        {
            if(strfind(escapename, "!", true) != -1 || strfind(escapename, "@", true) != -1 || strfind(escapename, "#", true) != -1 || strfind(escapename, "$", true) != -1 || strfind(escapename, "^", true) != -1 || strfind(escapename, "&", true) != -1 || strfind(escapename, "'", true) != -1)return SCM(playerid,red,"Please do not use symbols in your name.");
            if(strfind(escapename, " ", true) != -1)return SCM(playerid,red,"Don't use spaces in your name.");
            GetPlayerName(playerid,Nam,sizeof(Nam));
            format( str, sizeof( str ), "UPDATE accounts SET Name = '%s' WHERE Name = '%s'",escapename,Nam);
            mysql_query(str);
            //Achievement Change
            format(query,sizeof(query),"SELECT * FROM `Achievement` WHERE `Name` = '%s'",Nam);
            mysql_query(query);
            format(query,sizeof(query),"UPDATE `Achievement` SET `Name` = '%s' WHERE `Name` = '%s'",escapename,Nam);
            mysql_query(query);
            //Business Change
            format(str,sizeof(str),"SELECT * FROM `Business` WHERE `Owner` = '%s'",Nam);
            mysql_query(str);
            if(PlayerData[playerid][OwnBus] == 1)
            {
                format(str,sizeof(str),"UPDATE `Business` SET `Owner` = '%s'",pname);
                mysql_query(str);
            }
            //TcR Name
            if(strfind(escapename,"[TcR]",true) != -1)
            {
                format(str,sizeof(str),"SELECT `Name` FROM `clanmembers` WHERE `Name` = '%s'",Nam);
                mysql_query(str);
                mysql_store_result();
                if(mysql_num_rows() == 0)return SCM(playerid,red,"ERROR: Your not in the [TcR] Clan");
                if(mysql_num_rows() != 0) return format(str,sizeof(str),"UDPATE `clanmembers` SET `Name` = '%s' WHERE `Name` = '%s'",escapename,Nam) && mysql_query(str);
            }
            //Org Change
            format(str,sizeof(str),"SELECT * FROM orgs WHERE Orgid = %d",PlayerData[playerid][Member]);
            mysql_query(str);
            if(PlayerData[playerid][Leader] == 1)
            {
                GetPlayerName(playerid,Nam,sizeof(Nam));
                mysql_store_result();
                format(str,sizeof(str),"UPDATE orgs SET Leader = '%s' WHERE Orgid = '%d'",Nam,PlayerData[playerid][Member]);
                mysql_query(str);
                mysql_free_result();
                format(OrgInfo[PlayerData[playerid][Member]][LName],24,"%s",Nam);
                mysql_query(str);
            }
            format(str,sizeof(str),"You have changed your name to {FF0000}%s.",escapename);
            SCM(playerid,lightyellow,str);
            format(str,sizeof(str),"{FF0000}%s{FFFFFF} has changed his name to {8080FF}%s",Nam,escapename);
            SendClientMessageToAll(-1,str);
            SetPlayerName(playerid,escapename);
        }
        return 1;
    }
(No i did not copy achievement, business and orgs. I just used // to organize my self)
Reply
#4

bump
Reply
#5

bump
Reply
#6

pawn Код:
new name[20];
        mysql_real_escape_string(name,escapename);
That doesn't make sense at all. You're just escaping an empty string there. Besides, where do you define escapename in the first place?
Reply
#7

Quote:
Originally Posted by Vince
Посмотреть сообщение
pawn Код:
new name[20];
        mysql_real_escape_string(name,escapename);
That doesn't make sense at all. You're just escaping an empty string there. Besides, where do you define escapename in the first place?
on the top of my script
pawn Код:
new escapename[32];
Reply
#8

bump
Reply
#9

pawn Код:
CMD:setname(playerid, params[])
{
    new len;
    if(!Logged[playerid]) SCM(playerid,orange,"Please login before using this command.");
    else if(isnull(params)) SCM(playerid,grey,"USAGE: /setname [new name]");
    else if(!(2 < (len = strlen(params)) < 21)) SCM(playerid,orange,"Your name cannot be less than 3 and more than 20 characters.");
    else{
        new NewNick[24];
        mysql_real_escape_string(params,NewNick);
        format(str,sizeof(str),"SELECT * FROM accounts WHERE Name = '%s' LIMIT 1;",NewNick);
        mysql_query(str);
        mysql_store_result();
        if(mysql_num_rows())
        {
            mysql_free_result();
            SCM(playerid,red,"ERROR: That Name is already Used by someone!");
        }
        else
        {
            mysql_free_result();
            static characters[] = {'!','@','#','$','^','&','\'',' '};
            for(new i; i < len; i++)
                for(new d; d < sizeof(characters); d++)
                    if(params[i] == characters[d]) return SCM(playerid,red,"Invalid characters in nickname.");
            GetPlayerName(playerid,Nam,sizeof(Nam));
            format( str, sizeof( str ), "UPDATE accounts SET Name = '%s' WHERE Name = '%s'",NewNick,Nam);
            mysql_query(str);
            //Achievement Change
            format(query,sizeof(query),"UPDATE `Achievement` SET `Name` = '%s' WHERE `Name` = '%s'",NewNick,Nam);
            mysql_query(query);
            //Business Change
            if(PlayerData[playerid][OwnBus] == 1)
            {
                format(str,sizeof(str),"UPDATE `Business` SET `Owner` = '%s'",NewNick);
                mysql_query(str);
            }
            //TcR Name
            if(strfind(NewNick,"[TcR]",true) != -1)
            {
                format(str,sizeof(str),"SELECT `Name` FROM `clanmembers` WHERE `Name` = '%s'",Nam);
                mysql_query(str);
                mysql_store_result();
                new rows = mysql_num_rows();
                mysql_free_result();
                if(!rows) SCM(playerid,red,"ERROR: Your not in the [TcR] Clan");
                else{
                    format(str,sizeof(str),"UDPATE `clanmembers` SET `Name` = '%s' WHERE `Name` = '%s'",NewNick,Nam);
                    mysql_query(str);
                }
            }
            //Org Change
            if(PlayerData[playerid][Leader] == 1)
            {
                format(str,sizeof(str),"UPDATE orgs SET Leader = '%s' WHERE Orgid = '%d'",Nam,PlayerData[playerid][Member]);
                mysql_query(str);
                new Mem = PlayerData[playerid][Member];
                strcat((OrgInfo[Mem][LName][0]='\0',OrgInfo[Mem][LName]),NewNick);
            }
            format(str,sizeof(str),"You have changed your name to {FF0000}%s.",NewNick);
            SCM(playerid,lightyellow,str);
            format(str,sizeof(str),"{FF0000}%s{FFFFFF} has changed his name to {8080FF}%s",Nam,NewNick);
            SendClientMessageToAll(-1,str);
            SetPlayerName(playerid,NewNick);
        }
    }
    return 1;
}
My 1,000 post ^^
Reply
#10

now i get some problem with "That name is registered by someone"
pawn Код:
CMD:setname(playerid, params[])
    {
        new name[24];
        GetPlayerName(playerid,Nam,sizeof(Nam));
        if(Logged[playerid] == 0)return SCM(playerid,orange,"Please login before using this command.");
        if(sscanf(params,"s[24]",name))return SCM(playerid,grey,"USAGE: /setname [new name]");
        if(strlen(name) < 3) return SCM(playerid,orange,"Your name cannot be less than 3 characters.");
        if(strlen(name) > 20) return SCM(playerid,orange,"Your name cannot be more than 20 characters.");
        format(str,sizeof(str),"SELECT * FROM accounts WHERE Name = '%s'",name);
        mysql_query(str);
        if(mysql_num_rows() != 0)
        {
            SCM(playerid,red,"ERROR: That Name is already Used by someone!");
        }
        if(mysql_num_rows() == 0)
        {
            if(strfind(name, "!", true) != -1 || strfind(name, "@", true) != -1 || strfind(name, "#", true) != -1 || strfind(name, "$", true) != -1 || strfind(name, "^", true) != -1 || strfind(name, "&", true) != -1 || strfind(name, "'", true) != -1)return SCM(playerid,red,"Please do not use symbols in your name.");
            if(strfind(name, " ", true) != -1)return SCM(playerid,red,"Don't use spaces in your name.");
            GetPlayerName(playerid,Nam,sizeof(Nam));
            format( str, sizeof( str ), "UPDATE `accounts` SET `Name` = '%s' WHERE `Name` = '%s'",name,Nam);
            mysql_query(str);
            //Achievement Change
            format(query,sizeof(query),"UPDATE `Achievement` SET `Name` = '%s' WHERE `Name` = '%s'",name,Nam);
            mysql_query(query);
            //Business Change
            format(str,sizeof(str),"SELECT * FROM `Business` WHERE `Owner` = '%s'",Nam);
            mysql_query(str);
            if(PlayerData[playerid][OwnBus] == 1)
            {
                format(str,sizeof(str),"UPDATE `Business` SET `Owner` = '%s'",name);
                mysql_query(str);
            }
            //TcR Name
            if(strfind(name,"[TcR]",true) != -1)
            {
                format(str,sizeof(str),"SELECT `Name` FROM `clanmembers` WHERE `Name` = '%s'",Nam);
                mysql_query(str);
                mysql_store_result();
                new rows = mysql_num_rows();
                mysql_free_result();
                if(!rows) SCM(playerid,red,"ERROR: Your not in the [TcR] Clan");
                else{
                    format(str,sizeof(str),"UDPATE `clanmembers` SET `Name` = '%s' WHERE `Name` = '%s'",name,Nam);
                    mysql_query(str);
                }
            }
            //Org Change
            format(str,sizeof(str),"SELECT * FROM orgs WHERE Orgid = %d",PlayerData[playerid][Member]);
            mysql_query(str);
            if(PlayerData[playerid][Leader] == 1)
            {
                GetPlayerName(playerid,Nam,sizeof(Nam));
                mysql_store_result();
                format(str,sizeof(str),"UPDATE orgs SET Leader = '%s' WHERE Orgid = '%d'",name,PlayerData[playerid][Member]);
                mysql_query(str);
                mysql_free_result();
                format(OrgInfo[PlayerData[playerid][Member]][LName],24,"%s",name);
                mysql_query(str);
            }
            format(str,sizeof(str),"You have changed your name to {FF0000}%s.",name);
            SCM(playerid,lightyellow,str);
            format(str,sizeof(str),"{FF0000}%s{FFFFFF} has changed his name to {8080FF}%s",Nam,name);
            SendClientMessageToAll(-1,str);
            SetPlayerName(playerid,name);
        }
        return 1;
    }
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)