How to load Float from .ini with Y_ini
#1

pawn Code:
#include <YSI\y_ini>

enum nstation
{
s1,
s2,
s3,
s4,
s5,
}
new station[nstation];
enum posinfo6
{
    Float:posx,
    Float:posy,
    Float:posz,
};
new PosInfo6[posinfo6];
enum posinfo0
{
    Float:posx,
    Float:posy,
    Float:posz,
};
new PosInfo0[MAX_PLAYERS][posinfo0];
enum posinfo1
{
    Float:posx,
    Float:posy,
    Float:posz,
};
new PosInfo1[MAX_PLAYERS][posinfo1];
enum posinfo2
{
    Float:posx,
    Float:posy,
    Float:posz,
};
new PosInfo2[MAX_PLAYERS][posinfo2];
enum posinfo3
{
    Float:posx,
    Float:posy,
    Float:posz,
};
new PosInfo3[MAX_PLAYERS][posinfo3];
new rentcar1[MAX_PLAYERS];
new rentcar2[MAX_PLAYERS];
new rentcar3[MAX_PLAYERS];
new Locked[MAX_PLAYERS], IsLocked[MAX_VEHICLES];
new engine, lights, alarm, doors, bonnet, boot, objective;
new Float:x, Float:y, Float:z;
new timer1;
new timer2;
new timer3;
new slot;
new Float:x1, Float:y1, Float:z1;
new Float:x2, Float:y2, Float:z2;
new Float:x3, Float:y3, Float:z3;
new Float:x4, Float:y4, Float:z4;
new Float:x5, Float:y5, Float:z5;
new file1;

public OnFilterScriptInit()
{
        print("\n--------------------------------------");
        print(" Car Rental System by Horrible");
        print("--------------------------------------\n");
        print(" =   = = = =  = == = =  +  =     =    [====");
        print(" = = = =   =  =    =    =  ====) =    [=== ");
        print(" =   = = = =  =    =    =  =---) ==== [==== ");
        print(" ----------------Version 1.4-----------------");
        INI_Load("/h-rental/rental1.ini");
        LoadStores();
        DisableInteriorEnterExits();
        for(new v = 0; v < MAX_VEHICLES; v++) IsLocked[v] = 0;
        return 1;
}


CMD:createrental(playerid, params[])
{
        if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,0xFF0000AA,"You can't use this command.");
        if(sscanf(params, "i", slot)) return SendClientMessage(playerid, COLOR_GREEN, "Usage: /createrental <slot>");
        if(slot < 1 || slot > 5) return SendClientMessage(playerid, COLOR_GREEN, "Invalid slot Id, (1 - 5)");
        if(slot == 1)
        {
        file1 = INI_Open("/h-rental/rental1.ini");
        DestroyPickup(station[s1]);
        GetPlayerPos(playerid, x1, y1, z1);
        PosInfo6[posx] = x1;
        PosInfo6[posy] = y1;
        PosInfo6[posz] = z1;
        INI_WriteFloat(file1, "X1", PosInfo6[posx]);
        INI_WriteFloat(file1, "Y1", PosInfo6[posy]);
        INI_WriteFloat(file1, "Z1", PosInfo6[posz]);
        station[s1] = CreatePickup(1318, 1, x1,y1,z1, 0);
        INI_Close(file1);
        }
stock LoadStores()
{
        new ini;
        ini = INI_Open("rental1.ini");
        station[s1] = CreatePickup(1318, 1, PosInfo6[posx],PosInfo6[posy],PosInfo6[posz], 0);
        INI_Close(ini);
        return 1;
}
return 1;
}
the rental1.ini created but can't load when me turn on and turn off the server again
can someone help?
i think this problem is about can't load the float from .ini file
Help please....
Reply
#2

Open the file before you load it.
Reply
#3

Quote:
Originally Posted by Delux13
View Post
Open the file before you load it.
more explanation?
Reply
#4

INI_ParseFile.
pawn Code:
INI_ParseFile( "/h-rental/rental1.ini", "example" .bExtra = true, .extra =  /* Parameters */);

forward example( /* parameters */ );
public example( /* parameters */ )
{
    INI_Float( "X1", enumvar );
    INI_Float( "Z2", enumvar );

    // etc

    return 1;
}
.
Reply
#5

Quote:
Originally Posted by Horrible
View Post
pawn Code:
#include <YSI\y_ini>

