Housing Issue With Explanation
#1

Okay, gonna have a hard time explaining this but here we go. When I /createhouse <house id>, it creates like this:

pawn Code:
HouseInfo[0][hHouseID] = 0;
HouseInfo[1][hHouseID] = 1;
HouseInfo[2][hHouseID] = 2;
// And so forth..
If I delete house ID 1 and restart the server, this is what happens:

pawn Code:
HouseInfo[0][hHouseID] = 0;
HouseInfo[1][hHouseID] = 2; // The MAX_HOUSES goes to 1 instead of staying at 2
So when I "/createhouse 2" it overwrites the house and says house ID 1 already exists even know I deleted it..
How do I make it so it does this when I delete the middle house and restart server it loads houses like this:

pawn Code:
HouseInfo[0][hHouseID] = 0;
HouseInfo[2][hHouseID] = 2;
// And so forth..
Here is my /createhouse command and stock:

pawn Code:
CMD:createhouse(playerid, params[])
{
    new Float:pos[4], houseid;
    if(!IsPlayerLoggedIn(playerid))
    {
        SendClientMessage(playerid, COLOR_RED, "Error"White": You are restricted from using commands until you log in.");
        return 1;
    }
    if(PlayerInfo[playerid][pAdminLevel] < 1)
    {
        SendClientMessage(playerid, COLOR_RED, "Error"White": You do not have the authority to use this command.");
        return 1;
    }
    if(!AdminDuty[playerid])
    {
        SendClientMessage(playerid, COLOR_RED, "Error"White": You are not on duty as an Administrator (/aduty).");
        return 1;
    }
    if(sscanf(params, "i", houseid))
    {
        SendClientMessage(playerid, COLOR_GRAY, "");
        SendClientMessage(playerid, COLOR_GRAY, "Usage"White": /createhouse <house id>");
        SendClientMessage(playerid, COLOR_GRAY, "");
        return 1;
    }
    GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
    GetPlayerFacingAngle(playerid, pos[3]);
    CreateHouse(houseid, pos[0], pos[1], pos[2], pos[3], playerid);
    return 1;
}
pawn Code:
stock CreateHouse(houseid, Float:PosX, Float:PosY, Float:PosZ, Float:PosA, playerid)
{
    new string[200], query[400];
   
    if(HouseInfo[houseid][hIsCreated] == 1)
    {
        SendClientMessage(playerid, COLOR_RED, "That house ID already exists.");
        return 1;
    }
   
    HouseInfo[houseid][hHouseID] = houseid;
    HouseInfo[houseid][hEnterPos][0] = PosX;
    HouseInfo[houseid][hEnterPos][1] = PosY;
    HouseInfo[houseid][hEnterPos][2] = PosZ;
    HouseInfo[houseid][hEnterPos][3] = PosA;
    HouseInfo[houseid][hExitPos][0] = 266.9708;
    HouseInfo[houseid][hExitPos][1] = 304.9378;
    HouseInfo[houseid][hExitPos][2] = 999.1484;
    HouseInfo[houseid][hExitPos][3] = 273.4171;
    HouseInfo[houseid][hInterior] = 2;
    HouseInfo[houseid][hVirtualWorld] = houseid+2;
    HouseInfo[houseid][hType] = 1;
    HouseInfo[houseid][hLock] = 0;
    HouseInfo[houseid][hSafe] = -1;
    format(HouseInfo[houseid][hAddress], 32, "1 San Fierro Drive");
    format(HouseInfo[houseid][hOwner], 35, "None");
    HouseInfo[houseid][hPrice] = 120000;
    HouseInfo[houseid][hIsCreated] = 1;

    format(query, sizeof(query), "INSERT INTO `Houses` (`HouseID`, `Address`, `Owner`, `Price`, `EnterX`, `EnterY`, `EnterZ`, `EnterA`, `ExitX`, `ExitY`, `ExitZ`, `ExitA`, `Interior`, `VirtualWorld`, `Type`, `Lock`, `Safe`, `IsCreated`) VALUES (%d, \'%s\', \'%s\', %d, %f, %f, %f, %f, %f, %f, %f, %f, %d, %d, %d, %d, %d, %d)",
    HouseInfo[houseid][hHouseID],
    HouseInfo[houseid][hAddress],
    HouseInfo[houseid][hOwner],
    HouseInfo[houseid][hPrice],
    HouseInfo[houseid][hEnterPos][0],
    HouseInfo[houseid][hEnterPos][1],
    HouseInfo[houseid][hEnterPos][2],
    HouseInfo[houseid][hEnterPos][3],
    HouseInfo[houseid][hExitPos][0],
    HouseInfo[houseid][hExitPos][1],
    HouseInfo[houseid][hExitPos][2],
    HouseInfo[houseid][hExitPos][3],
    HouseInfo[houseid][hInterior],
    HouseInfo[houseid][hVirtualWorld],
    HouseInfo[houseid][hType],
    HouseInfo[houseid][hLock],
    HouseInfo[houseid][hSafe],
    HouseInfo[houseid][hIsCreated]
    );

    mysql_function_query(g_Handle, query, false, "", "");

    HouseInfo[houseid][hPickup] = CreateDynamicPickup(1273, 23, PosX, PosY, PosZ, -1, -1, -1, 100.0);
    format(string, sizeof(string), "Type"White": %s\n"Aqua"Address"White": %s\n"Aqua"Owner"White": %s\n"Aqua"Price"White": $%d\n"Aqua"Status"White": Unlocked", HouseType(houseid), HouseInfo[houseid][hAddress], HouseInfo[houseid][hOwner], HouseInfo[houseid][hPrice]);
    HouseInfo[houseid][hText] = CreateDynamic3DTextLabel(string, COLOR_AQUA, PosX, PosY, PosZ, 25, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, -1, -1, -1, 100);
    format(string, sizeof(string), "%s %s has created house ID %d.", AdminRanks(playerid), Player(playerid), houseid);
    SendAdminMessage(string);
    houseid ++;
    return 1;
}
Here is my code for loading houses:

