Tested the system on two accounts and it works, just got problems now when the player is in the house and the ID changes.
If I store the houses with a unique ID number they will end up like this when I remove a middle house from the database:
pawn Код:
HouseInfo[0][hHouseID] = 0;
HouseInfo[1][hHouseID] = 1;
HouseInfo[2][hHouseID] = 2;
Say if I deleted house ID 1 and restart the server, it will do this:
pawn Код:
HouseInfo[0][hHouseID] = 0;
HouseInfo[1][hHouseID] = 2;
So if I use commands for the house, it'll show that house ID 1 already exists and recreate number 2.
pawn Код:
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;
}
pawn Код:
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 Код:
stock LoadHouses()
{
mysql_function_query(g_Handle, "SELECT * FROM `Houses`", true, "HousesLoad", "");
return 1;
}
pawn Код:
public HousesLoad()
{
new temp[400], string[200], rows, fields;
cache_get_data(rows, fields, g_Handle);
new id = 0;
if(rows)
{
while(id <= rows-1)
{
HouseInfo[id][hHouseID] = id;
cache_get_row(id, 0, temp, g_Handle), HouseInfo[id][hOldID] = 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);
SaveHouse2(id);
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);
}
CheckObjects(id);
id ++;
}
printf("Houses: %d", rows);
}
else
{
printf("Houses: 0");
}
return 1;
}
pawn Код:
stock SaveHouse2(id)
{
new query[500];
HouseInfo[id][hVirtualWorld] = id+2;
format(query, sizeof(query), "UPDATE `Houses` SET `HouseID` = %d, `Address` = '%s', `Owner` = '%s', `Price` = %d, `EnterX` = %f, `EnterY` = %f, `EnterZ` = %f, `EnterA` = %f, `ExitX` = %f, `ExitY` = %f, `ExitZ` = %f, `ExitA` = %f, `Interior` = %d, VirtualWorld = %d, `Type` = %d, `Lock` = %d, `Safe` = %d, `IsCreated` = %d WHERE `HouseID` = %d",
HouseInfo[id][hHouseID],
HouseInfo[id][hAddress],
HouseInfo[id][hOwner],
HouseInfo[id][hPrice],
HouseInfo[id][hEnterPos][0],
HouseInfo[id][hEnterPos][1],
HouseInfo[id][hEnterPos][2],
HouseInfo[id][hEnterPos][3],
HouseInfo[id][hExitPos][0],
HouseInfo[id][hExitPos][1],
HouseInfo[id][hExitPos][2],
HouseInfo[id][hExitPos][3],
HouseInfo[id][hInterior],
HouseInfo[id][hVirtualWorld],
HouseInfo[id][hType],
HouseInfo[id][hLock],
HouseInfo[id][hSafe],
HouseInfo[id][hIsCreated],
HouseInfo[id][hOldID]
);
mysql_function_query(g_Handle, query, false, "", "");
return 1;
}
Here are the codes if you're able to think of a better way, but everything is working just if I delete a house, enter another one and restart server, it spawns me in the next house down.