enum nstation
{
s1,
s2,
s3,
s4,
s5,
}
new station[nstation];
enum posinfo6
{
    Float:posx,
    Float:posy,
    Float:posz,
};
new PosInfo6[posinfo6];
enum posinfo0
{
    Float:posx,
    Float:posy,
    Float:posz,
};
new PosInfo0[MAX_PLAYERS][posinfo0];
enum posinfo1
{
    Float:posx,
    Float:posy,
    Float:posz,
};
new PosInfo1[MAX_PLAYERS][posinfo1];
enum posinfo2
{
    Float:posx,
    Float:posy,
    Float:posz,
};
new PosInfo2[MAX_PLAYERS][posinfo2];
enum posinfo3
{
    Float:posx,
    Float:posy,
    Float:posz,
};
new PosInfo3[MAX_PLAYERS][posinfo3];
new rentcar1[MAX_PLAYERS];
new rentcar2[MAX_PLAYERS];
new rentcar3[MAX_PLAYERS];
new Locked[MAX_PLAYERS], IsLocked[MAX_VEHICLES];
new engine, lights, alarm, doors, bonnet, boot, objective;
new Float:x, Float:y, Float:z;
new timer1;
new timer2;
new timer3;
new slot;
new Float:x1, Float:y1, Float:z1;
new Float:x2, Float:y2, Float:z2;
new Float:x3, Float:y3, Float:z3;
new Float:x4, Float:y4, Float:z4;
new Float:x5, Float:y5, Float:z5;
new file1;

public OnFilterScriptInit()
{
        print("\n--------------------------------------");
        print(" Car Rental System by Horrible");
        print("--------------------------------------\n");
        print(" =   = = = =  = == = =  +  =     =    [====");
        print(" = = = =   =  =    =    =  ====) =    [=== ");
        print(" =   = = = =  =    =    =  =---) ==== [==== ");
        print(" ----------------Version 1.4-----------------");
        INI_Load("/h-rental/rental1.ini");
        LoadStores();
        DisableInteriorEnterExits();
        for(new v = 0; v < MAX_VEHICLES; v++) IsLocked[v] = 0;
        return 1;
}


CMD:createrental(playerid, params[])
{
        if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,0xFF0000AA,"You can't use this command.");
        if(sscanf(params, "i", slot)) return SendClientMessage(playerid, COLOR_GREEN, "Usage: /createrental <slot>");
        if(slot < 1 || slot > 5) return SendClientMessage(playerid, COLOR_GREEN, "Invalid slot Id, (1 - 5)");
        if(slot == 1)
        {
        file1 = INI_Open("/h-rental/rental1.ini");
        DestroyPickup(station[s1]);
        GetPlayerPos(playerid, x1, y1, z1);
        PosInfo6[posx] = x1;
        PosInfo6[posy] = y1;
        PosInfo6[posz] = z1;
        INI_WriteFloat(file1, "X1", PosInfo6[posx]);
        INI_WriteFloat(file1, "Y1", PosInfo6[posy]);
        INI_WriteFloat(file1, "Z1", PosInfo6[posz]);
        station[s1] = CreatePickup(1318, 1, x1,y1,z1, 0);
        INI_Close(file1);
        }
stock LoadStores()
{
        new ini;
        ini = INI_Open("rental1.ini");
        station[s1] = CreatePickup(1318, 1, PosInfo6[posx],PosInfo6[posy],PosInfo6[posz], 0);
        INI_Close(ini);
        return 1;
}
return 1;
}
the rental1.ini created but can't load when me turn on and turn off the server again
can someone help?
i think this problem is about can't load the float from .ini file
Help please....
This makes no sense what you are doing. You are attempting to open and close a file locally through the process of executing a command. This is not how y_ini is supposed to be used. I'm not saying that it will not work, but values are supposed to be saved through variables.
Reply
#6

Quote:
Originally Posted by Kush
View Post
This makes no sense what you are doing. You are attempting to open and close a file locally through the process of executing a command. This is not how y_ini is supposed to be used. I'm not saying that it will not work, but values are supposed to be saved through variables.
new code:
pawn Code:
//          +++++++++++++++++++++++++++++++++++++++++++++++++
//          +       Car Rental System by Horrible           +
//          +-----------------------------------------------+
//          +    =   = = = =  = == = =  +  =     =    [==== +
//          +    = = = =   =  =    =    =  ====) =    [===  +
//          +    =   = = = =  =    =    =  =---) ==== [==== +
//          +------------------Version 1.4----------------- +
//          +++++++++++++++++++++++++++++++++++++++++++++++++
#define FILTERSCRIPT

