SA-MP Forums Archive
Changename mysql [+REP] - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Changename mysql [+REP] (/showthread.php?tid=564260)



Changename mysql [+REP] - simo0000 - 20.02.2015

i make a CMD change player name but i got 2 problems

the name doesn't change ingame and doesn't save in mysql DB plz help

pawn Код:
CMD:setname(playerid,params[])
{
    if(IsPlayerAdmin(playerid))
    {
        new id, name[24], str[130], query[1200], newname[24];
        if(sscanf(params, "ds", id,newname)) return SendClientMessage(playerid,COLOR_WHITE,"/SetName [Playerid] [New Name]");
        {
        GetPlayerName(id,name,24);
        format(str,130,"You Changed %s (%d)'s Name to %s",name,id,newname);
        SendClientMessage(playerid,COLOR_BLUE,str);
        format(str,130, "Admin Changed Your Name to %s",newname);
        format(query, sizeof(query), "UPDATE 'players' SET Username='%s' WHERE Username='%s'",newname,name);
        mysql_tquery(mysql, query);
        SendClientMessage(playerid,COLOR_BLUE,str);
        SetPlayerName(id,newname,24);
        }
    } else return SendClientMessage(playerid,COLOR_RED,"Your Level Is Not High Enough To Use This Command");
    return 1;
}

sorry for my bad english
thanks


Re : Changename mysql [+REP] - simo0000 - 20.02.2015

help plz


Re: Changename mysql [+REP] - HydraHumza - 20.02.2015

Quote:

format(query, sizeof(query), "UPDATE 'players' SET Username='%s' WHERE Username='%s'",newname,name);

recheck this format and when it fix it automatically save ur username


Re : Re: Changename mysql [+REP] - simo0000 - 20.02.2015

Quote:
Originally Posted by Humza
Посмотреть сообщение
recheck this format and when it fix it automatically save ur username
explain more plz


Re: Changename mysql [+REP] - Sledgehammer - 20.02.2015

if(sscanf(params, "ds[24]", id,newname)) - Try that.


Re : Re: Changename mysql [+REP] - simo0000 - 20.02.2015

Quote:
Originally Posted by simo0000
Посмотреть сообщение
help plz
Quote:
Originally Posted by Sledgehammer
Посмотреть сообщение
if(sscanf(params, "ds[24]", id,newname)) - Try that.
same problem :/ plz help


Re : Re: Changename mysql [+REP] - simo0000 - 20.02.2015

Quote:
Originally Posted by Sledgehammer
Посмотреть сообщение
if(sscanf(params, "ds[24]", id,newname)) - Try that.
and i get sscanf error: SSCANF_SetPlayerName has incorrect parameters.


Re: Changename mysql [+REP] - JeaSon - 20.02.2015

use mysql_format insteed of format and also you are using setplayername wrong there is 2 parameters not 3 , do not use only s in sscanf becoz it is for strings you need to define size too

pawn Код:
CMD:setname(playerid,params[])
{
    if(IsPlayerAdmin(playerid))
    {
        new id, name[24], str[130], query[200], newname[24];
        if(sscanf(params, "ds[24]", id,newname)) return     SendClientMessage(playerid,COLOR_WHITE,"/SetName [Playerid] [New Name]");
        {
            GetPlayerName(id,name,24);
        format(str,sizeof(str),"You Changed %s (%d)'s Name to %s",name,id,newname);
        SendClientMessage(playerid,COLOR_BLUE,str);
        format(str,sizeof(str), "Admin Changed Your Name to %s",newname);
        mysql_format(mysql,query, sizeof(query), "UPDATE 'players' SET Username='%s' WHERE Username='%s'",newname,name);
        mysql_tquery(mysql, query,"", "");
        SendClientMessage(playerid,COLOR_BLUE,str);
        SetPlayerName(id,newname);
        }
    } else return SendClientMessage(playerid,COLOR_RED,"Your Level Is Not High Enough To Use This Command");
    return 1;
}



Re: Re : Re: Changename mysql [+REP] - Sledgehammer - 20.02.2015

Quote:
Originally Posted by simo0000
Посмотреть сообщение
and i get sscanf error: SSCANF_SetPlayerName has incorrect parameters.
Currently in your code, you have 3 parmaters in "SetPlayerName" even though it only has 2 parmaters.

Example:
SetPlayerName(playerid, newname);

https://sampwiki.blast.hk/wiki/SetPlayerName

Does it save in the database now? If so, We're making progress. If not, I suggest debugging your code.


Re : Re: Re : Re: Changename mysql [+REP] - simo0000 - 20.02.2015

Quote:
Originally Posted by Sledgehammer
Посмотреть сообщение
Currently in your code, you have 3 parmaters in "SetPlayerName" even though it only has 2 parmaters.

Example:
SetPlayerName(playerid, newname);

https://sampwiki.blast.hk/wiki/SetPlayerName

Does it save in the database now? If so, We're making progress. If not, I suggest debugging your code.
this is mysql log last 2 lines

[17:16:49] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE 'players' SET Username='Farid_OConnor' WHERE Username='Mar", callback: "R", format: "v"
[17:16:49] [ERROR] mysql_tquery - callback parameter count does not match format specifier length