Housing Script
#1

Is there an easier way to make a housing script that having one INI file that for instance the following
Код:
house1_name = Beach Hideout
house1_owner = Owner_Name
house1_price = 90000
house1_interior = 3
house2_name = Lake House
house2_owner = Owner_Name
house2_price = 100000
house2_interior = 5
So on and so forth for each and every house? Because then I would have to have 4 lines of code for each possible house number.
pawn Код:
INI_WriteString(myFile, "house1_name", hInfo[1][Name]);
INI_WriteString(myFile, "house1_owner", hInfo[1][Owner]);
INI_WriteInt(myFile, "house1_price", hInfo[1][Price]);
INI_WriteInt(myFile, "house1_interior", hInfo[1][Interior]);
INI_WriteString(myFile, "house2_name", hInfo[2][Name]);
INI_WriteString(myFile, "house2_owner", hInfo[2][Owner]);
INI_WriteInt(myFile, "house2_price", hInfo[2][Price]);
INI_WriteInt(myFile, "house2_interior", hInfo[2][Interior]);
That is just with 2 houses, imagine 20 of them.

Is there a way to have just a folder called "houses" in the scriptfiles folder that, each time a new house is generated, it makes a new text document titled 1.ini, 2.ini, 3.ini so forth, and then scan that folder OnGamemodeInit() for all those and import them? Or do I just have to stick with the way I was doing it above. Also, if you have any other ways or ideas, let me know. Thanks.
Reply
#2

There's plenty of ways to do this.

For example, for my house system, I use:

pawn Код:
stock HousePath(h)
{
    new house[64], hid = h;

    hid = hIDInfo[hID] +1;

    format(house, 30, "Houses/%d.ini", hid);
    hIDInfo[hID] ++; // multiplying

    return house;
}
And it saves them like: http://i.imgsafe.org/4c6fba0.png
Inside the files: http://i.imgsafe.org/74c656e.png

