Loop + SII Ini writing problem
#1

Hello, I got a small problem creating a servershop system...
I'm at the very last step wich is saving the stats but I got some problems...

ok so the shop enums:

pawn Код:
enum Shops
{
    shop_name[500],
    shop_costmoney,
    shop_costscore,
    shop_reward[500],
    shop_unlocked[MAX_PLAYERS]
}

new ServerShop[8][Shops]=
{
    {"No more speeding control",    150000, 10 ,    "you cannot be caught by speedtraps no more!",   0},
    {"Save Deathpos",   500000, 50 ,    "and you will be auto spawned to your death pos when you die!", 1},
    {"10 Score",    25000,  0 , "You have gained 10 score points",  1},
    {"50 Score",    100000, 0, "You have gained 50 score points",  1},
    {"100 Score",   1750000,    0 , "You have gained 100 score points", 0},
    {"Free Weather",   10000,    5 , "and u can now use /fweather to chose ur weather!", 0},
    {"Auto Armour", 50000,  7 , "and u can now use the command: /auto armour once every 10 minuts",   1},
    {"Auto Health", 750000, 12 ,    "and u can now use the command: /autp health once every 10 minuts",   0}//removed the ',' here too
};
then:
pawn Код:
public OnPlayerConnect(playerid)
{
    new file[200],
        name[24],
        string[1000];
    GetPlayerName(playerid, name, sizeof(name));
    format(file,sizeof(file),"LuxKnack/TeamStats/%s.ini",name);
    INI_Open(file);
    pKMs[playerid] = INI_ReadInt("KMDriven");
    pJoinBandits[playerid] = INI_ReadInt("JoinedBandits");
    pJoinCops[playerid] = INI_ReadInt("JoinedCops");
    pJoinDrivers[playerid] = INI_ReadInt("JoinedDrivers");
    pJoinTruckers[playerid] = INI_ReadInt("JoinedTruckers");
   
        for(new b; b < sizeof(ServerShop); b++)
        {
            if(ServerShop[b][shop_unlocked][playerid] == 1)
            {
                format(string, sizeof(string),"%s", ServerShop[b][shop_name]);
                ServerShop[b][shop_unlocked][playerid] = INI_ReadInt(string);
            }
        }
       
    INI_Close();
don't really look at the other stuff besides the loop

then OnPlayerDisconnect:

pawn Код:
GetPlayerName(playerid, name, sizeof(name));
    format(file,sizeof(file),"LuxKnack/TeamStats/%s.ini",name);//Formating the var to the selected house directory.
    INI_Open(file);//Opening the file with SII.
   
    INI_WriteInt("KMDriven\n", pKMs[playerid]);
    INI_WriteInt("JoinedBandits", pJoinBandits[playerid]);
    INI_WriteInt("JoinedCops", pJoinCops[playerid]);
    INI_WriteInt("JoinedDrivers", pJoinDrivers[playerid]);
    INI_WriteInt("JoinedTruckers", pJoinTruckers[playerid]);
   
        for(new b; b < sizeof(ServerShop); b++)
        {
            if(ServerShop[b][shop_unlocked][playerid] == 1)
            {
                format(string, sizeof(string),"%s", ServerShop[b][shop_name]);
                INI_WriteInt(string, 1);
            }
        }
       
    INI_Save();//Saving file with SII.
    INI_Close();

    if(GetPlayerWantedLevel(playerid) > 0){
        if(gTeam[playerid] == TEAM_DRIVERS || gTeam[playerid] == TEAM_COPS){
            ResetPlayerWeapons(playerid);
            SetPlayerWantedLevel(playerid, 0);
        }
    }
but my ini file looks like this:
Код:
KMDriven=70
JoinedBandits=1
JoinedCops=3
JoinedDrivers=13
JoinedTruckers=469
;KMDriven
;=70
;KMDriven
;=70
;KMDriven
;=70
KMDriven
=70
NOTE: the server reads the file correctly, according to testing, still its looking pretty bad in the file itself...

and I need a new line for every shop name and look if it's rather unlocked for the player or not...
... any help?
Reply
#2

INI_WriteInt("KMDriven\n", pKMs[playerid]);

The \n isn't needed since SII creates it automatically. Also, use print() to check if if its loading/saving correctly.

pawn Код:
for(new b; b < sizeof(ServerShop); b++)
        {
            if(ServerShop[b][shop_unlocked][playerid] == 1)
            {
                format(string, sizeof(string),"%s", ServerShop[b][shop_name]);
                print(string);
                INI_WriteInt(string, 1);
            }
        }
Reply
#3

ah, thank you : )
I did the /n because I wanted to get a space in my file...
anyways, do you know how to get a new line in SII, just to make the file more structured?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)