House System HELP !!!
#1

This is my House System from 0
I dont get what is problem with loading and saving houses,it only loads first house, and when i shut down server the houses.cfg makes some random numbers, and deleting all houses except first one.
pawn Код:
enum hInfo
{
    Float:hEntX,
    Float:hEntY,
    Float:hEntZ,
    hInt,
    Float:hExitX,
    Float:hExitY,
    Float:hExitZ,
    hPickup,
    hOwner[24],
    hPrice,
    hRentPrice,
    hOwned,
    hVehModel,
    Float:hVehX,
    Float:hVehY,
    Float:hVehZ,
    Float:hVehA,
    hLocked,
    hRented
};
new HouseInfo[10][hInfo];
new Iterator:Houses<10>;

public OnGameModeInit()
{
LoadHouses();
   
    foreach(Houses, h)
    {
        if(HouseInfo[h][hOwned] == 1) HouseInfo[h][hPickup] = CreateDynamicPickup(1272, 23, HouseInfo[h][hEntX], HouseInfo[h][hEntY], HouseInfo[h][hEntZ]);
        else if(HouseInfo[h][hOwned] == 0) HouseInfo[h][hPickup] = CreateDynamicPickup(1273, 23, HouseInfo[h][hEntX], HouseInfo[h][hEntY], HouseInfo[h][hEntZ]);
    }
        return true;
}

public LoadHouses()
{
    new strFromFile2[256];
    new File: file = fopen("IGRP/houses.cfg", io_read);
    if(file)
    {
        Iter_Add(Houses, 1);
        Iter_Add(Houses, 1);
        Iter_Add(Houses, 1);
        Iter_Add(Houses, 1);
        Iter_Add(Houses, 1);
        Iter_Add(Houses, 1);
        Iter_Add(Houses, 1);
        Iter_Add(Houses, 1);
        Iter_Add(Houses, 1);
        foreach(Houses, idx)
        {
            fread(file, strFromFile2);
            sscanf(strFromFile2, "p<,>fffifffis[24]iiiiiiffff",
            HouseInfo[idx][hEntX],
            HouseInfo[idx][hEntY],
            HouseInfo[idx][hEntZ],
            HouseInfo[idx][hInt],
            HouseInfo[idx][hExitX],
            HouseInfo[idx][hExitY],
            HouseInfo[idx][hExitZ],
            HouseInfo[idx][hPickup],
            HouseInfo[idx][hOwner],
            HouseInfo[idx][hPrice],
            HouseInfo[idx][hRentPrice],
            HouseInfo[idx][hOwned],
            HouseInfo[idx][hLocked],
            HouseInfo[idx][hRented],
            HouseInfo[idx][hVehModel],
            HouseInfo[idx][hVehX],
            HouseInfo[idx][hVehY],
            HouseInfo[idx][hVehZ],
            HouseInfo[idx][hVehA]);
            if(IsValidVehicleModel(HouseInfo[idx][hVehModel]))
            {
                CreateVehicle(HouseInfo[idx][hVehModel], HouseInfo[idx][hVehX], HouseInfo[idx][hVehY], HouseInfo[idx][hVehZ], HouseInfo[idx][hVehA], -1, -1, -1);
            }
        }
        fclose(file);
    }
    return true;
}

public SaveHouses()
{
    new
        coordsstring[256],
        File: File;

    printf("Owner: %s", HouseInfo[1][hOwner]);
    foreach(Houses, idx)
    {
        format(coordsstring, 256, "%f,%f,%f,%i,%f,%f,%i,s%,%i,%i,%i,%i,%i,%i,%f,%f,%f,%f",
        HouseInfo[idx][hEntX],
        HouseInfo[idx][hEntY],
        HouseInfo[idx][hEntZ],
        HouseInfo[idx][hInt],
        HouseInfo[idx][hExitX],
        HouseInfo[idx][hExitY],
        HouseInfo[idx][hExitZ],
        HouseInfo[idx][hPickup],
        HouseInfo[idx][hOwner],
        HouseInfo[idx][hPrice],
        HouseInfo[idx][hRentPrice],
        HouseInfo[idx][hOwned],
        HouseInfo[idx][hLocked],
        HouseInfo[idx][hRented],
        HouseInfo[idx][hVehModel],
        HouseInfo[idx][hVehX],
        HouseInfo[idx][hVehY],
        HouseInfo[idx][hVehZ],
        HouseInfo[idx][hVehA]);
        if(idx == 1)
        {
            File = fopen("IGRP/houses.cfg", io_write);
        }
        else
        {
            File = fopen("IGRP/houses.cfg", io_append);
        }
        fwrite(File, coordsstring);
        fclose(File);
    }
    return true;
}
Reply
#2

I really need help! :S
Reply
#3

***BUMP***
Reply
#4

Код:
foreach(Houses, h)
That's not really how foreach is used in Pawno..

Try..

Код:
while(idx < sizeof(HouseInfo))
{

//ADD THIS AT THE END:
idx++;
}
almost forgot, I noticed you didnt add a
Код:
new idx;
Add that too.

EDIT#2:

lol 666th post
Reply
#5

I replaced it but i get errors...

And i dont think it will work.
Reply
#6

If your house count is limited try using:

Код:
for(new i = 0; i < sizeof(HouseInfo); i++)
{
 // Load/Save your houses
}
Hope it helps.
Reply
#7

Quote:
Originally Posted by coole210
Посмотреть сообщение
Код:
foreach(Houses, h)
That's not really how foreach is used in Pawno..
Have you been living in the stone age? https://sampforum.blast.hk/showthread.php?tid=92679

Quote:
Originally Posted by black_dota
Посмотреть сообщение
pawn Код:
Iter_Add(Houses, 1);
        Iter_Add(Houses, 1);
        Iter_Add(Houses, 1);
        Iter_Add(Houses, 1);
        Iter_Add(Houses, 1);
        Iter_Add(Houses, 1);
        Iter_Add(Houses, 1);
        Iter_Add(Houses, 1);
        Iter_Add(Houses, 1);
I'm not really familiar with foreach, but that's obviously not how it's supposed to work. I suggest you carefully read the topic I linked above.
Reply
#8

I tried all but still not fixed problem :S
Reply
#9

BUMP!
Reply
#10

Try to download my include: sasi-houses, wich it has House + Business system. You can find it on the "Filterscripts and Includes" forum, or just in this link: Go to the thread

It's very advanced, with one line you add a house or a business, and it's easy to edit! With one define you can change the language!! To add houses with my include you just have to do: CreateHouse(houseid, Float:eX, Float:eY, Float:eZ, Float:iX, Float:iY, Float:iZ, BuyPrice, SellPrice, INT, VW)

and you can add business by doing: CreateBusiness(bizid, defaultname[24], Float:eX, Float:eY, Float:eZ, Float:iX, Float:iY, Float:iZ, BuyPrice, SellPrice, Earn, INT, VW)


I'm making a new version, that will be released in a few days
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)