djSet("accounts.json", str, value);
Well I've never personally used this library. Although I took a quick look at the release topic and an example that was provided in that topic, it would appear to be quite easy. Can you give me any information on how your script is setup? Where are your account files, how are they set up and so on....
It's impossible to provide help without such information, as there are so many dynamic possibilities to what you could've done. Looking at the example, I can tell you that a probable function you need is this: pawn Код:
There's a lovely Wiki for the library here. |
I've tried it myself on multiple occasions, and have always ended up in failure. I tend to get quite discouraged when this happens, although i'm exactly sure why, haha. Well, here's some information about my account system.
Files are saved under "PFiles/%s.json" - %s being their username. I will definately take a look at that library you provided, however; Thank you very much. |
A simple note is that is not how djSon was intended to be used, it was actually intended to be used to have all of the players information stored in a single file.
Regardless, it's quite easy to change the name of that file then, all you need is to re-name the file. Unfortunately there is no file re-naming function that comes with the SA-MP package, although there are plenty of PAWN implementations available around. Read this great page I found for more information: http://dracoblue.net/dev/renaming-a-file-in-pawn/139/ |
CMD:rename(playerid, params[])
{
if(PVar[playerid][pLevel] >= 4)
{
new Player, newname[MAX_PLAYER_NAME], string[128], File[50];
if(!sscanf(params, "us[MAX_PLAYER_NAME]", Player, newname))
{
format(string, sizeof(string), "%s.json", newname);
djCreateFile(string);
format(File, sizeof(File), PFiles, newname);
PVar[playerid][pKills] = djInt (File, "Kills");
PVar[playerid][pDeaths] = djInt (File, "Deaths");
PVar[playerid][pLevel] = djInt (File, "Level");
PVar[playerid][pMuted] = djInt (File, "Muted");
PVar[playerid][pCash] = djInt (File, "Cash");
PVar[playerid][pSkin] = djInt (File, "Skin");
PVar[playerid][pUseSkin] = djInt (File, "UseSkin");
format(PVar[playerid][pMutedReason], 52, "%s", dj(File, "MutedReason"));
format(string, sizeof(string), "%s.json", pName(playerid));
djRemoveFile(string);
SetPlayerName(playerid, newname);
}
}
return 1;
}
Well that's quite simply because you're not setting them in the new file at all, all you are doing is getting the information from the new file using djInt, which contains no information yet!
You should be using djSetInt to set the information in the new file! |
CMD:rename(playerid, params[])
{
if(PVar[playerid][pLevel] >= 4)
{
new Player, newname[32], string[128], File[85];
if(!sscanf(params, "us[32]", Player, newname))
{
format(File, sizeof(File), PFiles, newname);
if(!fexist(File))
{
format(File, sizeof(File), PFiles, pName(playerid));
PVar[playerid][pKills] = djInt (File, "Kills");
PVar[playerid][pDeaths] = djInt (File, "Deaths");
PVar[playerid][pLevel] = djInt (File, "Level");
PVar[playerid][pMuted] = djInt (File, "Muted");
PVar[playerid][pCash] = djInt (File, "Cash");
PVar[playerid][pSkin] = djInt (File, "Skin");
PVar[playerid][pUseSkin] = djInt (File, "UseSkin");
format(PVar[playerid][pMutedReason], 52, "%s", dj(File, "MutedReason"));
format(string, sizeof(string), "%s.json", newname);
djCreateFile(string);
format(File, sizeof(File), PFiles, newname);
djSetInt (File, "Kills", PVar[playerid][pKills]);
djSetInt (File, "Deaths", PVar[playerid][pDeaths]);
djSetInt (File, "Level", PVar[playerid][pLevel]);
djSetInt (File, "Cash", PVar[playerid][pCash]);
djSetInt (File, "Muted", PVar[playerid][pMuted]);
djSetInt (File, "Skin", PVar[playerid][pSkin]);
djSetInt (File, "UseSkin", PVar[playerid][pUseSkin]);
djSet (File, "MutedReason", PVar[playerid][pMutedReason]);
format(string, sizeof(string), "%s.json", pName(playerid));
djRemoveFile(string);
SetPlayerName(playerid, newname);
}
else return SendClientMessage(playerid, COLOR_RED, "File already exists!");
}
else return SendClientMessage(playerid, COLOR_LIGHTBLUE, "Usage: /rename < Player ID > < New Name >");
}
else return AdminCMD(playerid, 4);
return 1;
}
CMD:rename(playerid, params[])
{
if(PVar[playerid][pLevel] >= 4)
{
new Player, newname[32], string[128], File[85];
if(!sscanf(params, "us[32]", Player, newname))
{
format(File, sizeof(File), PFiles, newname);
if(!fexist(File))
{
format(File, sizeof(File), PFiles, pName(playerid));
PVar[playerid][pKills] = djInt (File, "Kills");
PVar[playerid][pDeaths] = djInt (File, "Deaths");
PVar[playerid][pLevel] = djInt (File, "Level");
PVar[playerid][pMuted] = djInt (File, "Muted");
PVar[playerid][pCash] = djInt (File, "Cash");
PVar[playerid][pSkin] = djInt (File, "Skin");
PVar[playerid][pUseSkin] = djInt (File, "UseSkin");
format(PVar[playerid][pMutedReason], 52, "%s", dj(File, "MutedReason"));
format(string, sizeof(string), "%s.json", newname);
djCreateFile(string);
format(File, sizeof(File), PFiles, newname);
printf("File: %s", File);
djSetInt (File, "Kills", PVar[playerid][pKills]);
djSetInt (File, "Deaths", PVar[playerid][pDeaths]);
djSetInt (File, "Level", PVar[playerid][pLevel]);
djSetInt (File, "Cash", PVar[playerid][pCash]);
djSetInt (File, "Muted", PVar[playerid][pMuted]);
djSetInt (File, "Skin", PVar[playerid][pSkin]);
djSetInt (File, "UseSkin", PVar[playerid][pUseSkin]);
djSet (File, "MutedReason", PVar[playerid][pMutedReason]);
format(string, sizeof(string), "%s.json", pName(playerid));
djRemoveFile(string);
SetPlayerName(playerid, newname);
}
else return SendClientMessage(playerid, COLOR_RED, "File already exists!");
}
else return SendClientMessage(playerid, COLOR_LIGHTBLUE, "Usage: /rename < Player ID > < New Name >");
}
else return AdminCMD(playerid, 4);
return 1;
}
Try to do some simple debugging.
pawn Код:
|
[19:35:05] K: 0, D: 0, Level: 5, Money: $0 [before] [19:35:05] File: PFiles/Sky7.json [19:35:05] K: 0, D: 0, Level: 5, Money: $0 [after] [19:35:05] [nick] Sky6 nick changed to Sky7 |