Reading files
#1

Hi, I'm scripting RP gamemode from scratch and I need some help.
It's about the houses, I want to load many houses, whilst each house has his own file.
For example:
scriptfiles/RP/Houses/
^ This is my files location.

And in the Houses the directory I want to create many files as :
1.ini
2.ini
3.ini
And load them all on OnGameModeInit
How can I load all of them?
I'm using dini btw, but any other include may be nice.
Reply
#2

Look at Antironix housing system. It's exactly what your looking for, and it's easy to add to for newer people to pawn.
Reply
#3

Well it's easier to name the files with a number on each of them. Then, when the script loads, you can use a for loop to see if any of the files exist and load them accordingly. Here's what I'm talking about from a house system I started a while ago.

pawn Код:
for(new i; i<MAX_HOME; i++)
{
        if(houseld <= MAX_HOME)
        {
            format(string,22,"%sHouse%d.hou",HOME_PATH,i);
            if(dini_Exists(string))
            {
HOME_PATH was equal to something like '\Homes\' and the MAX_HOME was 100. Then houseld just got incremented as each house was loaded so that you could set a maximum amount of homes loaded. That doesn't really matter though. Just the formatting of the house file name and the checking if it exists.
Reply
#4

Have something like this:
pawn Код:
stock LoadHouses() // Under OnGameModeInit
{
    for(new i = 1; i < MAX_HOUSES; ++i) // MAX_HOUSES define. Change if needed.
    {
        new
            House_File[15];

        format(House_File, sizeof(House_File), "%d.ini", i); // This will read the files starting from 1

        if(fexist(House_File)) // If the file exists
        {
            // Use dini to load the info and store it into your global variables.
        }
    }
    return 1;
}
I don't know much about your code, but you'll get the idea behind it.
Reply
#5

Not really
Actually I don't want AddHouse etc.
I just want on my gamemodeinit LoadHouses();
Something like that, and I would add houses through a file.

EDIT: Thanks!
Reply
#6

I did as Lethal told to do and it's just not loading my file..
Look:
* I did put it under gamemodeinit
MAX_HOUSES is 100
PHP код:
stock LoadHouses() // Under OnGameModeInit
{
    for(new 
5MAX_HOUSES; ++i)
    {
        new 
House_File[14];
        
format(House_Filesizeof(House_File), "Houses/%d.ini"i);
        if(
fexist(House_File))
        {
        
format(hInfo[i][Owner], 256dini_Get(House_File"Owner"));
        
hInfo[i][Owned] = dini_Int(House_File"Owned");
        
hInfo[i][Price] = dini_Int(House_File"Price");
        
hInfo[i][HouseX] = dini_Float(House_File"HouseX");
        
hInfo[i][HouseY] = dini_Float(House_File"HouseY");
        
hInfo[i][HouseZ] = dini_Float(House_File"HouseZ");
        
hInfo[i][InteriorX] = dini_Float(House_File"InteriorX");
        
hInfo[i][InteriorY] = dini_Float(House_File"InteriorY");
        
hInfo[i][InteriorZ] = dini_Float(House_File"InteriorZ");
        
hInfo[i][Rentable] = dini_Int(House_File"Rentable");
        
hInfo[i][RentPrice] = dini_Int(House_File"RentPrice");
        
hInfo[i][Lock] = dini_Int(House_File"Lock");
        
hInfo[i][Pickup] = CreatePickup(1273,1,hInfo[i][HouseX],hInfo[i][HouseY],hInfo[i][HouseZ],-1);
        print(
"One house loaded");
        
printf("House %d Loaded",i);
        }
    }
    return 
1;

print("One house loaded");
printf("House %d Loaded",i);
this doesn't show up on the log
Reply
#7

help
Reply
#8

bump
Reply
#9

can someone help.
Reply
#10

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)