Dini saving problem :/ (+ rep)
#1

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...
Reply
#2

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?
Reply
#3

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 *
Reply
#4

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.
Reply
#5

Anyone else?
Reply
#6

dini is way too outdated . Use y_ini
Reply
#7

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

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.
Reply
#9

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.
Reply
#10

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"));
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)