#include <a_samp>
#include <ZCMD>
#include <sscanf2>
#include <y_ini>

#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_WHITE 0xFFFFFFAA
#define price 1000
#define time 600000// 600000 Milisecond = 10 minute, You Can Change It
#define OFF 0
#define ON  1

enum nstation
{
s1,
s2,
s3,
s4,
s5,
}
new station[nstation];
enum posinfo6
{
    Float:posx,
    Float:posy,
    Float:posz,
};
new PosInfo6[posinfo6];
enum posinfo0
{
    Float:posx,
    Float:posy,
    Float:posz,
};
new PosInfo0[MAX_PLAYERS][posinfo0];
enum posinfo1
{
    Float:posx,
    Float:posy,
    Float:posz,
};
new PosInfo1[MAX_PLAYERS][posinfo1];
enum posinfo2
{
    Float:posx,
    Float:posy,
    Float:posz,
};
new PosInfo2[MAX_PLAYERS][posinfo2];
enum posinfo3
{
    Float:posx,
    Float:posy,
    Float:posz,
};
new PosInfo3[MAX_PLAYERS][posinfo3];
new rentcar1[MAX_PLAYERS];
new rentcar2[MAX_PLAYERS];
new rentcar3[MAX_PLAYERS];
new Locked[MAX_PLAYERS], IsLocked[MAX_VEHICLES];
new engine, lights, alarm, doors, bonnet, boot, objective;
new Float:x, Float:y, Float:z;
new timer1;
new timer2;
new timer3;
new slot;
new Float:x1, Float:y1, Float:z1;
new Float:x2, Float:y2, Float:z2;
new Float:x3, Float:y3, Float:z3;
new Float:x4, Float:y4, Float:z4;
new Float:x5, Float:y5, Float:z5;
new file1;

forward car1(playerid);
forward car2(playerid);
forward car3(playerid);
forward load_user_data_basic(playerid, name[], value[]);

public OnFilterScriptInit()
{
        print("\n--------------------------------------");
        print(" Car Rental System by Horrible");
        print("--------------------------------------\n");
        print(" =   = = = =  = == = =  +  =     =    [====");
        print(" = = = =   =  =    =    =  ====) =    [=== ");
        print(" =   = = = =  =    =    =  =---) ==== [==== ");
        print(" ----------------Version 1.4-----------------");
        DisableInteriorEnterExits();
        for(new v = 0; v < MAX_VEHICLES; v++) IsLocked[v] = 0;
        return 1;
}
public OnFilterScriptExit()
{
        print("\n--------------------------------------");
        print(" Car Rental System by Horrible");
        print("--------------------------------------\n");
        print(" =   = = = =  = == = =  +  =     =    [====");
        print(" = = = =   =  =    =    =  ====) =    [=== ");
        print(" =   = = = =  =    =    =  =---) ==== [==== ");
        print(" ----------------Version 1.4-----------------");
        return 1;
}
public OnPlayerConnect(playerid)
{
        INI_ParseFile( "/h-rental/rental.ini", "load_user_data_basic" ,.bExtra = true, .extra = playerid);
        Locked[playerid] = 0;
        return 1;
}
public load_user_data_basic(playerid, name[], value[])
{
    INI_Float("X1", PosInfo6[posx]);
    INI_Float("Y1", PosInfo6[posy]);
    INI_Float("Z1", PosInfo6[posz]);
    station[s1] = CreatePickup(1318, 1, PosInfo6[posx],PosInfo6[posy],PosInfo6[posz], 0);
    return 1;
}
CMD:createrental(playerid, params[])
{
        if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,0xFF0000AA,"You can't use this command.");
        if(sscanf(params, "i", slot)) return SendClientMessage(playerid, COLOR_GREEN, "Usage: /createrental <slot>");
        if(slot < 1 || slot > 5) return SendClientMessage(playerid, COLOR_GREEN, "Invalid slot Id, (1 - 5)");
        if(slot == 1)
        {
        new file;
        file = INI_Open("/h-rental/rental.ini");
        DestroyPickup(station[s1]);
        GetPlayerPos(playerid, x1, y1, z1);
        PosInfo6[posx] = x1;
        PosInfo6[posy] = y1;
        PosInfo6[posz] = z1;
        INI_SetTag(file1, "basic");
        INI_WriteFloat(file1, "X1", PosInfo6[posx]);
        INI_WriteFloat(file1, "Y1", PosInfo6[posy]);
        INI_WriteFloat(file1, "Z1", PosInfo6[posz]);
        station[s1] = CreatePickup(1318, 1, x1,y1,z1, 0);
        INI_Close(file);
        }
