/setname crashes the server
#1

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..
Reply
#2

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;
}
Reply
#3

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

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.
Reply
#5

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
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)