SII writing problem...
#1

Hello, I'm making an admin system for my server, however I have a little problem with saving the player stats when they disconnect

so here's the code:

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{

    if (PInfo[playerid][Logged] == 1)
    {
        new file[64],PlayerName[24];
        GetPlayerName(playerid,PlayerName,sizeof PlayerName);
        format(file,sizeof file,"Admin/%s.ini",PlayerName);
        PInfo[playerid][Score] = GetPlayerScore(playerid);
        PInfo[playerid][Money] = GetPlayerMoney(playerid);
        PInfo[playerid][Skin] = GetPlayerSkin(playerid);
   
        INI_Open(file);
        INI_WriteInt("Money",PInfo[playerid][Money]);
        INI_WriteInt("Score",PInfo[playerid][Money]);
        INI_WriteInt("Skin",PInfo[playerid][Skin]);
        INI_Save();
        INI_Close();
        PInfo[playerid][Logged] = 0;
    }

    return 1;
}
For some reason it won't save the stats into the requested file :/

any help?
Thanks in advance
Reply
#2

This is incorrect:

pawn Код:
format(file,sizeof file,"Admin/%s.ini",PlayerName);
This is correct:

pawn Код:
format(file,sizeof(file),"Admin/%s.ini",PlayerName);
Already arrayed words, like file[64], need brackets around the sizeof. Else, you write a number instead of sizeof(file).

I don't know if that will fix the problem, I'm just guessing. But I hope it will do.
Reply
#3

Wait no, it didn't work...
:/
Reply
#4

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    if(PInfo[playerid][Logged] == 1)
    {
        new file[64],PlayerName[24];
        GetPlayerName(playerid,PlayerName,sizeof PlayerName);
        format(file,sizeof file,"Admin/%s.ini",PlayerName);
        PInfo[playerid][Score] = GetPlayerScore(playerid);
        PInfo[playerid][Money] = GetPlayerMoney(playerid);
        PInfo[playerid][Skin] = GetPlayerSkin(playerid);
        INI_Open(file);
        INI_WriteInt(file,"Money",PInfo[playerid][Money]); // same as 2 down
        INI_WriteInt(file,"Score",PInfo[playerid][Money]); // same as 1 down
        INI_WriteInt(file,"Skin",PInfo[playerid][Skin]); // INI_WriteInt(<file name>,<what you want to write>,<the variable>);
        INI_Close(file); // the script didn't know what file to close with the () without "File"
        PInfo[playerid][Logged] = 0;
    }
    return 1;
}
Upon INI_Close(File), it will automatically save, so there's no need for INI_Save, and that doesn't exist I don't think, the rest of the changes, I put in the pawn tags. I should've detected it earlier .
Reply
#5

Код:
C:\Users\Els\Documents\GTA San Andreas User Files\Server\samp03x_svr_win32\gamemodes\TerribleStunts.pwn(76) : error 035: argument type mismatch (argument 2)
C:\Users\Els\Documents\GTA San Andreas User Files\Server\samp03x_svr_win32\gamemodes\TerribleStunts.pwn(77) : error 035: argument type mismatch (argument 2)
C:\Users\Els\Documents\GTA San Andreas User Files\Server\samp03x_svr_win32\gamemodes\TerribleStunts.pwn(78) : error 035: argument type mismatch (argument 2)
C:\Users\Els\Documents\GTA San Andreas User Files\Server\samp03x_svr_win32\gamemodes\TerribleStunts.pwn(79) : warning 202: number of arguments does not match definition
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


3 Errors.
pawn Код:
INI_WriteInt(file,"Money",PInfo[playerid][Money]); // same as 2 down
        INI_WriteInt(file,"Score",PInfo[playerid][Money]); // same as 1 down
        INI_WriteInt(file,"Skin",PInfo[playerid][Skin]); // INI_WriteInt(<file name>,<what you want to write>,<the variable>);
        INI_Close(file); // the script didn't know what file to close with the () without "File"
that are the error lines :/

EDIT: also tried to change the WriteInt into WriteFloat, but with no succes...
Reply
#6

Try this instead:

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    if(PInfo[playerid][Logged] == 1)
    {
        new username[MAX_PLAYER_NAME];
        GetPlayerName(playerid, username, sizeof(username));
        new INI:File = INI_Open("Admin/%s.ini", username);
        INI_SetTag(File,"data");
        INI_WriteInt(File,"Money",GetPlayerMoney(playerid));
        INI_WriteInt(File,"Score",GetPlayerScore(playerid));
        INI_WriteInt(File,"Skin",GetPlayerSkin(playerid));
        INI_Close(File);
        PInfo[playerid][Logged] = 0;
    }
    return 1;
}
If that doesn't work, show the OnDialogResponse for the login & register dialog.