I suggest you to look in how to use Y_INI (******'s thread for example) - or whatever saving system you use. There's also a few house systems released at the filterscript section that process files the way you want it to.

EDIT: Usage example:

pawn Код:
new INI:File = INI_Open(HousePath(h));

INI_SetTag(File, "House Data");

INI_WriteString(File, "Owner", "None");
INI_WriteInt(File, "Price", 25000);
INI_WriteInt(File, "Bought", 0);
Reply
#3

Quote:
Originally Posted by Mionee
Посмотреть сообщение
There's plenty of ways to do this.

For example, for my house system, I use:

pawn Код:
stock HousePath(h)
{
    new house[64], hid = h;

    hid = hIDInfo[hID] +1;

    format(house, 30, "Houses/%d.ini", hid);
    hIDInfo[hID] ++; // multiplying

    return house;
}
And it saves them like: http://i.imgsafe.org/4c6fba0.png
Inside the files: http://i.imgsafe.org/74c656e.png

I suggest you to look in how to use Y_INI (******'s thread for example) - or whatever saving system you use. There's also a few house systems released at the filterscript section that process files the way you want it to.

EDIT: Usage example:

pawn Код:
new INI:File = INI_Open(HousePath(h));

INI_SetTag(File, "House Data");

INI_WriteString(File, "Owner", "None");
INI_WriteInt(File, "Price", 25000);
INI_WriteInt(File, "Bought", 0);
How do you get it OnGamemodeInit to scan for these houses, or do you even have to? To put the house pickup down and a 3Dtextlabel on it.
Reply
#4

You use a loop to loop through all existing files.

This is my LoadHouses(); stock:

pawn Код:
stock LoadHouses()
{
    new hlabel[128], file[64], s[64];

    for(new i = 0; i < 50; i++) Delete3DTextLabel(Text3D: i);

    for(new h = 0; h < MAX_HOUSES; h++)
    {
        format(file, 64, "Houses/%d.ini", h);

        if(fexist(file))
        {
            INI_ParseFile(HousePath(h), "LoadHouseData", false, true, h, true, false );

            format(hlabel, 128, "[HOUSE]\n{46E850}[Owner]{FFFFFF}: %s\n{46E850}[Price]{FFFFFF}: %d", hInfo[h][Owner], hInfo[h][Price]);
            Create3DTextLabel(hlabel, 0xFFFFFF, hInfo[h][extX], hInfo[h][extY], hInfo[h][extZ], 15.0, 0, 1);

            format(s, 64, "  [!!] Loaded house ID: %d at %f %f %f", h, hInfo[h][extX], hInfo[h][extY], hInfo[h][extZ]);
            printf(s);
        }
    }
}
pawn Код:
forward LoadHouseData(h, name[], value[]);
public LoadHouseData(h, name[], value[])
{
    INI_String("Owner", hInfo[h][Owner], 32);
    INI_Int("Price", hInfo[h][Price]);
    INI_Int("Bought", hInfo[h][Bought]);

    INI_Float("extX", hInfo[h][extX]);
    INI_Float("extY", hInfo[h][extY]);
    INI_Float("extZ", hInfo[h][extZ]);

    INI_Float("intX", hInfo[h][intX]);
    INI_Float("intY", hInfo[h][intY]);
    INI_Float("intZ", hInfo[h][intZ]);

    INI_Int("intVW", hInfo[h][intVW]);
    INI_Int("intW", hInfo[h][intW]);
    INI_Int("Locked", hInfo[h][Locked]);

    return 1;
}
Reply
#5

Quote:
Originally Posted by Mionee
Посмотреть сообщение
You use a loop to loop through all existing files.

This is my LoadHouses(); stock:

pawn Код:
stock LoadHouses()
{
    new hlabel[128], file[64], s[64];

    for(new i = 0; i < 50; i++) Delete3DTextLabel(Text3D: i);

    for(new h = 0; h < MAX_HOUSES; h++)
    {
        format(file, 64, "Houses/%d.ini", h);

        if(fexist(file))
        {
            INI_ParseFile(HousePath(h), "LoadHouseData", false, true, h, true, false );

            format(hlabel, 128, "[HOUSE]\n{46E850}[Owner]{FFFFFF}: %s\n{46E850}[Price]{FFFFFF}: %d", hInfo[h][Owner], hInfo[h][Price]);
            Create3DTextLabel(hlabel, 0xFFFFFF, hInfo[h][extX], hInfo[h][extY], hInfo[h][extZ], 15.0, 0, 1);

            format(s, 64, "  [!!] Loaded house ID: %d at %f %f %f", h, hInfo[h][extX], hInfo[h][extY], hInfo[h][extZ]);
            printf(s);
        }
    }
}
pawn Код:
forward LoadHouseData(h, name[], value[]);
public LoadHouseData(h, name[], value[])
{
    INI_String("Owner", hInfo[h][Owner], 32);
    INI_Int("Price", hInfo[h][Price]);
    INI_Int("Bought", hInfo[h][Bought]);

    INI_Float("extX", hInfo[h][extX]);
    INI_Float("extY", hInfo[h][extY]);
    INI_Float("extZ", hInfo[h][extZ]);

    INI_Float("intX", hInfo[h][intX]);
    INI_Float("intY", hInfo[h][intY]);
    INI_Float("intZ", hInfo[h][intZ]);

    INI_Int("intVW", hInfo[h][intVW]);
    INI_Int("intW", hInfo[h][intW]);
    INI_Int("Locked", hInfo[h][Locked]);

    return 1;
}
Is there a limit to how many houses that can be stored this way?
Reply
#6

Quote:
Originally Posted by Nathan_Taylor
Посмотреть сообщение
Is there a limit to how many houses that can be stored this way?
You define how many houses you want to have.

You can see here:

pawn Код:
for(new h = 0; h < MAX_HOUSES; h++)
{
// code
}
I loop through "MAX_HOUSES"' value, which is 100.

pawn Код:
#define MAX_HOUSES 100
It won't loop higher than 100 so any house that has an ID higher than 100 won't get loaded ingame.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)