SA-MP Forums Archive
Help me with saving system please - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Help me with saving system please (/showthread.php?tid=311187)



Help me with saving system please - ryansheilds - 15.01.2012

Okay, the problem is when you receive money in game it doesn't always save, and when it does save - say you get 1299$ the next time you would login you'd have 1300 (It rounds it to the nearest hundred), And the same problem for on saving position - Sometimes it saves your position and sometimes you spawn at the start. (There are not errors)
Here is my saving (on player register)
pawn Код:
if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registering...","You have entered an invalid password.\nType 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,"Cash",0);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Level",0);
                INI_WriteInt(File,"Experience",0);
                INI_WriteInt(File,"Sex",0);
                INI_WriteInt(File,"Age",0);
                INI_WriteInt(File,"Job",0);
                INI_WriteFloat(File,"Pos_x",0);
                INI_WriteFloat(File,"Pos_y",0);
                INI_WriteFloat(File,"Pos_z",0);
                INI_WriteInt(File,"Skin",0);
                INI_WriteInt(File,"Team",0);
                INI_WriteInt(File,"Accent",0);
                INI_WriteInt(File,"pGun1",0);
                INI_WriteInt(File,"pGun2",0);
                INI_WriteInt(File,"pGun3",0);
                INI_WriteInt(File,"pGun4",0);
                INI_WriteInt(File,"pGun5",0);
                INI_WriteInt(File,"pGun6",0);
                INI_WriteInt(File,"pGun7",0);
                INI_WriteInt(File,"pGun8",0);
                INI_WriteInt(File,"pGun9",0);
                INI_WriteInt(File,"pGun10",0);
                INI_WriteInt(File,"pGun11",0);
                INI_WriteInt(File,"pGun12",0);
                INI_WriteInt(File,"pGPS",1);
                INI_WriteInt(File,"pDeposit",0);
                INI_WriteInt(File,"pMaterials",0);
                INI_WriteInt(File,"pPackages",0);
                INI_WriteInt(File,"pCocaine",0);
                INI_Close(File);
On player connect and login:
pawn Код:
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
And finally the load user function:
pawn Код:
function LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPass]);
    INI_Int("Cash",PlayerInfo[playerid][pCash]);
    INI_Int("Level",PlayerInfo[playerid][pLevel]);
    INI_Int("Experience",PlayerInfo[playerid][pExp]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    INI_Int("Sex",PlayerInfo[playerid][pSex]);
    INI_Int("Age",PlayerInfo[playerid][pAge]);
    INI_Float("Pos_x",PlayerInfo[playerid][pPos_x]);
    INI_Float("Pos_y",PlayerInfo[playerid][pPos_y]);
    INI_Float("Pos_z",PlayerInfo[playerid][pPos_z]);
    INI_Int("Skin",PlayerInfo[playerid][pSkin]);
    INI_Int("Team",PlayerInfo[playerid][pTeam]);
    INI_Int("Accent",PlayerInfo[playerid][pAccent]);
    INI_Int("Job",PlayerInfo[playerid][pJobID]);
    INI_Int("Gun1",PlayerInfo[playerid][pGun1]);
    INI_Int("Gun2",PlayerInfo[playerid][pGun2]);
    INI_Int("Gun3",PlayerInfo[playerid][pGun3]);
    INI_Int("Gun4",PlayerInfo[playerid][pGun4]);
    INI_Int("Gun5",PlayerInfo[playerid][pGun5]);
    INI_Int("Gun6",PlayerInfo[playerid][pGun6]);
    INI_Int("Gun7",PlayerInfo[playerid][pGun7]);
    INI_Int("Gun8",PlayerInfo[playerid][pGun8]);
    INI_Int("Gun9",PlayerInfo[playerid][pGun9]);
    INI_Int("Gun10",PlayerInfo[playerid][pGun10]);
    INI_Int("Gun11",PlayerInfo[playerid][pGun11]);
    INI_Int("Gun12",PlayerInfo[playerid][pGun12]);
    INI_Int("GPS",PlayerInfo[playerid][pGPS]);
    INI_Int("Deposit",PlayerInfo[playerid][pDeposit]);
    INI_Int("Materials",PlayerInfo[playerid][pMaterials]);
    INI_Int("Packages",PlayerInfo[playerid][pPackages]);
    INI_Int("Cocaine",PlayerInfo[playerid][pCocaine]);
    print("Loaded Player Information (Name, Age, Job...)");
    return 1;
}
Please help, I cant seem to figure out the problem..


