Hello (/setname) problem +REP
#1

Hello i'm using Y_INI ,i've tried multipe times to change the account name but it doesn't replace the new name to the old one, is there a problem with the code?
Код:
CMD:setname(playerid, params[])
{
	new giveplayerid, newname[24], string[128], sendername[MAX_PLAYER_NAME], giveplayer[MAX_PLAYER_NAME];
	if(PlayerInfo[playerid][pAdmin] >= 3)
	{
		if(!sscanf(params, "us[24]", giveplayerid, newname))
		{
			if(IsPlayerConnected(giveplayerid))
			{
				if(giveplayerid != INVALID_PLAYER_ID)
				{
					new string6[50];
					format(string6, sizeof(string6), "Accounts/%s.ini", newname);
					format(string, sizeof(string), "Accounts/%s.ini", newname);
					if(fexist(string))
					{
						SendClientMessage(playerid, COLOR_GRAD1, "That name is already registered.");
						return 1;
					}
					strmid(sendername, PlayerName(playerid), 0, MAX_PLAYER_NAME);
					strmid(giveplayer, PlayerName(giveplayerid), 0, MAX_PLAYER_NAME);
					SetPlayerName(giveplayerid, newname);
					format(string, sizeof(string), "Accounts/%s.ini", giveplayer);
					SaveAccounts();
					if(INI_Exist(string6))
					{
						fremove(string);
					}
					else
					{
					    SendClientMessage(playerid, COLOR_NICERED, "There was a problem with saving the account! Reverting changes...");
                        SetPlayerName(giveplayerid, giveplayer);
						if(INI_Exist(string6)) // For some odd reason it exists?
						{
						    fremove(string6);
							SaveAccounts();
						}
					}
					format(string, sizeof(string), "  You have renamed %s to %s !", giveplayer, newname);
					SendInfoMessage(playerid,2,"0", string);
					format(string, sizeof(string), "Your name has been changed from %s to %s.", giveplayer, newname);
					SendInfoMessage(giveplayerid,2,"0", string);
				}
			}
		}
		else
		{
		    SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setname [playerid/PartOfName] [name]");
		}
	}
	else
	{
		SendClientMessage(playerid, COLOR_GRAD1, "   {FF0000}ERROR{FFFFFF}: you do not have sufficient permissions!");
	}
	return 1;
}
Reply
#2

