SA-MP Forums Archive
House system only loading 1 house. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: House system only loading 1 house. (/showthread.php?tid=319091)



House system only loading 1 house. - ricardo178 - 17.02.2012

Hello guys. Well, i created a dynamic house system. It creates all right, but when i restart server it only loads the first house.. I made it same way as vehicle system, but vehicles load and this one doesn't.

The codes:

The OnGameModeInit() Load part:

pawn Код:
for(new h = 1; h < sizeof(HouseInfo); h++)
    {
        format(file, sizeof(file), "RRP/houses/%d.ini", h);
        if(fexist(file))
        {
            if(HouseInfo[h][Owner] == 0)
            {
                new string[128];
                housepickup[h] = CreatePickup(1273, 1, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 0);
                format(string, sizeof(string), "This house is for sale. Use /buyhouse to buy it. Price: %d", HouseInfo[h][Price]);
                housetext[h] = Create3DTextLabel(string, COLOR_RED, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 10.0, 0);
            }
            else
            {
                new string[128];
                housepickup[h] = CreatePickup(1273, 1, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 0);
                format(string, sizeof(string), "This house is owned by %s.", HouseInfo[h][Owner]);
                housetext[h] = Create3DTextLabel(string, COLOR_RED, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 10.0, 0);
            }
        }
        return 1;
    }
    return 1;