return 1;
}
Float saved but can't load (create pickup)
Reply
#7

Quote:
Originally Posted by Horrible
View Post
new code:
pawn Code:
//          +++++++++++++++++++++++++++++++++++++++++++++++++
//          +       Car Rental System by Horrible           +
//          +-----------------------------------------------+
//          +    =   = = = =  = == = =  +  =     =    [==== +
//          +    = = = =   =  =    =    =  ====) =    [===  +
//          +    =   = = = =  =    =    =  =---) ==== [==== +
//          +------------------Version 1.4----------------- +
//          +++++++++++++++++++++++++++++++++++++++++++++++++
#define FILTERSCRIPT

#include <a_samp>
#include <ZCMD>
#include <sscanf2>
#include <y_ini>

#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_WHITE 0xFFFFFFAA
#define price 1000
#define time 600000// 600000 Milisecond = 10 minute, You Can Change It
#define OFF 0
#define ON  1

enum nstation
{
s1,
s2,
s3,
s4,
s5,
}
new station[nstation];
enum posinfo6
{
    Float:posx,
    Float:posy,
    Float:posz,
};
new PosInfo6[posinfo6];
enum posinfo0
{
    Float:posx,
    Float:posy,
    Float:posz,
};
new PosInfo0[MAX_PLAYERS][posinfo0];
enum posinfo1
{
    Float:posx,
    Float:posy,
    Float:posz,
};
new PosInfo1[MAX_PLAYERS][posinfo1];
enum posinfo2
{
    Float:posx,
    Float:posy,
    Float:posz,
};
new PosInfo2[MAX_PLAYERS][posinfo2];
enum posinfo3
{
    Float:posx,
    Float:posy,
    Float:posz,
};
new PosInfo3[MAX_PLAYERS][posinfo3];
new rentcar1[MAX_PLAYERS];
new rentcar2[MAX_PLAYERS];
new rentcar3[MAX_PLAYERS];
new Locked[MAX_PLAYERS], IsLocked[MAX_VEHICLES];
new engine, lights, alarm, doors, bonnet, boot, objective;
new Float:x, Float:y, Float:z;
new timer1;
new timer2;
new timer3;
new slot;
new Float:x1, Float:y1, Float:z1;
new Float:x2, Float:y2, Float:z2;
new Float:x3, Float:y3, Float:z3;
new Float:x4, Float:y4, Float:z4;
new Float:x5, Float:y5, Float:z5;
new file1;

forward car1(playerid);
forward car2(playerid);
forward car3(playerid);
forward load_user_data_basic(playerid, name[], value[]);

