13.07.2011, 20:26
It just is not saving for ID 0 or that's what is appearing to happen. I think the whole thing is bugged to be honest as sometimes it saves and other times it doesn't. Can someone take a look I would appreciate it.
pawn Код:
#include <a_samp>
#include <dini>
#include <zcmd>
#include <sscanf2>
#define DIALOG_LOGIN 1
#define DIALOG_REGISTER 2
#define DEFAULT_SKIN 1
#define COLOR_INFO 0xDBCA00FF
forward SaveUser(playerid);
enum pInfo
{
Admin,
Money,
Skin,
Float: Health,
Float: Armour,
Float: Pos[4],
}
new PlayerInfo[MAX_PLAYERS][pInfo];
new
IsLogged[MAX_PLAYERS],
JustLogged[MAX_PLAYERS];
new
SaveTimer[MAX_PLAYERS];
new
Userfile[30];
new Float:SpawnPositions[][4] = {
{655.1382,865.7147,-34.0318,55.1471},
{637.3656,838.5986,-42.9609,62.3539}
};
main()
{
printf("...");
}
public OnGameModeInit()
{
AddPlayerClass(DEFAULT_SKIN, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
return 1;
}
public OnPlayerConnect(playerid)
{
ResetPlayerVariables(playerid);
if(CheckUser(playerid))
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Type in your password to login", "Login", "Quit");
}
else
{
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "Type in wanted password to register", "Register", "Quit");
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
KillTimer(SaveTimer[playerid]);
SaveUser(playerid);
return 1;
}
public OnPlayerSpawn(playerid)
{
if(JustLogged[playerid] == 1)
{
if(PlayerInfo[playerid][Pos][0] != 0)
{
SetPlayerPos(playerid, PlayerInfo[playerid][Pos][0], PlayerInfo[playerid][Pos][1], PlayerInfo[playerid][Pos][2]);
SetPlayerFacingAngle(playerid, PlayerInfo[playerid][Pos][3]);
}
else
{
new RandPos = random(sizeof(SpawnPositions));
SetPlayerPos(playerid, SpawnPositions[RandPos][0], SpawnPositions[RandPos][1], SpawnPositions[RandPos][2]);
SetPlayerFacingAngle(playerid, SpawnPositions[RandPos][3]);
}
JustLogged[playerid] = 0;
}
SetPlayerSkin(playerid, PlayerInfo[playerid][Skin]);
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case DIALOG_LOGIN:
{
if(!response)
{
SendClientMessage(playerid, COLOR_INFO, "Kick due to : Quitted login");
return Kick(playerid);
}
if(CheckUserLogin(playerid, inputtext))
{
return LoginUser(playerid);
}
else
{
SendClientMessage(playerid, COLOR_INFO, "Wrong password, please try again");
return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Type in your password to login", "Login", "Quit");
}
}
case DIALOG_REGISTER:
{
if(!response)
{
SendClientMessage(playerid, COLOR_INFO, "Kick due to : Quitted registering");
return Kick(playerid);
}
if(strlen(inputtext) >= 5 && strlen(inputtext) <= 20)
{
return CreateUser(playerid, inputtext);
}
else
{
SendClientMessage(playerid, COLOR_INFO, "Password has to containt between 5 - 20 characters.");
return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "Type in wanted password to register", "Register", "Quit");
}
}
}
return 1;
}
public SaveUser(playerid)
{
if(IsLogged[playerid] == 0) return 0;
GetPlayerHealth(playerid, PlayerInfo[playerid][Health]);
GetPlayerArmour(playerid, PlayerInfo[playerid][Armour]);
GetPlayerPos(playerid, PlayerInfo[playerid][Pos][0], PlayerInfo[playerid][Pos][1], PlayerInfo[playerid][Pos][2]);
GetPlayerFacingAngle(playerid, PlayerInfo[playerid][Pos][3]);
PlayerInfo[playerid][Money] = GetPlayerMoney(playerid);
PlayerInfo[playerid][Skin] = GetPlayerSkin(playerid);
dini_IntSet(Userfile, "Admin", PlayerInfo[playerid][Admin]);
dini_IntSet(Userfile, "Money", PlayerInfo[playerid][Money]);
dini_IntSet(Userfile, "Skin", PlayerInfo[playerid][Skin]);
if(PlayerInfo[playerid][Health] != 0) dini_FloatSet(Userfile, "Health", PlayerInfo[playerid][Health]);
if(PlayerInfo[playerid][Armour] != 0) dini_FloatSet(Userfile, "Armour", PlayerInfo[playerid][Armour]);
if(PlayerInfo[playerid][Pos][0] != 0) dini_FloatSet(Userfile, "X", PlayerInfo[playerid][Pos][0]);
if(PlayerInfo[playerid][Pos][1] != 0) dini_FloatSet(Userfile, "Y", PlayerInfo[playerid][Pos][1]);
if(PlayerInfo[playerid][Pos][2] != 0) dini_FloatSet(Userfile, "Z", PlayerInfo[playerid][Pos][2]);
if(PlayerInfo[playerid][Pos][3] != 0) dini_FloatSet(Userfile, "R", PlayerInfo[playerid][Pos][3]);
return 1;
}
// Stocks
stock LoginUser(playerid)
{
format(Userfile, sizeof(Userfile), "users/%s.ini", GetName(playerid));
IsLogged[playerid] = 1;
JustLogged[playerid] = 1;
PlayerInfo[playerid][Admin] = dini_Int(Userfile, "Admin");
PlayerInfo[playerid][Money] = dini_Int(Userfile, "Money");
PlayerInfo[playerid][Skin] = dini_Int(Userfile, "Skin");
PlayerInfo[playerid][Health] = dini_Float(Userfile, "Health");
PlayerInfo[playerid][Armour] = dini_Float(Userfile, "Armour");
PlayerInfo[playerid][Pos][0] = dini_Float(Userfile, "X");
PlayerInfo[playerid][Pos][1] = dini_Float(Userfile, "Y");
PlayerInfo[playerid][Pos][2] = dini_Float(Userfile, "Z");
PlayerInfo[playerid][Pos][3] = dini_Float(Userfile, "R");
GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);
// Timers
SaveTimer[playerid] = SetTimerEx("SaveUser", 60 * 1000 * 5, true, "i", playerid);
return SendClientMessage(playerid, COLOR_INFO, "Logged in.");
}
stock CreateUser(playerid, TempPW[])
{
format(Userfile, sizeof(Userfile), "users/%s.ini", GetName(playerid));
dini_Create(Userfile);
dini_Set(Userfile, "Password", TempPW);
dini_IntSet(Userfile, "Admin", 0);
dini_IntSet(Userfile, "Money", 0);
dini_IntSet(Userfile, "Skin", DEFAULT_SKIN);
dini_FloatSet(Userfile, "Health", 0);
dini_FloatSet(Userfile, "Armour", 0);
dini_FloatSet(Userfile, "X", 0);
dini_FloatSet(Userfile, "Y", 0);
dini_FloatSet(Userfile, "Z", 0);
dini_FloatSet(Userfile, "R", 0);
SendClientMessage(playerid, COLOR_INFO, "You will be automatically logged in.");
return LoginUser(playerid);
}
stock CheckUserLogin(playerid, TempPW[])
{
format(Userfile, sizeof(Userfile), "users/%s.ini", GetName(playerid));
if(strmatch(TempPW, dini_Get(Userfile, "Password"))) return 1;
return 0;
}
stock CheckUser(playerid)
{
format(Userfile, sizeof(Userfile), "users/%s.ini", GetName(playerid));
if(fexist(Userfile)) return 1;
return 0;
}
stock ResetPlayerVariables(playerid)
{
IsLogged[playerid] = 0;
PlayerInfo[playerid][Admin] = 0;
PlayerInfo[playerid][Money] = 0;
}
stock GetName(playerid)
{
new pName[25];
GetPlayerName(playerid, pName, 25);
return pName;
}
stock GetPlayerAdmin(playerid)
{
return PlayerInfo[playerid][Admin];
}
stock strmatch(const String1[], const String2[])
{
if ((strcmp(String1, String2, true, strlen(String2)) == 0) && (strlen(String2) == strlen(String1)))
{
return true;
}
else
{
return false;
}
}