SA-MP Forums Archive
Loading/Writing/saving a file problem - 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: Loading/Writing/saving a file problem (/showthread.php?tid=459073)



Loading/Writing/saving a file problem - JimmyCh - 20.08.2013

Hi guys, so I started a new gamemode, but having problems with the loading for score and money etc..
So it saves the admin level for now only.. I don't really know why.
Also like, when I use /ban, it should write in the file: Ban = 1, but always shows Ban = 0, but when they try to connect it shows they're banned until I do the command /unban..

Anyway I need some help for saving/loading from these files, and maybe writing in them too.
Let me give you my loading stuff..
LoadUser_data:
pawn Код:
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPass]);
    INI_Int("Cash",PlayerInfo[playerid][pCash]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    INI_Int("Mute",PlayerInfo[playerid][pMute]);
    INI_Int("Warns",PlayerInfo[playerid][pWarns]);
    INI_Int("Score", PlayerInfo[playerid][pScore]);
    INI_Int("Ban",PlayerInfo[playerid][pBan]);
    return 1;
}
OnPlayerDisconnect:
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Mute",PlayerInfo[playerid][pMute]);
    INI_WriteInt(File,"Warns",PlayerInfo[playerid][pWarns]);
    INI_WriteInt(File,"Score", GetPlayerScore(playerid));
    INI_WriteInt(File,"Ban",PlayerInfo[playerid][pBan]);
    INI_Close(File);
Now on the registration we got this:
pawn Код:
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,"Mute",0);
                INI_WriteInt(File,"Warns",0);
                INI_WriteInt(File,"Score", 0);
                INI_WriteInt(File,"Ban",0);
                INI_Close(File);
Can anyone please help me with this so I can proceed with my script? Would be awesome


Re: Loading/Writing/saving a file problem - iAnonymous - 20.08.2013

remove


Re: Loading/Writing/saving a file problem - JimmyCh - 20.08.2013

wat teh fuk?


Re: Loading/Writing/saving a file problem - RALL0 - 20.08.2013

Under OnPlayerConnect
pawn Код:
new plname[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid, plname, sizeof(plname));
PlayerInfo[playerid][pAdmin] = 0;
PlayerInfo[playerid][pMute] = 0;
PlayerInfo[playerid][pWarns] = 0;
PlayerInfo[playerid][pBan] = 0;
format(string, sizeof(string), "/Users/%s.ini", plname);



Re: Loading/Writing/saving a file problem - JimmyCh - 20.08.2013

Just a question, doesn't that like.. reset his stats? If we put them to 0?
Also, why don't we have the money and score on this one?

EDIT: PS, if you did that to save the user file, it already saves as Jimmy.ini ... But doesn't write there properly, nor read from there when I edit stats from the user file.


Re: Loading/Writing/saving a file problem - RALL0 - 20.08.2013

It loads perfectly fine, just change the "Users" to your users file. I recommend you to try it, I use the same and it works great. For the money do the same, I just forgot it.
pawn Код:
format(string, sizeof(string), "/Users/%s.ini", plname);



Re: Loading/Writing/saving a file problem - JimmyCh - 20.08.2013

I don't understand, did you test my codes and it worked?
But I don't understand why we need to put 0 for them OnPlayerConnect for it to load and save in the files properly..


Re: Loading/Writing/saving a file problem - RALL0 - 20.08.2013

Yes, you have very similar codes to mine, infact it's the same. I use this for a long time and never had trouble with it, it's up to you to test it or not, this is all the help I can offer you.


Re: Loading/Writing/saving a file problem - JimmyCh - 20.08.2013

Thanks, will test then post my result later on here.
Thank you for all your help anyway.

If anyone find my mistake(if RALL0 didn't solve it) please post ahead so I can solve my problem.
Thank you.


Re: Loading/Writing/saving a file problem - Matnix - 20.08.2013

pawn Код:
if(PlayerInfo[playerid][pBanned] == 1) return Ban(playerid); // on player connect


new INI:File = INI_Open(UserPath(playerid));// on your ban command
INI_WriteString(File,"Banned",1);
INI_Close(File);
I don't think the code from R4LLO will work. Maybe it's false.