Problem with data saving.
#1

Hi there. I`ve got a little confusing and annoying trouble with saving player data when they /q or crash.

I have under OnPlayerDisconnect this :

Code:
public OnPlayerDisconnect(playerid, reason)
{
   new Float:x, Float:y, Float:z, Float:rot;
   GetPlayerPos(playerid, Float:x, Float:y, Float:z);
   GetPlayerFacingAngle(playerid, Float:rot);
   SetPVarFloat(playerid, "Money", GetPlayerMoney(playerid));
   if(reason == 0)
   {
      SetPVarFloat(playerid, "loc_X", Float:x);
      SetPVarFloat(playerid, "loc_Y", Float:y);
      SetPVarFloat(playerid, "loc_Z", Float:z);
      SetPVarFloat(playerid, "loc_angle", Float:rot);
      return 1;
   }
   else
   {
       if(GetPVarInt(playerid, "last_pos_spawn" )== 1)
       {
         SetPVarFloat(playerid, "loc_X", Float:x);
         SetPVarFloat(playerid, "loc_Y", Float:y);
         SetPVarFloat(playerid, "loc_Z", Float:z);
         SetPVarFloat(playerid, "loc_angle", Float:rot);
         return 1;
      }
      else if(GetPVarInt(playerid, "has_rented_h") == 0)
      {
         SetPVarFloat(playerid, "loc_X", Float:x);
         SetPVarFloat(playerid, "loc_Y", Float:y);
         SetPVarFloat(playerid, "loc_Z", Float:z);
         SetPVarFloat(playerid, "loc_angle", Float:rot);
         return 1;
      }
   }
   // save data - !!!!! MUST BE LAST ONE !!!!!
   SavePlayerData(playerid);
   return 1;
}
And a forwarded function SavePlayerData(playerid) :

Code:
public SavePlayerData(playerid)
{
   new pName[MAX_PLAYER_NAME], file[128], inventory[128];
   GetPlayerName(playerid, pName, sizeof(pName));
   format(file, sizeof(file), "/Accounts/%s.ini", pName);
   format(inventory, sizeof(inventory), "/Accounts/%s_inv.ini", pName);
   // stats
   dini_IntSet(file, "XP", GetPVarInt(playerid, "XP"));
   dini_FloatSet(file, "Money", GetPVarFloat(playerid, "Money"));
   dini_FloatSet(file, "BankAcc", GetPVarFloat(playerid, "BankAcc"));
   dini_IntSet(file, "Level", GetPVarInt(playerid, "Level"));
   dini_IntSet(file, "AdminLevel", GetPVarInt(playerid, "AdminLevel"));
   dini_Set(file, "Name", pName);
   // password doesn`t save!
   dini_FloatSet(file, "loc_X", GetPVarFloat(playerid, "loc_X"));
   dini_FloatSet(file, "loc_Y", GetPVarFloat(playerid, "loc_Y"));
   dini_FloatSet(file, "loc_Z", GetPVarFloat(playerid, "loc_Z"));
   dini_FloatSet(file, "loc_angle", GetPVarFloat(playerid, "loc_angle"));
   dini_IntSet(file, "ooc_status", GetPVarInt(playerid, "ooc_status"));
   dini_IntSet(file, "pm_status", GetPVarInt(playerid, "pm_status"));
   dini_IntSet(file, "Phone_#", GetPVarInt(playerid, "Phone_#"));
   dini_IntSet(file, "Phone_Credit", GetPVarInt(playerid, "Phone_Credit"));
   dini_IntSet(file, "has_rented_h", GetPVarInt(playerid, "has_rented_h"));
   dini_IntSet(file, "last_pos_spawn", GetPVarInt(playerid, "last_pos_spawn"));
            // inventory
   GetPVarString(playerid, "item_1", InvItem1, sizeof(InvItem1));
   GetPVarString(playerid, "item_2", InvItem2, sizeof(InvItem2));
   GetPVarString(playerid, "item_3", InvItem3, sizeof(InvItem3));
   GetPVarString(playerid, "item_4", InvItem4, sizeof(InvItem4));
   GetPVarString(playerid, "item_5", InvItem5, sizeof(InvItem5));
   GetPVarString(playerid, "item_6", InvItem6, sizeof(InvItem6));
   GetPVarString(playerid, "item_7", InvItem7, sizeof(InvItem7));
   GetPVarString(playerid, "item_8", InvItem8, sizeof(InvItem8));
   GetPVarString(playerid, "item_9", InvItem9, sizeof(InvItem9));
   GetPVarString(playerid, "item_10", InvItem10, sizeof(InvItem10));
   dini_Set(inventory, "item_1", InvItem1);
   dini_Set(inventory, "item_2", InvItem2);
   dini_Set(inventory, "item_3", InvItem3);
   dini_Set(inventory, "item_4", InvItem4);
   dini_Set(inventory, "item_5", InvItem5);
   dini_Set(inventory, "item_6", InvItem6);
   dini_Set(inventory, "item_7", InvItem7);
   dini_Set(inventory, "item_8", InvItem8);
   dini_Set(inventory, "item_9", InvItem9);
   dini_Set(inventory, "item_10", InvItem10);
   return 1;
}
By any means I can`t make this thing work ... so I`ve gotta ask for your help guys. Maybe you`re much luckier than me.
Reply
#2

Code:
delete the function return 1; 

public OnPlayerDisconnect(playerid, reason)
{
   new Float:x, Float:y, Float:z, Float:rot;
   GetPlayerPos(playerid, Float:x, Float:y, Float:z);
   GetPlayerFacingAngle(playerid, Float:rot);
   SetPVarFloat(playerid, "Money", GetPlayerMoney(playerid));
   if(reason == 0)
   {
      SetPVarFloat(playerid, "loc_X", Float:x);
      SetPVarFloat(playerid, "loc_Y", Float:y);
      SetPVarFloat(playerid, "loc_Z", Float:z);
      SetPVarFloat(playerid, "loc_angle", Float:rot);
//      return 1;
   }
   else
   {
       if(GetPVarInt(playerid, "last_pos_spawn" )== 1)
       {
         SetPVarFloat(playerid, "loc_X", Float:x);
         SetPVarFloat(playerid, "loc_Y", Float:y);
         SetPVarFloat(playerid, "loc_Z", Float:z);
         SetPVarFloat(playerid, "loc_angle", Float:rot);
//         return 1;
      }
      else if(GetPVarInt(playerid, "has_rented_h") == 0)
      {
         SetPVarFloat(playerid, "loc_X", Float:x);
         SetPVarFloat(playerid, "loc_Y", Float:y);
         SetPVarFloat(playerid, "loc_Z", Float:z);
         SetPVarFloat(playerid, "loc_angle", Float:rot);
//         return 1;
      }
   }
   // save data - !!!!! MUST BE LAST ONE !!!!!
   SavePlayerData(playerid);
   return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)