pawn Code:
stock LoadHouses()
{
    mysql_function_query(g_Handle, "SELECT * FROM `Houses`", true, "HousesLoad", "");
    return 1;
}
pawn Code:
public HousesLoad()
{
    new temp[400], string[200], rows, fields;
    cache_get_data(rows, fields, g_Handle);

    new id = 0;
    if(rows)
    {
        while(id >= 0)
        {
            cache_get_row(id, 0, temp, g_Handle), HouseInfo[id][hHouseID] = strval(temp);
            cache_get_row(id, 1, HouseInfo[id][hAddress], g_Handle, 32);
            cache_get_row(id, 2, HouseInfo[id][hOwner], g_Handle, 35);
            cache_get_row(id, 3, temp, g_Handle), HouseInfo[id][hPrice] = strval(temp);
            cache_get_row(id, 4, temp, g_Handle), HouseInfo[id][hEnterPos][0] = floatstr(temp);
            cache_get_row(id, 5, temp, g_Handle), HouseInfo[id][hEnterPos][1] = floatstr(temp);
            cache_get_row(id, 6, temp, g_Handle), HouseInfo[id][hEnterPos][2] = floatstr(temp);
            cache_get_row(id, 7, temp, g_Handle), HouseInfo[id][hEnterPos][3] = floatstr(temp);
            cache_get_row(id, 8, temp, g_Handle), HouseInfo[id][hExitPos][0] = floatstr(temp);
            cache_get_row(id, 9, temp, g_Handle), HouseInfo[id][hExitPos][1] = floatstr(temp);
            cache_get_row(id, 10, temp, g_Handle), HouseInfo[id][hExitPos][2] = floatstr(temp);
            cache_get_row(id, 11, temp, g_Handle), HouseInfo[id][hExitPos][3] = floatstr(temp);
            cache_get_row(id, 12, temp, g_Handle), HouseInfo[id][hInterior] = strval(temp);
            cache_get_row(id, 13, temp, g_Handle), HouseInfo[id][hVirtualWorld] = strval(temp);
            cache_get_row(id, 14, temp, g_Handle), HouseInfo[id][hType] = strval(temp);
            cache_get_row(id, 15, temp, g_Handle), HouseInfo[id][hLock] = strval(temp);
            cache_get_row(id, 16, temp, g_Handle), HouseInfo[id][hSafe] = strval(temp);
            cache_get_row(id, 17, temp, g_Handle), HouseInfo[id][hIsCreated] = strval(temp);
           
            if(!strcmp("None", HouseInfo[id][hOwner], false))
            {
                HouseInfo[id][hPickup] = CreateDynamicPickup(1273, 23, HouseInfo[id][hEnterPos][0], HouseInfo[id][hEnterPos][1], HouseInfo[id][hEnterPos][2], -1, -1, -1, 100.0);
                format(string, sizeof(string), "Type"White": %s\n"Aqua"Address"White": %s\n"Aqua"Owner"White": None\n"Aqua"Price"White": $%d\n"Aqua"Status"White": Unlocked", HouseType(id), HouseInfo[id][hAddress], HouseInfo[id][hPrice]);
                HouseInfo[id][hText] = CreateDynamic3DTextLabel(string, COLOR_AQUA, HouseInfo[id][hEnterPos][0], HouseInfo[id][hEnterPos][1], HouseInfo[id][hEnterPos][2], 25, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, -1, -1, -1, 100);
            }
            else
            {
                HouseInfo[id][hPickup] = CreateDynamicPickup(1273, 23, HouseInfo[id][hEnterPos][0], HouseInfo[id][hEnterPos][1], HouseInfo[id][hEnterPos][2], -1, -1, -1, 100.0);
                format(string, sizeof(string), "Type"White": %s\n"Aqua"Address"White": %s\n"Aqua"Owner"White": %s\n"Aqua"Status"White": %s", HouseType(id), HouseInfo[id][hAddress], HouseInfo[id][hOwner], HouseStatus(id));
                HouseInfo[id][hText] = CreateDynamic3DTextLabel(string, COLOR_AQUA, HouseInfo[id][hEnterPos][0], HouseInfo[id][hEnterPos][1], HouseInfo[id][hEnterPos][2], 25, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, -1, -1, -1, 100);
            }
            if(HouseInfo[id][hSafe] > 0)
            {
                HouseInfo[id][hSafe] = CreateDynamicObject(2332, 273.93460, 304.21188, 998.54669, 356.85840, 0.00000, 270.00000, HouseInfo[id][hVirtualWorld], HouseInfo[id][hInterior], -1, 300.0);
                SaveHouse(id);
            }
            id ++;
        }
        printf("Houses: %d", rows);
    }
    else
    {
        printf("Houses: 0");
    }
    return 1;
}
If anyone can think of a way through this or even any alternative suggestions please help me.
Reply
#2

When you delete a house, you need to loop through all the houses greater than the deleted house id and subtract 1 from each house id.
Reply
#3

How can I loop through all houses greater than the one deleted?
It always loops through the whole of MAX_HOUSES
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)