Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate houses/apartments from qb-houses/qb-apartments #89

Merged
merged 11 commits into from
Aug 22, 2023
Merged
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ end)

10. Install the dependencies below.

## Migrating houses and apartments from qb-houses and qb-apartments

1. From a client run the `migratehouses` command to automatically convert all houses from qb-houses. It will print a message to the console once complete.
**The `migratehouses` command MUST be run from a client in order to retrieve street and region data for each house**

2. From a client or server console run the `migrateapartments` command to automatically convert all apartments from qb-apartments. It will print a message to the console once complete.

## Item Limits System

1. Choose an item you want to limit under `Config.Furniture` in under `shared/config.lua`
Expand Down
11 changes: 11 additions & 0 deletions client/migrate.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
RegisterCommand("migratehouses", function()
BackSH00TER marked this conversation as resolved.
Show resolved Hide resolved
TriggerServerEvent('ps-housing:server:migratehouses')
end)


lib.callback.register('ps-housing:client:getclientdata', function(data)
return {
street = GetStreetNameFromHashKey(GetStreetNameAtCoord(data.coords.x, data.coords.y, data.coords.z)),
region = GetLabelText(GetNameOfZone(data.coords.x, data.coords.y, data.coords.z))
}
end)
2 changes: 2 additions & 0 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ client_script {
'client/cl_property.lua',
'client/client.lua',
'client/modeler.lua',
'client/migrate.lua'
}

server_script {
'@oxmysql/lib/MySQL.lua',
"server/sv_property.lua",
"server/server.lua",
"server/migrate.lua"
}

files {
Expand Down
121 changes: 105 additions & 16 deletions server/migrate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,123 @@ local AptNames = {
["apartment2"] = "Morningwood Blvd",
["apartment3"] = "Integrity Way",
["apartment4"] = "Tinsel Towers",
["apartment5"] = "Fantastic Plaza"
["apartment5"] = "Fantastic Plaza",
}

local Shells = {
[1] = `shell_v16low`,
[2] = `shell_v16mid`,
[3] = `shell_trevor`,
[4] = `shell_trailer`,
[5] = `shell_lester`,
[6] = `shell_ranch`,
[7] = `container_shell`,
[8] = `furnitured_midapart`,
[9] = `modernhotel_shell`,
[10] = `shell_frankaunt`,
[11] = `shell_garagem`,
[12] = `shell_michael`,
[13] = `shell_office1`,
[14] = `shell_store1`,
[15] = `shell_warehouse1`
}


RegisterCommand("housingmigrate", function()
RegisterCommand("migrateapartments", function()

local properties = {}

local qbApt = MySQL.Sync.fetchAll("SELECT * FROM apartments")

for i = 1, #qbApt do
local apt = qbApt[i]

local aptName = AptNames[apt.type]
local data = {
owner_citizenid = apt.citizenid,
label = aptName .. " Apartment " .. tostring(i),
description = "This is " .. aptName .. " Apartment " .. tostring(i),
shell = Config.Apartments[aptName].shell,
apartment = aptName,
}
CreateThread(function()
for i = 1, #qbApt do
local apt = qbApt[i]

local aptName = AptNames[apt.type]
local propertyData = {
owner = apt.citizenid,
label = aptName .. " Apartment " .. tostring(i),
description = "This is " .. aptName .. " Apartment " .. tostring(i),
for_sale = 0,
shell = Config.Apartments[aptName].shell,
apartment = aptName,
}

TriggerEvent("ps-housing:server:registerProperty", propertyData)
end
print("Finished migrating apartments")
end)
end, true)

RegisterNetEvent('ps-housing:server:migratehouses', function()
if not source or source == 0 then return end
local src = source
local qbHouses = MySQL.Sync.fetchAll("SELECT * FROM player_houses")
local qbHouseLocations = MySQL.Sync.fetchAll("SELECT * FROM houselocations")

local formattedHouses = {}
for _,v in pairs(qbHouses) do
formattedHouses[v.house] = v
end

local qbHouses = MySQL.Sync.fetchAll("SELECT * FROM houses")
CreateThread(function()
for i = 1, #qbHouseLocations do
local house = qbHouseLocations[i]
local ownedHouse = formattedHouses[house.name]
local owner = ownedHouse and ownedHouse.citizenid
local sale = 0
local keyholders = ownedHouse and json.decode(ownedHouse.keyholders) or {}
if not ownedHouse then
sale = 1
end

local houseCoords = json.decode(house.coords)
local clientData = lib.callback.await("ps-housing:client:getclientdata", src, {coords = houseCoords.enter})

local door = {
x = math.floor(houseCoords.enter.x * 10000) / 10000,
y = math.floor(houseCoords.enter.y * 10000) / 10000,
z = math.floor(houseCoords.enter.z * 10000) / 10000,
h = math.floor(houseCoords.enter.h * 10000) / 10000,
length = 1.5,
width = 2.2,
locked = true
}

local garageCoords = json.decode(house.garage)
local garage = nil
if garageCoords then
garage = {
x = math.floor(garageCoords.x * 10000) / 10000,
y = math.floor(garageCoords.y * 10000) / 10000,
z = math.floor(garageCoords.z * 10000) / 10000,
h = math.floor(garageCoords.h * 10000) / 10000,
length = 3.0,
width = 5.0,
}
end

local shell = "Apartment Unfurnished"
for k,v in pairs(Config.Shells) do
if v.hash == Shells[house.tier] then
shell = k
end
end

local propertyData = {
owner = owner,
street = clientData.street,
region = clientData.region,
description = house.label,
has_access = keyholders,
for_sale = sale,
price = house.price,
shell = shell,
door_data = door,
garage_data = garage
}

end, true)
TriggerEvent("ps-housing:server:registerProperty", propertyData)
end
print("Finished migrating houses")
end)
end)