PDA

View Full Version : [Account Help]Saving Issues


SantarioLeone
12/10/2011, 02:01 AM
My account system is using Y_INI
I wanted each player to start off with 10,000$. But its not saving, nor is the skin, i hve searched but to no avail i havent found a fix, or anything that has helped me. If someone can direct me to where i can get this fixed, or tell me or explain to me how to fix it here it would be very appreciated.

Register Dialog
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch( dialogid )
{
case DIALOG_REGISTER:
{
if (!response) return Kick(playerid);
if(response)
{
if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Password",udb_hash(inputtext));
INI_WriteInt(File,"Level",1);
INI_WriteInt(File,"Cash",GivePlayerMoney(playerid, 10000));
INI_WriteInt(File,"Sex",0);
INI_WriteInt(File,"Age",0);
INI_WriteInt(File,"Skin",0);
INI_WriteInt(File,"Leader",0);
INI_WriteInt(File,"Rank",0);
INI_WriteInt(File,"Team",0);
INI_WriteInt(File,"Member",0);
INI_WriteInt(File,"Admin",0);
INI_WriteInt(File,"VIP",0);
INI_WriteInt(File,"Muted",0);
INI_WriteInt(File,"Tutorial",0);
INI_WriteInt(File,"Mute Time",0);
INI_WriteInt(File,"Banned",0);
INI_WriteInt(File,"Kills",0);
INI_WriteInt(File,"Deaths",0);
INI_Close(File);
new sex[] = " Male \n Female ";
ShowPlayerDialog(playerid, DIALOG_SEX, DIALOG_STYLE_LIST, "Please selecet your Gender", sex, "Select","Quit Game");
}
}


OnPlayerDisconnect
public OnPlayerDisconnect(playerid, reason)
{
GetPlayerMoney(playerid);
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Level",PlayerInfo[playerid][pLevel]);
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Sex",PlayerInfo[playerid][pSex]);
INI_WriteInt(File,"Age",PlayerInfo[playerid][pAge]);
INI_WriteInt(File,"Skin",PlayerInfo[playerid][pSkin]);
INI_WriteInt(File,"Leader",PlayerInfo[playerid][pLeader]);
INI_WriteInt(File,"Rank",PlayerInfo[playerid][pRank]);
INI_WriteInt(File,"Team",PlayerInfo[playerid][pTeam]);
INI_WriteInt(File,"Member",PlayerInfo[playerid][pMember]);
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
INI_WriteInt(File,"Vip",PlayerInfo[playerid][pVip]);
INI_WriteInt(File,"Muted",PlayerInfo[playerid][pMuted]);
INI_WriteInt(File,"Tutorial",PlayerInfo[playerid][pTut]);
INI_WriteInt(File,"Mute Time",PlayerInfo[playerid][pMuteTime]);
INI_WriteInt(File,"Banned",PlayerInfo[playerid][pLocked]);
INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
INI_Close(File);
return 1;
}

SaveUserData
public SaveUserData(playerid)
{
new PlayerName[MAX_PLAYERS];
GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Level",PlayerInfo[playerid][pLevel]);
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Sex",PlayerInfo[playerid][pSex]);
INI_WriteInt(File,"Age",PlayerInfo[playerid][pAge]);
INI_WriteInt(File,"Skin",PlayerInfo[playerid][pSkin]);
INI_WriteInt(File,"Leader",PlayerInfo[playerid][pLeader]);
INI_WriteInt(File,"Rank",PlayerInfo[playerid][pRank]);
INI_WriteInt(File,"Team",PlayerInfo[playerid][pTeam]);
INI_WriteInt(File,"Member",PlayerInfo[playerid][pMember]);
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
INI_WriteInt(File,"Vip",PlayerInfo[playerid][pVip]);
INI_WriteInt(File,"Muted",PlayerInfo[playerid][pMuted]);
INI_WriteInt(File,"Tutorial",PlayerInfo[playerid][pTut]);
INI_WriteInt(File,"Mute Time",PlayerInfo[playerid][pMuteTime]);
INI_WriteInt(File,"Banned",PlayerInfo[playerid][pLocked]);
INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
INI_Close(File);
printf("[userdata] Player Data of %s has been saved.", PlayerName);
return 1;
}

[HiC]TheKiller
12/10/2011, 02:07 AM
INI_WriteInt(File,"Cash",GivePlayerMoney(playerid, 10000));

Lolwat? That should just be

INI_WriteInt(File, "Cash", 10000);
GivePlayerMoney(playerid, 10000);


Because GivePlayerMoney doesn't return the $$ given as far as I know. For the skin issue, make sure that there is actually a value on PlayerInfo[playerid][pSkin] or just use GetPlayerSkin.

Kush
12/10/2011, 02:22 AM
So you write the data upon disconnect, what's the point of the SaveUserData function?


OnPlayerDisconnect(playerid, reason) { SaveUserData(playerid); };



OnPlayerSpawn(playerid) { GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]); SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]); }


Use OnPlayerSpawn as a debugging method, and try creating a seperate function to be called once the player is actually logged in.

SantarioLeone
12/10/2011, 02:39 AM
So you write the data upon disconnect, what's the point of the SaveUserData function?


OnPlayerDisconnect(playerid, reason) { SaveUserData(playerid); };



OnPlayerSpawn(playerid) { GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]); SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]); }


Use OnPlayerSpawn as a debugging method, and try creating a seperate function to be called once the player is actually logged in.

The SaveUserData is used when i use /GMX to save stats prior to the restart. But that hasnt seemed to be working, still got alot of stuff to work out, which is hard doing majority myself, other than coming to the forum asking for help sometimes.

Kush
12/10/2011, 02:52 AM
The SaveUserData is used when i use /GMX to save stats prior to the restart. But that hasnt seemed to be working, still got alot of stuff to work out, which is hard doing majority myself, other than coming to the forum asking for help sometimes.


public SaveUserData(playerid)
{
new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteInt(File,"Level",PlayerInfo[playerid][pLevel]);
INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
INI_WriteInt(File,"Sex",PlayerInfo[playerid][pSex]);
INI_WriteInt(File,"Age",PlayerInfo[playerid][pAge]);
INI_WriteInt(File,"Skin",GetPlayerSkin(playerid));
INI_WriteInt(File,"Leader",PlayerInfo[playerid][pLeader]);
INI_WriteInt(File,"Rank",PlayerInfo[playerid][pRank]);
INI_WriteInt(File,"Team",PlayerInfo[playerid][pTeam]);
INI_WriteInt(File,"Member",PlayerInfo[playerid][pMember]);
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
INI_WriteInt(File,"Vip",PlayerInfo[playerid][pVip]);
INI_WriteInt(File,"Muted",PlayerInfo[playerid][pMuted]);
INI_WriteInt(File,"Tutorial",PlayerInfo[playerid][pTut]);
INI_WriteInt(File,"Mute Time",PlayerInfo[playerid][pMuteTime]);
INI_WriteInt(File,"Banned",PlayerInfo[playerid][pLocked]);
INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
INI_Close(File);
return 1;
}


This is the function which writes the information. Your job, is to apply/insert that function into whatever callback you desire. So since I'm assuming your wanting this to be called when a player disconnects, you would place that function under OnPlayerDisconnect. You would also place that function, in your command.

SantarioLeone
12/10/2011, 05:59 PM
CMD:gmx(playerid, params[])
{
SaveUserData(playerid);
SetTimer("Gmx",3000,false);
SendRconCommand("gmx");
return 1;
}

I have that function already in my GMX command but it still fails to work correctly, what i mean by that is it still wont save the players data, cause when the server restarts everyones skin is 0. and cash 0