public OnFilterScriptInit()
{
        print("\n--------------------------------------");
        print(" Car Rental System by Horrible");
        print("--------------------------------------\n");
        print(" =   = = = =  = == = =  +  =     =    [====");
        print(" = = = =   =  =    =    =  ====) =    [=== ");
        print(" =   = = = =  =    =    =  =---) ==== [==== ");
        print(" ----------------Version 1.4-----------------");
        DisableInteriorEnterExits();
        for(new v = 0; v < MAX_VEHICLES; v++) IsLocked[v] = 0;
        return 1;
}
public OnFilterScriptExit()
{
        print("\n--------------------------------------");
        print(" Car Rental System by Horrible");
        print("--------------------------------------\n");
        print(" =   = = = =  = == = =  +  =     =    [====");
        print(" = = = =   =  =    =    =  ====) =    [=== ");
        print(" =   = = = =  =    =    =  =---) ==== [==== ");
        print(" ----------------Version 1.4-----------------");
        return 1;
}
public OnPlayerConnect(playerid)
{
        INI_ParseFile( "/h-rental/rental.ini", "load_user_data_basic" ,.bExtra = true, .extra = playerid);
        Locked[playerid] = 0;
        return 1;
}
public load_user_data_basic(playerid, name[], value[])
{
    INI_Float("X1", PosInfo6[posx]);
    INI_Float("Y1", PosInfo6[posy]);
    INI_Float("Z1", PosInfo6[posz]);
    station[s1] = CreatePickup(1318, 1, PosInfo6[posx],PosInfo6[posy],PosInfo6[posz], 0);
    return 1;
}
CMD:createrental(playerid, params[])
{
        if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,0xFF0000AA,"You can't use this command.");
        if(sscanf(params, "i", slot)) return SendClientMessage(playerid, COLOR_GREEN, "Usage: /createrental <slot>");
        if(slot < 1 || slot > 5) return SendClientMessage(playerid, COLOR_GREEN, "Invalid slot Id, (1 - 5)");
        if(slot == 1)
        {
        new file;
        file = INI_Open("/h-rental/rental.ini");
        DestroyPickup(station[s1]);
        GetPlayerPos(playerid, x1, y1, z1);
        PosInfo6[posx] = x1;
        PosInfo6[posy] = y1;
        PosInfo6[posz] = z1;
        INI_SetTag(file1, "basic");
        INI_WriteFloat(file1, "X1", PosInfo6[posx]);
        INI_WriteFloat(file1, "Y1", PosInfo6[posy]);
        INI_WriteFloat(file1, "Z1", PosInfo6[posz]);
        station[s1] = CreatePickup(1318, 1, x1,y1,z1, 0);
        INI_Close(file);
        }
return 1;
}
Float saved but can't load (create pickup)
I've warned people about changing stuff. Unless you actually know how it is being used, don't change. Anyways, I don't see any problems with the loading. Let me take another look.
Reply
#8

Quote:
Originally Posted by Kush
View Post
I've warned people about changing stuff. Unless you actually know how it is being used, don't change. Anyways, I don't see any problems with the loading. Let me take another look.
but pickup not create when u turn off and turn on your server i think i got little wrong code
Reply
#9

Few tips:

1. Don't add any other things to the parse function. (Because it gets called multiple times during parse).

pawn Code:
public load_user_data_basic(playerid, name[], value[])
{
    INI_Float("X1", PosInfo6[posx]);
    INI_Float("Y1", PosInfo6[posy]);
    INI_Float("Z1", PosInfo6[posz]);
    //station[s1] = CreatePickup(1318, 1, PosInfo6[posx],PosInfo6[posy],PosInfo6[posz], 0); < Remove this.
    return 1;
}
//This function will call multiple times so creating pickup with it isn't a good idea.

2. Use arrays inside single enum instead of multiple enums.
Example:
pawn Code:
enum posinfo
{
    Float:posx[7],
    Float:posy[7],
    Float:posz[7],
};
new PosInfo[MAX_PLAYERS][posinfo];

//Reduced many lines..

//Usage:
PosInfo[playerid][posx][0] = 51.00; //posinfo0

PosInfo[playerid][posx][2] = 15.00; //posinfo2

PosInfo[playerid][posx][5] = 27.00; //posinfo5
Reply
#10

Quote:
Originally Posted by iPLEOMAX
View Post
Few tips:

1. Don't add any other things to the parse function. (Because it gets called multiple times during parse).

pawn Code:
public load_user_data_basic(playerid, name[], value[])
{
    INI_Float("X1", PosInfo6[posx]);
    INI_Float("Y1", PosInfo6[posy]);
    INI_Float("Z1", PosInfo6[posz]);
    //station[s1] = CreatePickup(1318, 1, PosInfo6[posx],PosInfo6[posy],PosInfo6[posz], 0); < Remove this.
    return 1;
}
//This function will call multiple times so creating pickup with it isn't a good idea.

2. Use arrays inside single enum instead of multiple enums.
Example:
pawn Code:
enum posinfo
{
    Float:posx[7],
    Float:posy[7],
    Float:posz[7],
};
new PosInfo[MAX_PLAYERS][posinfo];

//Reduced many lines..

//Usage:
PosInfo[playerid][posx][0] = 51.00

PosInfo[playerid][posx][2] = 15.00

PosInfo[playerid][posx][5] = 27.00
OK ty i will fix it but where i must place the createpickup?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)