[HELP] Changename with MySQL +REP1
#1

How to make changename commands in using MySQL ?
Btw my Data Base name is `venom`, table name is `players` , and player name is `Username`!

Sorry for my bad english -_-
Reply
#2

This query would rename a player named "some" to player named "example"
PHP код:
UPDATE `playersSET `Username` = 'example' WHERE `Username` = 'some'
UPDATE `playersSET `Username` = 'example' WHERE `ID`= '2'//better way here u have to use player id in mysql table which has autoincrement on it 
Reply
#3

How to check if name has already exists ?
Reply
#4

Код:
"SELECT `players` WHERE username = '%s'"
In your thread :
pawn Код:
if(cache_get_row_count()) // if the name already exists
{
}

else // we can change his name
{
}
Reply
#5

This my script :

pawn Код:
CMD:changename(playerid,params[])
{
    new newname[24];
    new query[128],query1[128];
    new mess[128];
   
    if(pInfo[playerid][Login] == 0) return Kick(playerid);
    if(sscanf(params,"s[24]",newname)) return SCM(playerid,-1,"**Usage : /changename [Name]");

    mysql_format(mysql, query, sizeof(query),"SELECT `players` WHERE Username = '%e' LIMIT 1", GetName(playerid));

    if(cache_get_row_count())
    {
        SCM(playerid,-1,"** The name already exists!");
    }
    else
    {
        mysql_format(mysql, query1, sizeof(query1), "UPDATE `players` SET `Username`= '%e' WHERE `ID`= '%d'",newname,pInfo[playerid][ID]);
        mysql_tquery(mysql, query1, "", "");
       
        format(mess,128,"** Your name has changed too : %s",newname);
        printf("**CHANGE-NAME : %s has change name to %s",GetName(playerid),newname);
        SCM(playerid,-1,mess);
        pKick(playerid);
    }
    return 1;
}
Still can use already name exists !
How to fix that ?
Reply
#6

no one ?
Reply
#7

You need a callback when you are SELECTing stuff, AFAIK
Reply
#8

can you make the script for me ?
Reply
#9

pawn Код:
CMD:changename(playerid, params[]) {
    if(isnull(params)) {
        return SendClientMessage(playerid, -1, "/changename [newname]");
    }

    if(strlen(params) > MAX_PLAYER_NAME) {
        return SendClientMessage(playerid, -1, "Your name must contain a maximum of 24 characters.");
    }

    new current[MAX_PLAYER_NAME];
    GetPlayerName(playerid, current, sizeof current);

    if(!strcmp(current, params, false)) {
        return SendClientMessage(playerid, -1, "That's already your name!");
    }

    new query[128];
    mysql_format(mysql, query, sizeof query, "SELECT * FROM `players` WHERE `Username` = '%s'", params);
    mysql_tquery(mysql, query, "ChangeName", "is", playerid, params);
    return 1;
}



forward ChangeName(playerid, newname[]);
public ChangeName(playerid, newname[]) {
    if(cache_get_row_count(mysql)) {
        return SendClientMessage(playerid, -1, "This name is already in use!");
    }

    new current[MAX_PLAYER_NAME];
    GetPlayerName(playerid, current, sizeof current);

    new query[128];
    mysql_format(mysql, query, sizeof query, "UPDATE `players` SET `Username` = '%s' WHERE `Username` = '%s'", newname, current);
    mysql_tquery(mysql, query);

    SetPlayerName(playerid, newname);
    return 1;
}
Reply
#10

Thanks so +rep1
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)