Whole OnGameModeInit:
pawn Код:
public OnGameModeInit()
{
    SetGameModeText("RRP v0.01");
    AddPlayerClass(0, 1958.33, 1343.12, 15.36, 269.15, 26, 36, 28, 150, 0, 0);
    LoadServerInfo();
    LoadVehiclesInfo();
    LoadVehicles();
    for(new h = 1; h < sizeof(CarInfo); h++)
    {
        format(file, sizeof(file), "RRP/vehicles/%d.ini", h);
        if(fexist(file))
        {
            if(CarInfo[h][Owner] == 0)
            {
                new string[128];
                CreateVehicle(CarInfo[h][Model], CarInfo[h][X], CarInfo[h][Y], CarInfo[h][Z], CarInfo[h][A], CarInfo[h][Color1], CarInfo[h][Color2], 86400);
                format(string, sizeof(string), "This vehicle is for sale. Use /buycar to buy it. Price: %d", CarInfo[h][Price]);
                dealercar[h] = Create3DTextLabel(string, COLOR_RED, CarInfo[h][X], CarInfo[h][Y], CarInfo[h][Z], 10.0, 0, 0);
            }
            else CreateVehicle(CarInfo[h][Model], CarInfo[h][X], CarInfo[h][Y], CarInfo[h][Z], CarInfo[h][A], CarInfo[h][Color1], CarInfo[h][Color2], 86400);
        }
    }
    LoadHousesInfo();
    LoadHouses();
    for(new h = 1; h < sizeof(HouseInfo); h++)
    {
        format(file, sizeof(file), "RRP/houses/%d.ini", h);
        if(fexist(file))
        {
            if(HouseInfo[h][Owner] == 0)
            {
                new string[128];
                housepickup[h] = CreatePickup(1273, 1, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 0);
                format(string, sizeof(string), "This house is for sale. Use /buyhouse to buy it. Price: %d", HouseInfo[h][Price]);
                housetext[h] = Create3DTextLabel(string, COLOR_RED, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 10.0, 0);
            }
            else
            {
                new string[128];
                housepickup[h] = CreatePickup(1273, 1, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 0);
                format(string, sizeof(string), "This house is owned by %s.", HouseInfo[h][Owner]);
                housetext[h] = Create3DTextLabel(string, COLOR_RED, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 10.0, 0);
            }
        }
        return 1;
    }
    return 1;
}
Create house cmd:
pawn Код:
CMD:createhouse(playerid, params[])
{
    new Float:px, Float:py, Float:pz, hprice, hint, string[128];
    GetPlayerPos(playerid, px, py, pz);
    if(!sscanf(params, "ii", hint, hprice))
    {
        new hid;
        hid = Houses[topnumber]+1;
        new vwid;
        vwid = Houses[vwtopnumber]+1;
        if(hint == 1)
        {
            format(file, sizeof(file), "RRP/houses/%d.ini", hid);
            dini_Create(file);
            dini_FloatSet(file, "X", Float:px);
            dini_FloatSet(file, "Y", Float:py);
            dini_FloatSet(file, "Z", Float:pz);
            dini_IntSet(file, "Price", hprice);
            dini_IntSet(file, "Int", hint);
            dini_IntSet(file, "Owner", 0);
            dini_IntSet(file, "Lock", 0);
            dini_FloatSet(file, "IntX", 223.043991);
            dini_FloatSet(file, "IntY", 1289.259888);
            dini_FloatSet(file, "IntZ", 1082.199951);
            dini_IntSet(file, "Vw", vwid);
            LoadHouses();
            housepickup[hid] = CreatePickup(1273, 1, Float:px, Float:py, Float:pz, 0);
            format(string, sizeof(string), "This house is for sale. Use /buyhouse to buy it. Price: %d", hprice);
            housetext[hid] = Create3DTextLabel(string, COLOR_RED, Float:px, Float:py, Float:pz, 10.0, 0);
            Houses[topnumber] = Houses[topnumber]+1;
            Houses[vwtopnumber] = Houses[vwtopnumber]+1;
        }
        if(hint == 2)
        {
            format(file, sizeof(file), "RRP/houses/%d.ini", hid);
            dini_Create(file);
            dini_FloatSet(file, "X", Float:px);
            dini_FloatSet(file, "Y", Float:py);
            dini_FloatSet(file, "Z", Float:pz);
            dini_IntSet(file, "Price", hprice);
            dini_IntSet(file, "Int", hint);
            dini_IntSet(file, "Owner", 0);
            dini_IntSet(file, "Lock", 0);
            dini_FloatSet(file, "IntX", 225.756989);
            dini_FloatSet(file, "IntY", 1240.000000);
            dini_FloatSet(file, "IntZ", 1082.149902);
            dini_IntSet(file, "Vw", vwid);
            LoadHouses();
            housepickup[hid] = CreatePickup(1273, 1, Float:px, Float:py, Float:pz, 0);
            format(string, sizeof(string), "This house is for sale. Use /buyhouse to buy it. Price: %d", hprice);
            housetext[hid] = Create3DTextLabel(string, COLOR_RED, Float:px, Float:py, Float:pz, 10.0, 0);
            Houses[topnumber] = Houses[topnumber]+1;
            Houses[vwtopnumber] = Houses[vwtopnumber]+1;
        }
        if(hint == 3)
        {
            format(file, sizeof(file), "RRP/houses/%d.ini", hid);
            dini_Create(file);
            dini_FloatSet(file, "X", Float:px);
            dini_FloatSet(file, "Y", Float:py);
            dini_FloatSet(file, "Z", Float:pz);
            dini_IntSet(file, "Price", hprice);
            dini_IntSet(file, "Int", hint);
            dini_IntSet(file, "Owner", 0);
            dini_IntSet(file, "Lock", 0);
            dini_FloatSet(file, "IntX", 235.508994);
            dini_FloatSet(file, "IntY", 1189.169897);
            dini_FloatSet(file, "IntZ", 1080.339966);
            dini_IntSet(file, "Vw", vwid);
            LoadHouses();
            housepickup[hid] = CreatePickup(1273, 1, Float:px, Float:py, Float:pz, 0);
            format(string, sizeof(string), "This house is for sale. Use /buyhouse to buy it. Price: %d", hprice);
            housetext[hid] = Create3DTextLabel(string, COLOR_RED, Float:px, Float:py, Float:pz, 10.0, 0);
            Houses[topnumber] = Houses[topnumber]+1;
            Houses[vwtopnumber] = Houses[vwtopnumber]+1;
        }
        if(hint == 5)
        {
            format(file, sizeof(file), "RRP/houses/%d.ini", hid);
            dini_Create(file);
            dini_FloatSet(file, "X", Float:px);
            dini_FloatSet(file, "Y", Float:py);
            dini_FloatSet(file, "Z", Float:pz);
            dini_IntSet(file, "Price", hprice);
            dini_IntSet(file, "Int", hint);
            dini_IntSet(file, "Owner", 0);
            dini_IntSet(file, "Lock", 0);
            dini_FloatSet(file, "IntX", 1299.14);
            dini_FloatSet(file, "IntY", -794.77);
            dini_FloatSet(file, "IntZ", 1084.00);
            dini_IntSet(file, "Vw", vwid);
            LoadHouses();
            housepickup[hid] = CreatePickup(1273, 1, Float:px, Float:py, Float:pz, 0);
            format(string, sizeof(string), "This house is for sale. Use /buyhouse to buy it. Price: %d", hprice);
            housetext[hid] = Create3DTextLabel(string, COLOR_RED, Float:px, Float:py, Float:pz, 10.0, 0);
            Houses[topnumber] = Houses[topnumber]+1;
            Houses[vwtopnumber] = Houses[vwtopnumber]+1;
        }
        if(hint == 7)
        {
            format(file, sizeof(file), "RRP/houses/%d.ini", hid);
            dini_Create(file);
            dini_FloatSet(file, "X", Float:px);
            dini_FloatSet(file, "Y", Float:py);
            dini_FloatSet(file, "Z", Float:pz);
            dini_IntSet(file, "Price", hprice);
            dini_IntSet(file, "Int", hint);
            dini_IntSet(file, "Owner", 0);
            dini_IntSet(file, "Lock", 0);
            dini_FloatSet(file, "IntX", 225.630997);
            dini_FloatSet(file, "IntY", 1022.479980);
            dini_FloatSet(file, "IntZ", 1084.069946);
            dini_IntSet(file, "Vw", vwid);
            LoadHouses();
            housepickup[hid] = CreatePickup(1273, 1, Float:px, Float:py, Float:pz, 0);
            format(string, sizeof(string), "This house is for sale. Use /buyhouse to buy it. Price: %d", hprice);
            housetext[hid] = Create3DTextLabel(string, COLOR_RED, Float:px, Float:py, Float:pz, 10.0, 0);
            Houses[topnumber] = Houses[topnumber]+1;
            Houses[vwtopnumber] = Houses[vwtopnumber]+1;
        }
        if(hint == 8)
        {
            format(file, sizeof(file), "RRP/houses/%d.ini", hid);
            dini_Create(file);
            dini_FloatSet(file, "X", Float:px);
            dini_FloatSet(file, "Y", Float:py);
            dini_FloatSet(file, "Z", Float:pz);
            dini_IntSet(file, "Price", hprice);
            dini_IntSet(file, "Int", hint);
            dini_IntSet(file, "Owner", 0);
            dini_IntSet(file, "Lock", 0);
            dini_FloatSet(file, "IntX", 2365.42);
            dini_FloatSet(file, "IntY", -1131.85);
            dini_FloatSet(file, "IntZ", 1050.88);
            dini_IntSet(file, "Vw", vwid);
            LoadHouses();
            housepickup[hid] = CreatePickup(1273, 1, Float:px, Float:py, Float:pz, 0);
            format(string, sizeof(string), "This house is for sale. Use /buyhouse to buy it. Price: %d", hprice);
            housetext[hid] = Create3DTextLabel(string, COLOR_RED, Float:px, Float:py, Float:pz, 10.0, 0);
            Houses[topnumber] = Houses[topnumber]+1;
            Houses[vwtopnumber] = Houses[vwtopnumber]+1;
        }
        if(hint == 10)
        {
            format(file, sizeof(file), "RRP/houses/%d.ini", hid);
            dini_Create(file);
            dini_FloatSet(file, "X", Float:px);
            dini_FloatSet(file, "Y", Float:py);
            dini_FloatSet(file, "Z", Float:pz);
            dini_IntSet(file, "Price", hprice);
            dini_IntSet(file, "Int", hint);
            dini_IntSet(file, "Owner", 0);
            dini_IntSet(file, "Lock", 0);
            dini_FloatSet(file, "IntX", 2260.76);
            dini_FloatSet(file, "IntY", -1210.45);
            dini_FloatSet(file, "IntZ", 1049.02);
            dini_IntSet(file, "Vw", vwid);
            LoadHouses();
            housepickup[hid] = CreatePickup(1273, 1, Float:px, Float:py, Float:pz, 0);
            format(string, sizeof(string), "This house is for sale. Use /buyhouse to buy it. Price: %d", hprice);
            housetext[hid] = Create3DTextLabel(string, COLOR_RED, Float:px, Float:py, Float:pz, 10.0, 0);
            Houses[topnumber] = Houses[topnumber]+1;
            Houses[vwtopnumber] = Houses[vwtopnumber]+1;
        }
        format(file, sizeof(file), "RRP/houses/Hindex.ini");
        if(fexist(file))
        {
            dini_IntSet(file, "topnumber", Houses[topnumber]);
            dini_IntSet(file, "vwtopnumber", Houses[vwtopnumber]);
        }
        return 1;
    }
    else
    {
        SendClientMessage(playerid, COLOR_DARKGOLD, "USAGE: /createhouse [Interior] [Price]");
        SendClientMessage(playerid, COLOR_DARKGOLD, "||Interiors|| Madd Doggs: 5 || Very Largue: 7 || Largue: 3 || Medium: 2 || Small: 1 || Very Small: 7 || CJ House: 3 || Verdant Bluffs: 8 || Hashbury: 10");
        return 1;
    }
}
OnGameModeExit:
pawn Код:
public OnGameModeExit()
{
    SaveServerInfo();
    SaveVehicles();
    SaveHousesInfo();
    SaveHouses();
    return 1;
}
Load and Save houses and house info:
pawn Код:
//LoadHousesInfo
forward LoadHousesInfo();
public LoadHousesInfo()
{
    format(file, sizeof(file), "RRP/houses/Hindex.ini");
    if(fexist(file))
    {
        Houses[topnumber] = dini_Int(file, "topnumber");
    }
    return 1;
}
//LoadHouses
forward LoadHouses();
public LoadHouses()
{
    for(new i = 1; i < sizeof(HouseInfo); i++)
    {
        format(file, sizeof(file), "RRP/houses/%d.ini", i);
        if(fexist(file))
        {
            HouseInfo[i][X] = dini_Int(file, "X");
            HouseInfo[i][Y] = dini_Int(file, "Y");
            HouseInfo[i][Z] = dini_Int(file, "Z");
            HouseInfo[i][Int] = dini_Int(file, "Int");
            HouseInfo[i][Vw] = dini_Int(file, "Vw");
            HouseInfo[i][Owner] = dini_Int(file, "Owner");
            HouseInfo[i][Lock] = dini_Int(file, "Lock");
            HouseInfo[i][Price] = dini_Int(file, "Price");
        }
        return 1;
    }
    print("[RRP]: Houses Loadeds");
    return 1;
}
//Save Houses
forward SaveHouses();
public SaveHouses()
{
    for(new i = 1; i < sizeof(CarInfo); i++)
    {
        format(file, sizeof(file), "RRP/houses/%d", i);
        if(fexist(file))
        {
            dini_IntSet(file, "X", HouseInfo[i][X]);
            dini_IntSet(file, "Y", HouseInfo[i][Y]);
            dini_IntSet(file, "Z", HouseInfo[i][Z]);
            dini_IntSet(file, "Int", HouseInfo[i][Int]);
            dini_IntSet(file, "Vw", HouseInfo[i][Vw]);
            dini_IntSet(file, "Owner", HouseInfo[i][Owner]);
            dini_IntSet(file, "Lock", HouseInfo[i][Lock]);
            dini_IntSet(file, "Price", HouseInfo[i][Price]);
        }
    }
    return 1;
}
forward SaveHousesInfo();
public SaveHousesInfo()
{
    format(file, sizeof(file), "RRP/houses/Hindex.ini");
    if(fexist(file))
    {
        dini_IntSet(file, "topnumber", Houses[topnumber]);
        dini_IntSet(file, "vwtopnumber", Houses[vwtopnumber]);
    }
    return 1;
}
Thank you.
It actualy has 5 house files(5 houses) annd only creates the first one.