PS: No point to change it to WriteFloat, Float's are given for positions, for example, a car position or a player's spawn position.
Reply
#7

SII doesn't have those functions you used, because I got lots of errors and looked in the sii.inc...
Anways here's the login and register command:

pawn Код:
CMD:register(playerid,params[])
{
    if(PInfo[playerid][Logged] == 1) return SendClientMessage(playerid,-4,"You are already logged in!");//Checking if the player is logged in, if he is, it won't allow him to re-register
    new password[23];//Creating a variable to store the password
    if(sscanf(params,"s[23]",password)) return SendClientMessage(playerid,-1,"USAGE: /register <password>");//Here we're checking if the player inputs any password, if not, it will return to him a message saying the proper usage.
    new file[64],PlayerName[24];//Creating a variable to store the file path, and a variable to store the players name.
    GetPlayerName(playerid,PlayerName,sizeof PlayerName);
    format(file,sizeof file,"Admin/%s.ini",PlayerName);
    if(fexist(file)) return SendClientMessage(playerid,-4,"Somehow you're already registered!");//Checking if the player is already registered, again....
    INI_Open(file);//Opening the file with SII include (with this function, if the file is not created, it will automatically create the file.)
    INI_WriteString("Password",password);//Writing in the file the password the player has inputted.
    INI_WriteInt("Level",PInfo[playerid][Level]);//Writing in the file, the variable of the admin level.
    INI_Save();//After we write something to the file, we already have to use this to save the information in the player's file.
    INI_Close();//"Closing the file", that means that we're not using it anymore :P
    SendClientMessage(playerid,-1,"You have successfully registered!");
    PInfo[playerid][Logged] = 1;//Setting the logged in variable to 1
    return 1;
}

CMD:login(playerid,params[])
{
    if(PInfo[playerid][Logged] == 1) return SendClientMessage(playerid,-4,"You are already logged in!");//Checking if the player is logged in, if he is, it won't allow him to login
    new password[23],password2[23];//Creating a variable to store the password, and another one to store the password from the user's file.
    if(sscanf(params,"s[23]",password)) return SendClientMessage(playerid,-1,"USAGE: /login <password>");//Here we're checking if the player inputs any password, if not, it will return to him a message saying the proper usage.
    new file[64],PlayerName[24];//Creating a variable to store the file path, and a variable to store the players name.
    GetPlayerName(playerid,PlayerName,sizeof PlayerName);
    format(file,sizeof file,"Admin/%s.ini",PlayerName);
    if(!fexist(file)) return SendClientMessage(playerid,-4,"Please use /register");//Checking if the player is not registered, again....
    INI_Open(file);//Opening the file with SII include
    INI_ReadString(password2,"Password");
    if(strcmp(password,password2) != 0) return SendClientMessage(playerid,-4,"Wrong password!"),INI_Close();//Checking if he inputted the correct password, if not, retrieve him a message and closing the file;
    PInfo[playerid][Level] = INI_ReadInt("Level");//Setting the admin level variable, to the one thats in his file.
    PInfo[playerid][Score] = INI_ReadInt("Score");
    GivePlayerMoney(playerid, INI_ReadInt("Money"));
    SetPlayerScore(playerid, PInfo[playerid][Score]);
    SetPlayerSkin(playerid, INI_ReadInt("Skin"));
    INI_Close();//"Closing the file", that means that we're not using it anymore :P
    SendClientMessage(playerid,-1,"You have been successfully logged in!");
    PInfo[playerid][Logged] = 1;//Setting the logged in variable to 1
    return 1;
this part of code works flawless btw
Reply
#8

Ok, and the code that I gave you in the last post doesn't work? If not.. then I don't know what's wrong.
Reply
#9

No
thanks anyway

Maybe someone else?
Reply
#10

Make sure that the Admin folder exists.

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    if (PInfo[playerid][Logged] == 1)
    {
        new file[64], playerName[24];
        GetPlayerName(playerid, playerName, sizeof(playerName));
        format(file, sizeof(file), "Admin/%s.ini", playerName);

        PInfo[playerid][Score] = GetPlayerScore(playerid);
        PInfo[playerid][Money] = GetPlayerMoney(playerid);
        PInfo[playerid][Skin] = GetPlayerSkin(playerid);

        if (INI_Open(file))
        {
            INI_WriteInt("Money", PInfo[playerid][Money]);
            INI_WriteInt("Score", PInfo[playerid][Money]);
            INI_WriteInt("Skin", PInfo[playerid][Skin]);
            INI_Save();
            INI_Close();
        }
        PInfo[playerid][Logged] = 0;
    }
    return 1;
}
If that doesn't work, then try this version of SII:

http://pastebin.com/raw.php?i=Gtfruqk6
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)