SA-MP Forums Archive
Dini saving problem :/ (+ rep) - 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: Dini saving problem :/ (+ rep) (/showthread.php?tid=309456)



Dini saving problem :/ (+ rep) - SpiritEvil - 07.01.2012

Hello! So I am trying to make a Points system that saves the points in a file to load them again after the player connects. When I try to compile the code is all right, but when I go in-game the file doesn't save at all :/
Here's the code I'm using:

pawn Код:
#include <a_samp>
#include <Dini>


#define MyFile  "\\Points\\%s.ini"
new Points[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    new File[68];
    new Name[MAX_PLAYER_NAME];

    GetPlayerName(playerid, Name, sizeof(Name));
    format(File, sizeof(File), MyFile, Name);
    if(!dini_Exists(File))
    {
        dini_Create(File);
        dini_Set(File, "Name", Name);
        dini_IntSet(File, "Points", 0);
        Points[playerid] = dini_Int(File, "Points");
    }
    else
    Points[playerid] = dini_Int(File, "Points");

    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new File[68];
    new Name[MAX_PLAYER_NAME];

    GetPlayerName(playerid, Name  , sizeof(Name));
    format(File, sizeof(File) , MyFile , Name);
    dini_IntSet(File, "Points" , Points[playerid]);
    Points[playerid] = 0;
    return 1;
I hope someone can help me...


Re: Dini saving problem :/ (+ rep) - Steven82 - 07.01.2012

Do you have the points folder in your script files?

pawn Код:
#define MyFile  "Points/%s.ini"
Use that. It might work. Since i've never actually tried using doubles "\\" but whats the point?


Re: Dini saving problem :/ (+ rep) - Psymetrix - 07.01.2012

Should
pawn Код:
#define MyFile  "\\Points\\%s.ini"
not be
pawn Код:
#define MyFile  "Points/%s.ini"
?

I've been using databases so I'm not 100% sure about this one.

* edited *


Re: Dini saving problem :/ (+ rep) - SpiritEvil - 07.01.2012

Quote:

Do you have the points folder in your script files?

Of course I have otherways the server would crash.

Anyway, I tried used both of your methods and still, it doesn't save the file.


Re: Dini saving problem :/ (+ rep) - SpiritEvil - 07.01.2012

Anyone else?


Re: Dini saving problem :/ (+ rep) - DonWade - 07.01.2012

dini is way too outdated . Use y_ini


Re: Dini saving problem :/ (+ rep) - SpiritEvil - 08.01.2012

Yes, I know but I'm more familiar with it that's why I use it. Anyway I'll try y_ini.


Re: Dini saving problem :/ (+ rep) - Konstantinos - 08.01.2012

pawn Код:
#include <a_samp>
#include <dini>

#define MyFile  "Points/%s.ini"
// Create a floder inside Scriptfiles called 'Points'
enum pInfo
{
    Score
}
new PlayerInfo[MAX_PLAYERS][pInfo];

public OnPlayerConnect(playerid)
{
    new File[68];
    new Name[MAX_PLAYER_NAME];

    GetPlayerName(playerid, Name, sizeof(Name));
    format(File, sizeof(File), MyFile, Name);
    if(!dini_Exists(File)) {
        dini_Create(File);
        dini_Set(File, "Name", Name);
        dini_IntSet(File, "Points", 0);
    }
    else {
        PlayerInfo[playerid][Score]= dini_Int(File, "Points");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new File[68];
    new Name[MAX_PLAYER_NAME];

    GetPlayerName(playerid, Name  , sizeof(Name));
    format(File, sizeof(File) , MyFile , Name);
    if(dini_Exists(File)) {
        dini_IntSet(File, "Points", PlayerInfo[playerid][Score]);
    }
    return 1;
}
To save them after closing the console, you have to use the same part from OnPlayerDisconnect to OnFilterScriptExit but with loop or foreach.


Re: Dini saving problem :/ (+ rep) - SpiritEvil - 08.01.2012

Quote:
Originally Posted by Dwane
Посмотреть сообщение
pawn Код:
#include <a_samp>
#include <dini>

#define MyFile  "Points/%s.ini"
// Create a floder inside Scriptfiles called 'Points'
enum pInfo
{
    Score
}
new PlayerInfo[MAX_PLAYERS][pInfo];

public OnPlayerConnect(playerid)
{
    new File[68];
    new Name[MAX_PLAYER_NAME];

    GetPlayerName(playerid, Name, sizeof(Name));
    format(File, sizeof(File), MyFile, Name);
    if(!dini_Exists(File)) {
        dini_Create(File);
        dini_Set(File, "Name", Name);
        dini_IntSet(File, "Points", 0);
    }
    else {
        PlayerInfo[playerid][Score]= dini_Int(File, "Points");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new File[68];
    new Name[MAX_PLAYER_NAME];

    GetPlayerName(playerid, Name  , sizeof(Name));
    format(File, sizeof(File) , MyFile , Name);
    if(dini_Exists(File)) {
        dini_IntSet(File, "Points", PlayerInfo[playerid][Score]);
    }
    return 1;
}
To save them after closing the console, you have to use the same part from OnPlayerDisconnect to OnFilterScriptExit but with loop or foreach.
Thank you for your help, but it still doesn't save any file.


Re: Dini saving problem :/ (+ rep) - Konstantinos - 08.01.2012

I tested and works. If it's the score replace
pawn Код:
dini_IntSet(File, "Points", PlayerInfo[playerid][Score]);
To
pawn Код:
dini_IntSet(File, "Points", GetPlayerScore(playerid));
And this
pawn Код:
PlayerInfo[playerid][Score]= dini_Int(File, "Points");
To
pawn Код:
SetPlayerScore(playerid, dini_Int(File, "Points"));