16.08.2010, 21:54
Well, with the arrival of 0.3b, something is terribly wrong with djson. I don't know if it's because it's not compatible or i'm just coding it wrong.. but here's my code, and a video of what happens:
[ame]http://www.youtube.com/watch?v=xVhJqR5I5vg[/ame]
[ame]http://www.youtube.com/watch?v=xVhJqR5I5vg[/ame]
pawn Код:
COMMAND:register(playerid, params[])
{
new pass[64],string[64];
if(!sscanf(params, "s", pass))
{
new PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
format(string, sizeof(string), "TDM/userfiles/%s.json", PlayerName);
if(!djIsSet(string,"Key"))
{
format(string, sizeof(string), "INFO: You have registered using the password '%s'", pass);
SendClientMessage(playerid, sc_Lime, string);
OnPlayerRegistration(playerid,pass);
}
else return SendClientMessage(playerid, sc_LightRed, "ERROR: This account already exists.");
}
else return SendClientMessage(playerid, sc_White, "COMMAND: /register [password]");
return 1;
}
COMMAND:login(playerid, params[])
{
new pass[64],string[64];
if(!sscanf(params, "s", pass))
{
new PlayerName[MAX_PLAYER_NAME];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
format(string, sizeof(string), "TDM/userfiles/%s.json", PlayerName);
if(djIsSet(string,"Key"))
{
if(playerLogged[playerid] == 1) return SendClientMessage(playerid, sc_LightRed, "ERROR: You are already logged in.");
OnPlayerAuthorization(playerid,pass);
}
else return SendClientMessage(playerid, sc_LightRed, "ERROR: This account does not exist.");
}
else return SendClientMessage(playerid, sc_White, "COMMAND: /login [password]");
return 1;
}
public ThreeSecondTimer()
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(playerLogged[i]==1)
{
playerStats[i][MoneyOnHand] = GetPlayerMoney(i);
new string[50], CharName[MAX_PLAYER_NAME];
GetPlayerName(i, CharName, sizeof(CharName));
format(string, sizeof(string), "TDM/userfiles/%s.json", CharName);
djSetInt(string,"IsRegistered", playerStats[i][IsRegistered]);
djSetInt(string,"Administrator",playerStats[i][Administrator]);
djSetInt(string,"Kills", playerStats[i][Kills]);
djSetInt(string,"Deaths", playerStats[i][Deaths]);
djSetInt(string,"Skin", playerStats[i][Skin]);
djSetInt(string,"WantedLevel", playerStats[i][WantedLevel]);
djSetInt(string,"TimeOnline", playerStats[i][TimeOnline]);
djSetInt(string,"MoneyOnHand", playerStats[i][MoneyOnHand]);
djSetInt(string,"MoneyInBank", playerStats[i][MoneyInBank]);
djCommit(string);
}
}
}
}
public OnPlayerAuthorization(playerid,password[])
{
new string[80], CharName[MAX_PLAYER_NAME];
GetPlayerName(playerid, CharName, sizeof(CharName));
format(string, sizeof(string), "TDM/userfiles/%s.json", CharName);
if(strcmp(dj(string,"Key"),password, true ) == 0 )
{
playerStats[playerid][IsRegistered]= djInt(string,"IsRegistered");
playerStats[playerid][Administrator]= djInt(string,"Administrator");
playerStats[playerid][Skin]= djInt(string,"Skin");
playerStats[playerid][WantedLevel]= djInt(string,"WantedLevel");
playerStats[playerid][TimeOnline]= djInt(string,"TimeOnline");
playerStats[playerid][MoneyInBank]= djInt(string,"MoneyInBank");
playerStats[playerid][MoneyOnHand]= djInt(string,"MoneyOnHand");
}
else { GameTextForPlayer(playerid, "~w~Authentication~n~~r~rejected", 3000, 1); return 1; }
if(playerStats[playerid][IsRegistered] == 0)
{
playerStats[playerid][Kills]= 0;
playerStats[playerid][Deaths]= 0;
playerStats[playerid][MoneyOnHand]= 250;
playerStats[playerid][MoneyInBank]= 500;
playerStats[playerid][IsRegistered]= 1;
playerStats[playerid][Administrator]= 0;
playerStats[playerid][WantedLevel]= 0;
playerStats[playerid][TimeOnline]= 0;
}
playerLogged[playerid] = 1;
format(string, sizeof(string), "%s has logged in.", ReturnPlayerName(playerid));
printf(string);
SetSpawnInfo(playerid, 0, playerStats[playerid][Skin], 1, 1, 1, 0, 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
TogglePlayerControllable(playerid, 1);
SetPlayerSkin(playerid, playerStats[playerid][Skin]);
SetCameraBehindPlayer(playerid);
SetPlayerWantedLevel(playerid, playerStats[playerid][WantedLevel]);
return 1;
}
public OnPlayerRegistration(playerid, password[])
{
new string[50], CharName[MAX_PLAYER_NAME];
GetPlayerName(playerid, CharName, sizeof(CharName));
format(string, sizeof(string), "TDM/userfiles/%s.json", CharName);
djCreateFile(string);
djSet(string,"Key",password);
djSetInt(string,"IsRegistered", playerStats[playerid][IsRegistered]);
djSetInt(string,"Administrator", playerStats[playerid][Administrator]);
djSetInt(string,"Skin", playerStats[playerid][Skin]);
djSetInt(string,"WantedLevel", playerStats[playerid][WantedLevel]);
djSetInt(string,"TimeOnline", playerStats[playerid][TimeOnline]);
djSetInt(string,"MoneyInBank", playerStats[playerid][MoneyInBank]);
djSetInt(string,"Money", playerStats[playerid][MoneyOnHand]);
djCommit(string);
OnPlayerAuthorization(playerid,password);
return 1;
}