Re: House system only loading 1 house. - TheGamer! - 17.02.2012

I think the problem is that you returned in 'for'
pawn Код:
for(new h = 1; h < sizeof(HouseInfo); h++)
    {
        format(file, sizeof(file), "RRP/houses/%d.ini", h);
        if(fexist(file))
        {
            if(HouseInfo[h][Owner] == 0)
            {
                new string[128];
                housepickup[h] = CreatePickup(1273, 1, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 0);
                format(string, sizeof(string), "This house is for sale. Use /buyhouse to buy it. Price: %d", HouseInfo[h][Price]);
                housetext[h] = Create3DTextLabel(string, COLOR_RED, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 10.0, 0);
            }
            else
            {
                new string[128];
                housepickup[h] = CreatePickup(1273, 1, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 0);
                format(string, sizeof(string), "This house is owned by %s.", HouseInfo[h][Owner]);
                housetext[h] = Create3DTextLabel(string, COLOR_RED, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 10.0, 0);
            }
        }
        [b][u]return 1;[/u][/b]
    }
    return 1;



Re: House system only loading 1 house. - milanosie - 17.02.2012

pawn Код:
{
    for(new i = 1; i < sizeof(HouseInfo); i++)
    {
        format(file, sizeof(file), "RRP/houses/%d.ini", i);
        if(fexist(file))
        {
            HouseInfo[i][X] = dini_Int(file, "X");
            HouseInfo[i][Y] = dini_Int(file, "Y");
            HouseInfo[i][Z] = dini_Int(file, "Z");
            HouseInfo[i][Int] = dini_Int(file, "Int");
            HouseInfo[i][Vw] = dini_Int(file, "Vw");
            HouseInfo[i][Owner] = dini_Int(file, "Owner");
            HouseInfo[i][Lock] = dini_Int(file, "Lock");
            HouseInfo[i][Price] = dini_Int(file, "Price");
        }
    }
    print("[RRP]: Houses Loadeds");
    return 1;
Remove the return 1;


do NOT use return INSIDE the looping!


Re : House system only loading 1 house. - ricardo178 - 17.02.2012

Still doesn't work... In the files, all save as it should. Create the right files, all that.
The problem is on loading, it only load the first house, that is the file "1.ini"...


Re : House system only loading 1 house. - ricardo178 - 18.02.2012

Bump.

Reason for bump before the 48h: You all know that a thread in the 4° page is forgeten and no-one will see it anymore. I really need help.


Re: House system only loading 1 house. - DaRkM - 18.02.2012

pawn Код:
for(new h = 1; h < sizeof(HouseInfo); h++)
    {
        format(file, sizeof(file), "RRP/houses/%d.ini", h);
        if(fexist(file))
        {
            if(HouseInfo[h][Owner] == 0)
            {
                new string[128];
                housepickup[h] = CreatePickup(1273, 1, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 0);
                format(string, sizeof(string), "This house is for sale. Use /buyhouse to buy it. Price: %d", HouseInfo[h][Price]);
                housetext[h] = Create3DTextLabel(string, COLOR_RED, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 10.0, 0);
            }
            else
            {
                new string[128];
                housepickup[h] = CreatePickup(1273, 1, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 0);
                format(string, sizeof(string), "This house is owned by %s.", HouseInfo[h][Owner]);
                housetext[h] = Create3DTextLabel(string, COLOR_RED, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 10.0, 0);
            }
        }
    }
    return 1;
pawn Код:
//LoadHouses
forward LoadHouses();
public LoadHouses()
{
    for(new i = 1; i < sizeof(HouseInfo); i++)
    {
        format(file, sizeof(file), "RRP/houses/%d.ini", i);
        if(fexist(file))
        {
            HouseInfo[i][X] = dini_Int(file, "X");
            HouseInfo[i][Y] = dini_Int(file, "Y");
            HouseInfo[i][Z] = dini_Int(file, "Z");
            HouseInfo[i][Int] = dini_Int(file, "Int");
            HouseInfo[i][Vw] = dini_Int(file, "Vw");
            HouseInfo[i][Owner] = dini_Int(file, "Owner");
            HouseInfo[i][Lock] = dini_Int(file, "Lock");
            HouseInfo[i][Price] = dini_Int(file, "Price");
        }
    }
    print("[RRP]: Houses Loadeds");
    return 1;
}



Re : Re: House system only loading 1 house. - ricardo178 - 18.02.2012

Quote:
Originally Posted by DaRkM
Посмотреть сообщение
pawn Код:
for(new h = 1; h < sizeof(HouseInfo); h++)
    {
        format(file, sizeof(file), "RRP/houses/%d.ini", h);
        if(fexist(file))
        {
            if(HouseInfo[h][Owner] == 0)
            {
                new string[128];
                housepickup[h] = CreatePickup(1273, 1, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 0);
                format(string, sizeof(string), "This house is for sale. Use /buyhouse to buy it. Price: %d", HouseInfo[h][Price]);
                housetext[h] = Create3DTextLabel(string, COLOR_RED, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 10.0, 0);
            }
            else
            {
                new string[128];
                housepickup[h] = CreatePickup(1273, 1, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 0);
                format(string, sizeof(string), "This house is owned by %s.", HouseInfo[h][Owner]);
                housetext[h] = Create3DTextLabel(string, COLOR_RED, HouseInfo[h][X], HouseInfo[h][Y], HouseInfo[h][Z], 10.0, 0);
            }
        }
    }
    return 1;
pawn Код:
//LoadHouses
forward LoadHouses();
public LoadHouses()
{
    for(new i = 1; i < sizeof(HouseInfo); i++)
    {
        format(file, sizeof(file), "RRP/houses/%d.ini", i);
        if(fexist(file))
        {
            HouseInfo[i][X] = dini_Int(file, "X");
            HouseInfo[i][Y] = dini_Int(file, "Y");
            HouseInfo[i][Z] = dini_Int(file, "Z");
            HouseInfo[i][Int] = dini_Int(file, "Int");
            HouseInfo[i][Vw] = dini_Int(file, "Vw");
            HouseInfo[i][Owner] = dini_Int(file, "Owner");
            HouseInfo[i][Lock] = dini_Int(file, "Lock");
            HouseInfo[i][Price] = dini_Int(file, "Price");
        }
    }
    print("[RRP]: Houses Loadeds");
    return 1;
}
What you changed?


Re : House system only loading 1 house. - ricardo178 - 18.02.2012

Well it works. thank you but please tell me what you changed cos i don't get it.. +rep


Re: House system only loading 1 house. - DaRkM - 19.02.2012

Just removed the returns inside the for loops.