Changename Problem
#1

Hello!
I have a /changename command to change player name and rename player file!
But file doesn't change [%s.ini(name)]

Код:
if(dialogid == CHANGE_NAME)
{
if (response)
{

if(strlen(inputtext) < 4) return ShowPlayerDialog(playerid, CHANGE_NAME, DIALOG_STYLE_INPUT, "{AA3333}New Name", "Input your new name below\nName must be at least 4 lethers long!:", "Change", "Cancel");
if (dini_Exists(inputtext)) return SendClientMessage(playerid,COLOR_RED,"This User Name Is Taken!");
new name1[MAX_PLAYER_NAME],name2[MAX_PLAYER_NAME];
format(name1, sizeof(name1), PLAYERS, PlayerName(playerid));
format(name2, sizeof(name2), PLAYERS, inputtext);
SetPlayerName(playerid,inputtext);
frename(name1, name2);
}
}
Код:
stock frename(const oldname[], const newname[])
{
if (!fexist(oldname)) return 0;

new
File: oldfile = fopen(oldname, io_read),
File: newfile = fopen(newname, io_write),
line[128];
if (!oldfile || !newfile) return 0;
while (fread(oldfile, line)) fwrite(newfile, line);
fclose(oldfile);
fclose(newfile);
fremove(oldname);
return 1;
}
Reply
#2

Okay change this:

Код:
format(name1, sizeof(name1), PLAYERS, PlayerName(playerid));
format(name2, sizeof(name2), PLAYERS, inputtext);
to this:

Код:
format(name1, sizeof(name1), "%s", PlayerName(playerid));
format(name2, sizeof(name2), "%s", inputtext);
%s is a replacement character for strings.
Reply
#3

#define PLAYERS Server/Players/%s
??
Reply
#4

You didn't explain what Players was,

Also I am pretty sure you need to put quotes around the define like #define PLAYERS "Server/Players/%s"

if it still doesn't work try doing it like I said, just manually type it out.
Reply
#5

In case frename returns 0, it will not create a new file, write from the old file to new and delete the old.

You can return an error if that happens:
pawn Код:
format(name1, sizeof(name1), PLAYERS, PlayerName(playerid));
format(name2, sizeof(name2), PLAYERS, inputtext);
if (!frename(name1, name2)) return SendClientMessage(playerid, -1, "Could not be changed. Please try again later.");
SetPlayerName(playerid,inputtext);
Reply
#6

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
In case frename returns 0, it will not create a new file, write from the old file to new and delete the old.

You can return an error if that happens:
pawn Код:
format(name1, sizeof(name1), PLAYERS, PlayerName(playerid));
format(name2, sizeof(name2), PLAYERS, inputtext);
if (!frename(name1, name2)) return SendClientMessage(playerid, -1, "Could not be changed. Please try again later.");
SetPlayerName(playerid,inputtext);

I change the code as you sad
I says "Unable to change ...."
What should I do?
Reply
#7

Bump!
Please help!
Reply
#8

I dont now how to fix I tried but still the same
Reply
#9

If it fails to open the files most of the times, then you may need to read this: http://forum.sa-mp.com/showpost.php?...20&postcount=6
Reply
#10

Quote:

if(strlen(inputtext) < 4) return ShowPlayerDialog(playerid, CHANGE_NAME, DIALOG_STYLE_INPUT, "{AA3333}New Name", "Input your new name below\nName must be at least 4 lethers long!:", "Change", "Cancel");
if (dini_Exists(inputtext)) return SendClientMessage(playerid,COLOR_RED,"This User Name Is Taken!");
new name1[MAX_PLAYER_NAME],name2[MAX_PLAYER_NAME];
format(name1, sizeof(name1), PLAYERS, PlayerName(playerid));
format(name2, sizeof(name2), PLAYERS, strval(inputtext));
SetPlayerName(playerid,strval(inputtext));
frename(name1, name2);

You have to add STRVAL to SetPlayerName and format(name2..
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)