if Config.HouseScript ~= "vms_housing" then return end local function BillsOf(house) local out = {} if type(house.bills) ~= 'table' then return out end for i = 1, #house.bills do local bill = house.bills[i] local split = nil if type(bill.details) == 'string' then local ok, decoded = pcall(json.decode, bill.details) if ok and type(decoded) == 'table' then split = decoded end end if split then for _, key in ipairs({ 'electricity', 'water', 'internet' }) do local amount = tonumber(split[key]) if amount and amount > 0 then out[#out + 1] = { id = key, name = bill.period, amount = amount, paid = bill.paid == true } end end else out[#out + 1] = { id = bill.type, name = bill.period, amount = tonumber(bill.total) or 0, paid = bill.paid == true } end end return out end local function ServicesOf(house) local out = {} if type(house.bills) ~= 'table' then return out end for i = 1, #house.bills do local bill = house.bills[i] if type(bill.details) == 'string' then local ok, split = pcall(json.decode, bill.details) if ok and type(split) == 'table' then out[#out + 1] = { id = 'electricity', connected = true, used = tonumber(split.electricityUsage) or 0 } out[#out + 1] = { id = 'water', connected = true, used = tonumber(split.waterUsage) or 0 } break end end end return out end local function KeyholdersOf(raw) if not raw then return {} end local ok, keys = pcall(json.decode, raw) if not ok or type(keys) ~= 'table' then return {} end if exports['vms_housing']:GetConfiguration('UseKeysOnItem') then return HouseKeys(keys, function(_, serial) return HouseKey(nil, serial) end) end return HouseKeys(keys, function(identifier, name) return HouseKey(identifier, name) end) end local function DoorOf(house) local building if house.object_id then local object = exports['vms_housing']:GetProperty(house.object_id) if object and object.type == 'building' then building = object end end return (building and building.metadata and building.metadata.enter) or (house.metadata and house.metadata.enter) or (house.metadata and house.metadata.menu) end RegisterNuiCallback("gksphone:home:fetchHouseData", function(data, cb) local properties = exports['vms_housing']:GetPlayerProperties() local out = {} if type(properties) == 'table' then for i = 1, #properties do local house = properties[i] local coords = DoorOf(house) local locked = nil if type(house.metadata) == 'table' then locked = house.metadata.locked == true end local where = house.address if house.address and house.region then where = house.address .. ', ' .. house.region end out[#out + 1] = HouseEntry({ id = house.id, label = house.name or house.address, tag = house.name and where or nil, keyholders = KeyholdersOf(house.keys), bills = BillsOf(house), services = ServicesOf(house), locked = locked, garage = house.metadata and house.metadata.garage and true or false, coords = coords, canLocate = coords and coords.x ~= nil, canTransfer = true, canGiveKey = true, canRemoveKey = not exports['vms_housing']:GetConfiguration('UseKeysOnItem') }) end end Debugprint('vms_housing houses', out) cb(out) end) RegisterNUICallback('gksphone:home:transferHouse', function(data, cb) Debugprint('vms_housing transfer', data) TriggerServerEvent('gksphone:server:vmsTransferHouse', data.id, data.phoneNumber) cb('ok') end) RegisterNUICallback('gksphone:home:houseLocation', function(data, cb) local property = exports['vms_housing']:GetProperty(tonumber(data.id)) local coords = property and DoorOf(property) or data.coords if not HouseWaypoint(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('vms_housing:sv:buyKey', data.id, tonumber(target)) TriggerServerEvent('vms_housing:sv:giveKey', data.id, tonumber(target)) cb('ok') end, data.phoneNumber) end) RegisterNUICallback('gksphone:home:removeKey', function(data, cb) if not data.holderId or exports['vms_housing']:GetConfiguration('UseKeysOnItem') then cb(false) return end TriggerServerEvent('vms_housing:sv:removeKey', data.id, data.holderId) cb('ok') end) RegisterNUICallback('gksphone:home:toggleLock', function(data, cb) cb(false) end)