Score and Money Save! Help! -
Kasis - 09.02.2011
Well i can't figure out how to save score and money!! Can somebody help me!
Here will be code:
Код:
public OnPlayerConnect(playerid)
{
Login[playerid] = 0;
new name[MAX_PLAYER_NAME], archive[256];
GetPlayerName(playerid, name, sizeof(name));
format(archive, sizeof(archive), "/Users/%s.ini", name);
if (!dini_Exists(archive))
{
ShowPlayerDialog(playerid, Register, DIALOG_STYLE_INPUT, "Register", "Enter your password please:", "Accept", "Cancel");
}
else
{
ShowPlayerDialog(playerid, Logged, DIALOG_STYLE_INPUT, "Login", "Enter your password please:", "Accept", "Cancel");
}
return 1;
}
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if (dialogid == Register)
{
new name[MAX_PLAYER_NAME], archive[256];
if (!strlen(inputtext)) return ShowPlayerDialog(playerid, Register, DIALOG_STYLE_INPUT, "Register", "Enter your password please", "Accept", "Cancel");
if (!response) return ShowPlayerDialog(playerid, Register, DIALOG_STYLE_INPUT, "Register", "Enter your password please:", "Accept", "Cancel");
GetPlayerName(playerid, name, sizeof(name));
format(archive, sizeof(archive), "/Users/%s.ini", name);
dini_Create(archive);
dini_Set(archive, "User", name);
dini_Set(archive, "Password", inputtext);
ShowPlayerDialog(playerid, Logged, DIALOG_STYLE_INPUT, "Login", "Enter your password please", "Accept", "Cancel");
}
if (dialogid == Logged)
{
new name[MAX_PLAYER_NAME], archive[256], proof[256];
if (!strlen(inputtext)) return ShowPlayerDialog(playerid, Logged, DIALOG_STYLE_INPUT, "Login", "Enter your password please", "Accept", "Cancel");
if (!response) return ShowPlayerDialog(playerid, Logged, DIALOG_STYLE_INPUT, "Login", "Enter your password please", "Accept", "Cancel");
GetPlayerName(playerid, name, sizeof(name));
format(archive, sizeof(archive), "/Users/%s.ini", name);
format(proof, sizeof(proof), "%s", dini_Get(archive, "Password"));
if (!strcmp (inputtext, proof))
{
}
else
{
ShowPlayerDialog(playerid, Logged, DIALOG_STYLE_INPUT, "Login", "Enter your password please", "Accept", "Cancel");
}
}
return 1;
}
Re: Score and Money Save! Help! -
HyperZ - 09.02.2011
pawn Код:
enum pInfo
{
pCash,
pScore
}
new PlayerInfo[MAX_PLAYERS][pInfo];
new gPlayerLogged[MAX_PLAYERS];
public OnPlayerDisconnect(playerid, reason)
{
new name[MAX_PLAYER_NAME], file[256];
GetPlayerName(playerid, name, sizeof(name));
format(file, sizeof(file), "/Users/%s.ini", name);
if(gPlayerLogged[playerid] == 1)
{
dini_IntSet(file, "Score", PlayerInfo[playerid][pScore]);
dini_IntSet(file, "Money", PlayerInfo[playerid][pCash]);
}
gPlayerLogged[playerid] = 0;
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if (dialogid == Register)
{
new name[MAX_PLAYER_NAME], archive[256];
if (!strlen(inputtext)) return ShowPlayerDialog(playerid, Register, DIALOG_STYLE_INPUT, "Register", "Enter your password please", "Accept", "Cancel");
if (!response) return ShowPlayerDialog(playerid, Register, DIALOG_STYLE_INPUT, "Register", "Enter your password please:", "Accept", "Cancel");
GetPlayerName(playerid, name, sizeof(name));
format(archive, sizeof(archive), "/Users/%s.ini", name);
dini_Create(archive);
dini_Set(archive, "User", name);
dini_Set(archive, "Password", inputtext);
dini_IntSet(archive, "Money",PlayerInfo[playerid][pCash] = 500);
dini_IntSet(archive, "Score",PlayerInfo[playerid][pScore] = 0);
ShowPlayerDialog(playerid, Logged, DIALOG_STYLE_INPUT, "Login", "Enter your password please", "Accept", "Cancel");
gPlayerLogged[playerid] = 1;
}
if (dialogid == Logged)
{
new name[MAX_PLAYER_NAME], archive[256], proof[256];
if (!strlen(inputtext)) return ShowPlayerDialog(playerid, Logged, DIALOG_STYLE_INPUT, "Login", "Enter your password please", "Accept", "Cancel");
if (!response) return ShowPlayerDialog(playerid, Logged, DIALOG_STYLE_INPUT, "Login", "Enter your password please", "Accept", "Cancel");
GetPlayerName(playerid, name, sizeof(name));
format(archive, sizeof(archive), "/Users/%s.ini", name);
format(proof, sizeof(proof), "%s", dini_Get(archive, "Password"));
if (!strcmp (inputtext, proof))
{
ShowPlayerDialog(playerid, Logged, DIALOG_STYLE_INPUT, "Login", "Enter your password please", "Accept", "Cancel");
}
else
{
gPlayerLogged[playerid] = 1;
SetPlayerScore(playerid, dini_Int(archive, "pScore"));
GivePlayerMoney(playerid, dini_Int(archive, "Money")-GetPlayerMoney(playerid));
}
}
return 1;
}
Edit: not tested.