SA-MP Forums Archive
/setname crashes the server - 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: /setname crashes the server (/showthread.php?tid=443089)



/setname crashes the server - DetoNater - 10.06.2013

Actually when i execute this code the server crashes and the samp-server.exe closes, and the name is not changed in the database!!

pawn Код:
CMD:setname(playerid, params[])
{
    if(aDuty[playerid] == 1)
    if(PlayerInfo[playerid][pAdmin] >= 4)
    {
            new name[MAX_PLAYER_NAME],string1[128],query[128],q[128];
            new targetid, inputtext[25];
            if(sscanf(params, "u", targetid, inputtext)) return SendClientMessage(playerid, C_GREY, "USAGE: /setname [playerid] [new name]");
            {
            format(q,sizeof(q),"SELECT * FROM `accounts` WHERE user = '%s'",inputtext);
            mysql_query(q);
            mysql_store_result();
            if(mysql_num_rows()>0)
            {
            SendClientMessage(playerid, C_RED,"SERVER: That name is already taken. Please choose another name.");
            }
            else
            {
            GetPlayerName(playerid, name, sizeof(name));
            format(query, sizeof(query), "UPDATE `accounts` SET user ='%s' WHERE user ='%s'",inputtext,name);
            mysql_query(query);
            format(string1, sizeof(string1), "ADMIN: %s have changed your name to %s [Use this username while logging in next time].",Name(playerid), inputtext);
            SendClientMessage(targetid, C_CYAN, string1);
            SendClientMessage(playerid, C_YELLOW, "You have successfully changed the name!");
            SetPlayerName(targetid, inputtext);
            mysql_free_result();
            }
            }
    } else return SendClientMessage(playerid, C_RED, "You are not authorized to use this command!");
    return 1;
}
Try to fix this problem as soon as possible..


Re: /setname crashes the server - Sascha - 10.06.2013

try this
Код:
CMD:setname(playerid, params[])
{
    if(aDuty[playerid] == 1)
    if(PlayerInfo[playerid][pAdmin] >= 4)
    {
            new name[MAX_PLAYER_NAME],string1[128],query[128],q[128];
            new targetid, inputtext[25];
            if(sscanf(params, "is[25]", targetid, inputtext)) return SendClientMessage(playerid, C_GREY, "USAGE: /setname [playerid] [new name]");
            {
			if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, C_GREY, "Player not connected");
            format(q,sizeof(q),"SELECT * FROM `accounts` WHERE user = '%s'",inputtext);
            mysql_query(q);
            mysql_store_result();
            if(mysql_num_rows()>0)
            {
            SendClientMessage(playerid, C_RED,"SERVER: That name is already taken. Please choose another name.");
            }
            else
            {
            GetPlayerName(targetid, name, sizeof(name));
            format(query, sizeof(query), "UPDATE `accounts` SET user ='%s' WHERE user ='%s'",inputtext,name);
            mysql_query(query);
            format(string1, sizeof(string1), "ADMIN: %s have changed your name to %s [Use this username while logging in next time].",Name(playerid), inputtext);
            SendClientMessage(targetid, C_CYAN, string1);
            SendClientMessage(playerid, C_YELLOW, "You have successfully changed the name!");
            SetPlayerName(targetid, inputtext);
            mysql_free_result();
            }
            }
    } else return SendClientMessage(playerid, C_RED, "You are not authorized to use this command!");
    return 1;
}



Re: /setname crashes the server - DetoNater - 10.06.2013

Fine bro it worked , btw what is my mistake in the script i'd like to learn from it


Re: /setname crashes the server - moadi - 10.06.2013

Quote:
Originally Posted by DetoNater
Посмотреть сообщение
Fine bro it worked , btw what is my mistake in the script i'd like to learn from it
Код:
if(sscanf(params, "u", targetid, inputtext)) return SendClientMessage(playerid, C_GREY, "USAGE: /setname [playerid] [new name]");
Should be
Код:
if(sscanf(params, "us[25]", targetid, inputtext)) return SendClientMessage(playerid, C_GREY, "USAGE: /setname [playerid] [new name]");
The 's' stands for string, which is inputtext and the [25] is the length of it.


Re: /setname crashes the server - Sascha - 10.06.2013

what he said and in addition you should check whether the player who's name you want to change is actually connected (IsPlayerConnected) and you used "GetPlayerName(playerid,....)" whereas it should be "GetPlayerName(targetid,...)" as you want to have the name of the player you selected and not your own
so it would've changed your own name in the database and not the name of the player you selected :P