Re: Help me with saving system please - mineralo - 15.01.2012

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
INI_SetTag(File,"data");
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Level",0);
                INI_WriteInt(File,"Experience",0);
                INI_WriteInt(File,"Sex",0);
                INI_WriteInt(File,"Age",0);
                INI_WriteInt(File,"Job",0);
                INI_WriteFloat(File,"Pos_x",0);
                INI_WriteFloat(File,"Pos_y",0);
                INI_WriteFloat(File,"Pos_z",0);
                INI_WriteInt(File,"Skin",0);
                INI_WriteInt(File,"Team",0);
                INI_WriteInt(File,"Accent",0);
                INI_WriteInt(File,"pGun1",0);
                INI_WriteInt(File,"pGun2",0);
                INI_WriteInt(File,"pGun3",0);
                INI_WriteInt(File,"pGun4",0);
                INI_WriteInt(File,"pGun5",0);
                INI_WriteInt(File,"pGun6",0);
                INI_WriteInt(File,"pGun7",0);
                INI_WriteInt(File,"pGun8",0);
                INI_WriteInt(File,"pGun9",0);
                INI_WriteInt(File,"pGun10",0);
                INI_WriteInt(File,"pGun11",0);
                INI_WriteInt(File,"pGun12",0);
                INI_WriteInt(File,"pGPS",1);
                INI_WriteInt(File,"pDeposit",0);
                INI_WriteInt(File,"pMaterials",0);
                INI_WriteInt(File,"pPackages",0);
                INI_WriteInt(File,"pCocaine",0);
                INI_Close(File);
return 1;
}
you just forgot to save the stuff when player disconnect from server


Re: Help me with saving system please - ryansheilds - 15.01.2012

I have something like that already, I have:
pawn Код:
SaveAccountStats(playerid);
And the save accounts function:
pawn Код:
function SaveAccountStats(playerid)
{
    new
        INI:File = INI_Open(UserPath(playerid))
    ;
    INI_SetTag(File,"data");
   
    PlayerInfo[playerid][pSkin] = GetPlayerSkin(playerid);
    PlayerInfo[playerid][pCash] = GetPlayerCash(playerid);
    new
        Float:x,
        Float:y,
        Float:z
    ;
    GetPlayerPos(playerid,x,y,z);
    PlayerInfo[playerid][pPos_x] = x;
    PlayerInfo[playerid][pPos_y] = y;
    PlayerInfo[playerid][pPos_z] = z;
    GetPlayerPos(playerid,PlayerInfo[playerid][pPos_x],PlayerInfo[playerid][pPos_y],PlayerInfo[playerid][pPos_z]);
   
    INI_WriteInt(File,"Cash",PlayerInfo[playerid][pCash]);
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Level",PlayerInfo[playerid][pLevel]);
    INI_WriteInt(File, "Experience",PlayerInfo[playerid][pExp]);
    INI_WriteInt(File,"Sex",PlayerInfo[playerid][pSex]);
    INI_WriteInt(File,"Age",PlayerInfo[playerid][pAge]);
    INI_WriteFloat(File,"Pos_x",PlayerInfo[playerid][pPos_x]);
    INI_WriteFloat(File,"Pos_y",PlayerInfo[playerid][pPos_y]);
    INI_WriteFloat(File,"Pos_z",PlayerInfo[playerid][pPos_z]);
    INI_WriteInt(File,"Skin",PlayerInfo[playerid][pSkin]);
    INI_WriteInt(File,"Team",PlayerInfo[playerid][pTeam]);
    INI_WriteInt(File,"Accent",PlayerInfo[playerid][pAccent]);
    INI_WriteInt(File,"Job",PlayerInfo[playerid][pJobID]);
    INI_WriteInt(File,"Gun1",PlayerInfo[playerid][pGun1]);
    INI_WriteInt(File,"Gun2",PlayerInfo[playerid][pGun2]);
    INI_WriteInt(File,"Gun3",PlayerInfo[playerid][pGun3]);
    INI_WriteInt(File,"Gun4",PlayerInfo[playerid][pGun4]);
    INI_WriteInt(File,"Gun5",PlayerInfo[playerid][pGun5]);
    INI_WriteInt(File,"Gun6",PlayerInfo[playerid][pGun6]);
    INI_WriteInt(File,"Gun7",PlayerInfo[playerid][pGun7]);
    INI_WriteInt(File,"Gun8",PlayerInfo[playerid][pGun8]);
    INI_WriteInt(File,"Gun9",PlayerInfo[playerid][pGun9]);
    INI_WriteInt(File,"Gun10",PlayerInfo[playerid][pGun10]);
    INI_WriteInt(File,"Gun11",PlayerInfo[playerid][pGun11]);
    INI_WriteInt(File,"Gun12",PlayerInfo[playerid][pGun12]);
    INI_WriteInt(File,"GPS",PlayerInfo[playerid][pGPS]);
    INI_WriteInt(File,"Deposit",PlayerInfo[playerid][pDeposit]);
    INI_WriteInt(File,"Materials",PlayerInfo[playerid][pMaterials]);
    INI_WriteInt(File,"Packages",PlayerInfo[playerid][pPackages]);
    INI_WriteInt(File,"Cocaine",PlayerInfo[playerid][pCocaine]);
    INI_Close(File);
    return 1;
}
So thats not the problem.


