SA-MP Forums Archive
SQL help - 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: SQL help (/showthread.php?tid=505272)



SQL help - Hybris - 07.04.2014

Hello I was wondering if anyone would have a /setname command sql anyone that can help me will be repped.


Re: SQL help - Hybris - 08.04.2014

*BUMP*


Re: SQL help - Binx - 08.04.2014

pawn Код:
CMD:setname(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 2)
    {
        new
            szQuery[128],
            Player,
            NewPlayerName[MAX_PLAYER_NAME];

        if(sscanf(params, "us[24]", Player, NewPlayerName))
            return SendClientMessage(playerid, COLOR_GREY, "SERVER: /setname [playerid] [new name]");

        SetPVarInt(Player, "changeBy", playerid);
        SetPVarString(Player, "oldName", PlayerInfo[Player][pUsername]);

        mysql_real_escape_string(NewPlayerName, PlayerInfo[Player][pUsername], 24);

        format(szQuery, sizeof(szQuery), "UPDATE players SET Username = '%s' WHERE ID = %d", PlayerInfo[Player][pUsername], PlayerInfo[Player][pDBID]);
        mysql_query(szQuery, THREAD_CHANGE_NAME, Player, iConnectionHandle);
    }
    else return SendClientMessage(playerid, COLOR_RED, "You're not an admin!");
    return true;
}
You might have to edit it to your script.

EDIT: "This forum requires that you wait 120 seconds between posts. Please try again in 40 seconds." ffs


Re: SQL help - Flake. - 08.04.2014

Quote:
Originally Posted by Binx
Посмотреть сообщение
pawn Код:
CMD:setname(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] >= 2)
    {
        new
            szQuery[128],
            Player,
            NewPlayerName[MAX_PLAYER_NAME];

        if(sscanf(params, "us[24]", Player, NewPlayerName))
            return SendClientMessage(playerid, COLOR_GREY, "SERVER: /setname [playerid] [new name]");

        SetPVarInt(Player, "changeBy", playerid);
        SetPVarString(Player, "oldName", PlayerInfo[Player][pUsername]);

        mysql_real_escape_string(NewPlayerName, PlayerInfo[Player][pUsername], 24);

        format(szQuery, sizeof(szQuery), "UPDATE players SET Username = '%s' WHERE ID = %d", PlayerInfo[Player][pUsername], PlayerInfo[Player][pDBID]);
        mysql_query(szQuery, THREAD_CHANGE_NAME, Player, iConnectionHandle);
    }
    else return SendClientMessage(playerid, COLOR_RED, "You're not an admin!");
    return true;
}
You might have to edit it to your script.

EDIT: "This forum requires that you wait 120 seconds between posts. Please try again in 40 seconds." ffs
You never checked if a row already had the inputed string in it, people could just setname to what ever

pawn Код:
//You'll have to edit this a little however it should lay down the
//Base of how to make one yourself.
CMD:changename(playerid, params[])
{
    new newname[24], pname[24], mystring[256], string2[256], string3[256];
    if(sscanf(params, "s[24]",newname))return SendClientMessage(playerid,COLOR_LIGHTBLUE,"USAGE: {FFFFFF}/changename [New Name]");

    GetPlayerName(playerid,pname,24); //you can remove all this if you already have a getname funtion
    new query1[256],escapename[24];
    mysql_real_escape_string(newname, escapename);
    format(query1, sizeof(query1), "SELECT `nick` FROM `playerdata` WHERE `name` = '%s'", escapename); //Change this to your info
    mysql_query(query1);
    mysql_store_result();
    new rows = mysql_num_rows();
    if(!rows) //Checking if there is nothing in the row
    {
        new query[256];
        format(query, sizeof(query), "UPDATE `playerdata` SET `nick`= '%s' WHERE `nick` ='%s'",escapename,pname);
        mysql_query(query); //Again, change the line above to suit your database
        SetPlayerName(playerid , newname);

        format(string2, sizeof(string2),"You've changed your name from %s to %s", pname, newname);
        SendClientMessage(playerid, COLOR_ORANGE, string2);
    }
    else if(rows == 1) //If the row is filled with the string you inputted already it'll send this message.
    {
        SendClientMessage(playerid, 0xFF0000FF, "This name already exists!");
    }
    mysql_free_result();
    return 1;
}
Try that.