Look this one isn't working too, it deletes the file without creating the new one..
Код:
CMD:setname(playerid, params[])
{
	new string[128], giveplayerid, name[MAX_PLAYER_NAME];
	new playername[MAX_PLAYER_NAME];
	if(sscanf(params, "us[24]", giveplayerid, name)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setname [playerid/partofname] [newname]");

	if(IsPlayerConnected(giveplayerid))
	{
		if(PlayerInfo[playerid][pAdmin] >= 4)
		{
			if(!INI_Exist(name))
			{
				new
					newname[MAX_PLAYER_NAME + 10];

				GetPlayerName(giveplayerid, playername, sizeof(playername));
				format(newname, sizeof(newname), "Accounts/%s.ini", name);
				format(string, sizeof(string), "{FF1B31}[Administration]{FFFFFF} %s has renamed %s to %s.", PlayerName(playerid), playername, newname);
				ABroadCast(COLOR_GRAD1,string,2);
				
				format(newname, sizeof(newname), "Accounts/%s.ini", playername);
				fremove(newname);

				if(INI_Exist(playername))  // If it doesn't get removed, blank the file with write io and check its length when a player attempts to authenticate (it'll be 0)
				{
					new File: BlankTheFile = fopen(newname, io_write);
					SendClientMessage(playerid, COLOR_GRAD2, "The old account couldn't be removed completely (it's been blanked for future use).");
					fclose(BlankTheFile);
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_WHITE, "This name is already registered.");
			}
		}
		else
		{
			SendClientMessage(playerid, COLOR_GRAD2, "You're not authorised to use this command.");
		}
	}
	else
	{
		SendClientMessage(playerid, COLOR_GRAD2, "No Such Player");
	}
	return 1;
}
Reply
#3

what exactly is the problem ?
Reply
#4

Change:
pawn Код:
format(string6, sizeof(string6), "Accounts/%s.ini", newname);
To:
pawn Код:
format(string6, sizeof(string6), "Accounts/%s.ini", PlayerName(playerid));
And:
pawn Код:
if(INI_Exist(string6))
{
    fremove(string);
}
To:
pawn Код:
if(INI_Exist(string6))
{
    fremove(string6);
}
Reply
#5

This script seems familiar from my previous experiences, where did you get it from? Not trying to be rude... but it's like 95 percent the same of what I have seen before, from a server I'm developing. Funny enough just recently converted this bit to mySQL & changed it all.
Reply
#6

Not the script it's a command -.-
Reply
#7

i've tried this one, and still,
it doesn't change the account name, it does in game but in Accounts no it only deletes the old name, file,i wish i can fix it , please if you can help me tell me
i'm using Y_INI Save data..

Код:
CMD:setname(playerid, params[])
{
	new string[128], giveplayerid, name[MAX_PLAYER_NAME];
	new playername[MAX_PLAYER_NAME];
	if(sscanf(params, "us[24]", giveplayerid, name)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setname [playerid/partofname] [newname]");

	if(IsPlayerConnected(giveplayerid))
	{
		if(PlayerInfo[playerid][pAdmin] >= 4)
		{

			if(!DoesAccountExist(name))
			{
				new
					newname[MAX_PLAYER_NAME + 10];

				GetPlayerName(giveplayerid, playername, sizeof(playername));
				format(newname, sizeof(newname), "Accounts/%s.ini", name);

				format(string, sizeof(string), " Your name has been changed from %s to %s.", GetPlayerNameEx(giveplayerid), name);
				SendClientMessage(giveplayerid,COLOR_YELLOW,string);
				format(string, sizeof(string), " You have changed %s's name to %s.", GetPlayerNameEx(giveplayerid), name);
				SendClientMessage(playerid,COLOR_YELLOW,string);

				SetPlayerName(giveplayerid, name);

				format(newname, sizeof(newname), "Accounts/%s.ini", playername);
				fremove(newname);

				if(DoesAccountExist(playername))  // If it doesn't get removed, blank the file with write io and check its length when a player attempts to authenticate (it'll be 0)
				{
					new File: BlankTheFile = fopen(newname, io_write);
					SendClientMessage(playerid, COLOR_GRAD2, "The old account couldn't be removed completely (it's been blanked for future use).");
					fclose(BlankTheFile);
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_WHITE, "This name is already registered.");
			}
		}
		else
		{
			SendClientMessage(playerid, COLOR_GRAD2, "You're not authorised to use this command.");
		}
	}
	else
	{
		SendClientMessage(playerid, COLOR_GRAD2, "No Such Player");
	}
	return 1;
}
And here the stock of "DoesAccountExist"

Код:
stock DoesAccountExist(account_name[])
{
	new sz_accStr[MAX_PLAYER_NAME + 12], File:f_Handle;

	format(sz_accStr, sizeof(sz_accStr), "Accounts/%s.ini", account_name);
	if(fexist(sz_accStr)) {

		if(!(f_Handle = fopen(sz_accStr, io_read))) {
			return 1;
		}

		if(flength(f_Handle) > 0) {
			fclose(f_Handle);
			return 1;
		}
		fclose(f_Handle);
	}
	return 0;
}
Reply
#8

after i've removed
" format(newname, sizeof(newname), "Accounts/%s.ini", playername);
fremove(newname);
"
it work's perfect but it doesn't delete the old name, it's a serious problem guys please help me -.-
Reply
#9

pawn Код:
CMD:setname(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] < 3) return SendClientMessage(playerid, COLOR_GRAD1, "   {FF0000}ERROR{FFFFFF}: you do not have sufficient permissions!");
    new giveplayerid, newname[MAX_PLAYER_NAME];
    if(!sscanf(params, "us[24]", giveplayerid, newname)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setname [playerid/PartOfName] [name]");
    if(!IsPlayerConnected(giveplayerid) || giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GRAD1, "   {FF0000}ERROR{FFFFFF}: player is not connected!");
    //Perhaps check if the player is logged in and/or registered here?
    new string[90];
    format(string, sizeof(string), "Accounts/%s.ini", newname);
    if(fexist(string)) return SendClientMessage(playerid, COLOR_GRAD1, "That name is already registered.");
    new string2[40];
    format(string2, sizeof(string2), "Accounts/%s.ini", PlayerName(giveplayerid));
    if(INI_Exist(string2)) fremove(string2);
    else SendClientMessage(playerid, COLOR_NICERED, "There was a problem with saving the account! Reverting changes...");
    //SaveAccounts(); //Wrong. You should be transferring the player's current stats from his current account to the new account
    SetPlayerName(giveplayerid, newname);
    format(string, sizeof(string), "  You have renamed %s to %s !", PlayerName(giveplayerid), newname);
    SendInfoMessage(playerid, 2, "0", string);
    format(string, sizeof(string), "Your name has been changed from %s to %s.", PlayerName(giveplayerid), newname);
    SendInfoMessage(giveplayerid, 2, "0", string);
    return 1;
}
Can you show me your SaveAccounts function?
Reply
#10

Quote:
Originally Posted by Threshold
Посмотреть сообщение
pawn Код:
CMD:setname(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] < 3) return SendClientMessage(playerid, COLOR_GRAD1, "   {FF0000}ERROR{FFFFFF}: you do not have sufficient permissions!");
    new giveplayerid, newname[MAX_PLAYER_NAME];
    if(!sscanf(params, "us[24]", giveplayerid, newname)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setname [playerid/PartOfName] [name]");
    if(!IsPlayerConnected(giveplayerid) || giveplayerid == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_GRAD1, "   {FF0000}ERROR{FFFFFF}: player is not connected!");
    //Perhaps check if the player is logged in and/or registered here?
    new string[90];
    format(string, sizeof(string), "Accounts/%s.ini", newname);
    if(fexist(string)) return SendClientMessage(playerid, COLOR_GRAD1, "That name is already registered.");
    new string2[40];
    format(string2, sizeof(string2), "Accounts/%s.ini", PlayerName(giveplayerid));
    if(INI_Exist(string2)) fremove(string2);
    else SendClientMessage(playerid, COLOR_NICERED, "There was a problem with saving the account! Reverting changes...");
    //SaveAccounts(); //Wrong. You should be transferring the player's current stats from his current account to the new account
    SetPlayerName(giveplayerid, newname);
    format(string, sizeof(string), "  You have renamed %s to %s !", PlayerName(giveplayerid), newname);
    SendInfoMessage(playerid, 2, "0", string);
    format(string, sizeof(string), "Your name has been changed from %s to %s.", PlayerName(giveplayerid), newname);
    SendInfoMessage(giveplayerid, 2, "0", string);
    return 1;
}
Can you show me your SaveAccounts function?
it doesn't work it crashes the server :/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)