Re: Help me with saving system please - Bogdan1992 - 15.01.2012

EDIT: SORRY, i'll fix this, wait


Re: Help me with saving system please - ryansheilds - 15.01.2012

Already have that too, Well something similar.


Re: Help me with saving system please - Bogdan1992 - 15.01.2012

Ok make this variable global.
PHP код:
new Logged[MAX_PLAYERS]; 
After that add this at OnPlayerConnect()
PHP код:
public OnPlayerConnect(playerid)
{
     
//Rest of your code
      
Logged[playerid] = 0;
      return 
1;

After that add this at OnPlayerSpawn()
PHP код:
Logged[playerid] = 1
Then,
PHP код:
function SaveAccountStats(playerid)
{
if(
Logged[playerid] == 1){
    new
        
INI:File INI_Open(UserPath(playerid))
    ;
    
INI_SetTag(File,"data");
    
    
PlayerInfo[playerid][pSkin] = GetPlayerSkin(playerid);
    
PlayerInfo[playerid][pCash] = GetPlayerCash(playerid);
    new
        
Float:x,
        
Float:y,
        
Float:z
    
;
    
GetPlayerPos(playerid,x,y,z);
    
PlayerInfo[playerid][pPos_x] = x;
    
PlayerInfo[playerid][pPos_y] = y;
    
PlayerInfo[playerid][pPos_z] = z;
    
GetPlayerPos(playerid,PlayerInfo[playerid][pPos_x],PlayerInfo[playerid][pPos_y],PlayerInfo[playerid][pPos_z]);
    
    
INI_WriteInt(File,"Cash",PlayerInfo[playerid][pCash]);
    
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    
INI_WriteInt(File,"Level",PlayerInfo[playerid][pLevel]);
    
INI_WriteInt(File"Experience",PlayerInfo[playerid][pExp]);
    
INI_WriteInt(File,"Sex",PlayerInfo[playerid][pSex]);
    
INI_WriteInt(File,"Age",PlayerInfo[playerid][pAge]);
    
INI_WriteFloat(File,"Pos_x",PlayerInfo[playerid][pPos_x]);
    
INI_WriteFloat(File,"Pos_y",PlayerInfo[playerid][pPos_y]);
    
INI_WriteFloat(File,"Pos_z",PlayerInfo[playerid][pPos_z]);
    
INI_WriteInt(File,"Skin",PlayerInfo[playerid][pSkin]);
    
INI_WriteInt(File,"Team",PlayerInfo[playerid][pTeam]);
    
INI_WriteInt(File,"Accent",PlayerInfo[playerid][pAccent]);
    
INI_WriteInt(File,"Job",PlayerInfo[playerid][pJobID]);
    
INI_WriteInt(File,"Gun1",PlayerInfo[playerid][pGun1]);
    
INI_WriteInt(File,"Gun2",PlayerInfo[playerid][pGun2]);
    
INI_WriteInt(File,"Gun3",PlayerInfo[playerid][pGun3]);
    
INI_WriteInt(File,"Gun4",PlayerInfo[playerid][pGun4]);
    
INI_WriteInt(File,"Gun5",PlayerInfo[playerid][pGun5]);
    
INI_WriteInt(File,"Gun6",PlayerInfo[playerid][pGun6]);
    
INI_WriteInt(File,"Gun7",PlayerInfo[playerid][pGun7]);
    
INI_WriteInt(File,"Gun8",PlayerInfo[playerid][pGun8]);
    
INI_WriteInt(File,"Gun9",PlayerInfo[playerid][pGun9]);
    
INI_WriteInt(File,"Gun10",PlayerInfo[playerid][pGun10]);
    
INI_WriteInt(File,"Gun11",PlayerInfo[playerid][pGun11]);
    
INI_WriteInt(File,"Gun12",PlayerInfo[playerid][pGun12]);
    
INI_WriteInt(File,"GPS",PlayerInfo[playerid][pGPS]);
    
INI_WriteInt(File,"Deposit",PlayerInfo[playerid][pDeposit]);
    
INI_WriteInt(File,"Materials",PlayerInfo[playerid][pMaterials]);
    
INI_WriteInt(File,"Packages",PlayerInfo[playerid][pPackages]);
    
INI_WriteInt(File,"Cocaine",PlayerInfo[playerid][pCocaine]);
    
INI_Close(File);
    return 
1;
    }




Re: Help me with saving system please - ryansheilds - 15.01.2012

(2266) : warning 209: function "SaveAccountStats" should return a value - Line 2266 is the "}" at the end of function SaveAccountStats(playerid)


Re: Help me with saving system please - Bogdan1992 - 15.01.2012

Here, should work now.
PHP код:
function SaveAccountStats(playerid

if(
Logged[playerid] == 1){ 
    new 
        
INI:File INI_Open(UserPath(playerid)) 
    ; 
    
INI_SetTag(File,"data"); 
     
    
PlayerInfo[playerid][pSkin] = GetPlayerSkin(playerid); 
    
PlayerInfo[playerid][pCash] = GetPlayerCash(playerid); 
    new 
        
Float:x
        
Float:y
        
Float:
    

    
GetPlayerPos(playerid,x,y,z); 
    
PlayerInfo[playerid][pPos_x] = x
    
PlayerInfo[playerid][pPos_y] = y
    
PlayerInfo[playerid][pPos_z] = z
    
GetPlayerPos(playerid,PlayerInfo[playerid][pPos_x],PlayerInfo[playerid][pPos_y],PlayerInfo[playerid][pPos_z]); 
     
    
INI_WriteInt(File,"Cash",PlayerInfo[playerid][pCash]); 
    
INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]); 
    
INI_WriteInt(File,"Level",PlayerInfo[playerid][pLevel]); 
    
INI_WriteInt(File"Experience",PlayerInfo[playerid][pExp]); 
    
INI_WriteInt(File,"Sex",PlayerInfo[playerid][pSex]); 
    
INI_WriteInt(File,"Age",PlayerInfo[playerid][pAge]); 
    
INI_WriteFloat(File,"Pos_x",PlayerInfo[playerid][pPos_x]); 
    
INI_WriteFloat(File,"Pos_y",PlayerInfo[playerid][pPos_y]); 
    
INI_WriteFloat(File,"Pos_z",PlayerInfo[playerid][pPos_z]); 
    
INI_WriteInt(File,"Skin",PlayerInfo[playerid][pSkin]); 
    
INI_WriteInt(File,"Team",PlayerInfo[playerid][pTeam]); 
    
INI_WriteInt(File,"Accent",PlayerInfo[playerid][pAccent]); 
    
INI_WriteInt(File,"Job",PlayerInfo[playerid][pJobID]); 
    
INI_WriteInt(File,"Gun1",PlayerInfo[playerid][pGun1]); 
    
INI_WriteInt(File,"Gun2",PlayerInfo[playerid][pGun2]); 
    
INI_WriteInt(File,"Gun3",PlayerInfo[playerid][pGun3]); 
    
INI_WriteInt(File,"Gun4",PlayerInfo[playerid][pGun4]); 
    
INI_WriteInt(File,"Gun5",PlayerInfo[playerid][pGun5]); 
    
INI_WriteInt(File,"Gun6",PlayerInfo[playerid][pGun6]); 
    
INI_WriteInt(File,"Gun7",PlayerInfo[playerid][pGun7]); 
    
INI_WriteInt(File,"Gun8",PlayerInfo[playerid][pGun8]); 
    
INI_WriteInt(File,"Gun9",PlayerInfo[playerid][pGun9]); 
    
INI_WriteInt(File,"Gun10",PlayerInfo[playerid][pGun10]); 
    
INI_WriteInt(File,"Gun11",PlayerInfo[playerid][pGun11]); 
    
INI_WriteInt(File,"Gun12",PlayerInfo[playerid][pGun12]); 
    
INI_WriteInt(File,"GPS",PlayerInfo[playerid][pGPS]); 
    
INI_WriteInt(File,"Deposit",PlayerInfo[playerid][pDeposit]); 
    
INI_WriteInt(File,"Materials",PlayerInfo[playerid][pMaterials]); 
    
INI_WriteInt(File,"Packages",PlayerInfo[playerid][pPackages]); 
    
INI_WriteInt(File,"Cocaine",PlayerInfo[playerid][pCocaine]); 
    
INI_Close(File); 
    } 
    return 
1




Re: Help me with saving system please - ryansheilds - 15.01.2012

I already tried moving the "return 1;" and I got the error (2265) : warning 217: loose indentation
But apart from that warning it seems to work, apart from the money ends up going up to the same amount of 9500 even if you spend some of it or deposit it.

EDIT: Doesn't matter, Just a little error I made - Noticed instead of putting GivePlayerCash(giveplayerid, money); I had GivePlayerMoney(giveplayerid, money);


Re: Help me with saving system please - Bogdan1992 - 15.01.2012

That warning Loose indentation, you just need to line that return.

About that thing with money, try to fix those things,
PHP код:
PlayerInfo[playerid][pCash] = GetPlayerCash(playerid); 
into
PHP код:
PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid); 
And add this if you don't have it.
PHP код:
OnPlayerSpawn(playerid);
{
     
SetPlayerMoney(playeridPlayerInfo[playerid][pCash]);
     return 
1;