if Config.HouseScript ~= "rtx_housing" then return end local function LockKey(houseId) return 'rtxhousing-' .. tostring(houseId) .. '-locked' end local function IsLocked(houseId) local state = GlobalState[LockKey(houseId)] return state == true end local function PeopleOf(property) return HouseKeys(property.permissions, function(_, entry) if type(entry) ~= 'table' then return nil end return HouseKey(entry.identifierdata, entry.playername) end) end local function BillsOf(property) local out = {} if type(property.bills) ~= 'table' then return out end for id, bill in pairs(property.bills) do if type(bill) == 'table' then out[#out + 1] = { id = bill.id or id, name = bill.name, amount = tonumber(bill.amount) or 0, paid = bill.paid == true } end end return out end local function ServicesOf(property) local out = {} if type(property.services) ~= 'table' then return out end for id, service in pairs(property.services) do if type(service) == 'table' then out[#out + 1] = { id = id, connected = service.connected == true, used = tonumber(service.consumption) or 0, unpaid = tonumber(service.consumptionunpaid) or 0, unit = service.unit } end end return out end local function UpgradesOf(property) local out = {} if type(property.upgrades) ~= 'table' then return out end for id, upgrade in pairs(property.upgrades) do if type(upgrade) == 'table' and upgrade.owned == true then out[#out + 1] = upgrade.id or id end end return out end local function DoorOf(property) local complex = property.partofcomplex if type(complex) == 'table' and complex.enabled and complex.complexid ~= '' then local block = exports['rtx_housing']:GetPropertyData(complex.complexid) if block and block.enter then return block.enter.coords end end return property.enter and property.enter.coords or nil end RegisterNuiCallback("gksphone:home:fetchHouseData", function(data, cb) local properties = exports['rtx_housing']:GetPlayerOwnedProperties() local out = {} if type(properties) == 'table' then for _, property in pairs(properties) do local coords = DoorOf(property) out[#out + 1] = HouseEntry({ id = property.houseid, label = property.propertyname or property.adress, tag = property.propertyname and property.adress or nil, owned = property.owned ~= false, keyholders = PeopleOf(property), garage = type(property.garage) == 'table' and property.garage.enabled == true, coords = coords, canLocate = type(coords) == 'table' and coords.x ~= nil, canTransfer = true, canGiveKey = true, canRemoveKey = true, canLock = true, locked = IsLocked(property.houseid), bills = BillsOf(property), services = ServicesOf(property), upgrades = UpgradesOf(property) }) end end Debugprint('rtx_housing houses', out) cb(out) end) RegisterNUICallback('gksphone:home:transferHouse', function(data, cb) Debugprint('rtx_housing transfer', data) TriggerServerEvent('gksphone:server:rtxTransferHouse', data.id, data.phoneNumber) cb('ok') end) RegisterNUICallback('gksphone:home:houseLocation', function(data, cb) if not HouseWaypoint(data.coords) then exports["gksphone"]:ToastNotification( _T(LastItemData?.info?.phoneLang, "HouseAPP.APP_HOUSE_ERROR_NOTFOUND")) cb(false) return end exports["gksphone"]:ToastNotification( _T(LastItemData?.info?.phoneLang, "HouseAPP.APP_HOUSE_SETGPS")) cb('ok') end) RegisterNUICallback('gksphone:home:giveKey', function(data, cb) CallBackServerTrigger('gksphone:server:getCizitinIDSource', function(_, target) if not target then cb(false) return end TriggerServerEvent('rtx_housing:Global:AddPermission', data.id, tonumber(target)) cb('ok') end, data.phoneNumber) end) RegisterNUICallback('gksphone:home:removeKey', function(data, cb) if not data.holderId then cb(false) return end TriggerServerEvent('rtx_housing:Global:RemovePermission', data.id, data.holderId) cb('ok') end) RegisterNUICallback('gksphone:home:toggleLock', function(data, cb) TriggerServerEvent('rtx_housing:Global:PropertyLockStatus', data.id) SetTimeout(800, function() cb({ locked = IsLocked(data.id) }) end) end)