if Config.HouseScript ~= "qb-houses" then return end local houseConfig = {} RegisterNetEvent('qb-houses:client:setHouseConfig', function(config) houseConfig = config or {} end) local lockState = {} RegisterNetEvent('qb-houses:client:lockHouse', function(locked, house) lockState[house] = locked and true or false end) CreateThread(function() TriggerServerEvent('qb-houses:server:setHouses') end) local function KeyholdersOf(house) return HouseKeys(house.keyholders, function(_, holder) local charinfo = holder.charinfo local name = charinfo and (charinfo.firstname .. ' ' .. charinfo.lastname) return HouseKey(holder.citizenid, name or holder.name) end) end local function TierTag(tier) if not tier then return nil end return _T(LastItemData?.info?.phoneLang, "HouseAPP.APP_HOUSE_TIER") .. ' ' .. tier end local function IsLocked(name) if lockState[name] ~= nil then return lockState[name] end local config = name and houseConfig[name] return config and config.locked == true or false end local function DoorOf(name) local config = name and houseConfig[name] return config and config.coords and config.coords.enter or nil end RegisterNuiCallback("gksphone:home:fetchHouseData", function(data, cb) Config.Core.Functions.TriggerCallback('qb-phone:server:GetPlayerHouses', function(owned) Config.Core.Functions.TriggerCallback('qb-phone:server:GetHouseKeys', function(keyed) owned = owned or {} keyed = keyed or {} local out = {} local seen = {} for i = 1, #owned do local house = owned[i] local door = DoorOf(house.name) seen[house.label] = true out[#out + 1] = HouseEntry({ id = house.name, label = house.label, tag = TierTag(house.tier), tier = house.tier, price = house.price, garage = house.garage, keyholders = KeyholdersOf(house), coords = door, canTransfer = true, canLocate = door ~= nil, canGiveKey = true, canRemoveKey = true, canLock = true, locked = IsLocked(house.name) }) end for i = 1, #keyed do local info = keyed[i].HouseData if info and info.adress and not seen[info.adress] then seen[info.adress] = true out[#out + 1] = HouseEntry({ id = info.adress, label = info.adress, tag = TierTag(info.tier), tier = info.tier, garage = info.garage, owned = false, coords = info.coords and info.coords.enter or nil, canLocate = info.coords and info.coords.enter and true or false }) end end Debugprint('qb-houses houses', out) cb(out) end) end) end) RegisterNUICallback('gksphone:home:transferHouse', function(data, cb) Debugprint('qb-houses transfer', data) CallBackServerTrigger('gksphone:server:getCizitinIDSource', function(citizenid) if not citizenid then cb(false) return end Config.Core.Functions.TriggerCallback('qb-phone:server:TransferCid', function(transfer) if transfer then exports["gksphone"]:ToastNotification( _T(LastItemData?.info?.phoneLang, "HouseAPP.APP_HOME_TRANSFERSUCCESS")) end cb(transfer and 'ok' or false) end, citizenid, { name = data.id }) end, data.phoneNumber) end) RegisterNUICallback('gksphone:home:houseLocation', function(data, cb) if not HouseWaypoint(data.coords) then 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('qb-houses:server:giveHouseKey', tonumber(target), data.id) cb('ok') end, data.phoneNumber) end) RegisterNUICallback('gksphone:home:removeKey', function(data, cb) if not data.holderId then cb(false) return end TriggerServerEvent('qb-houses:server:removeHouseKey', data.id, { citizenid = data.holderId, firstname = '', lastname = '' }) cb('ok') end) RegisterNUICallback('gksphone:home:toggleLock', function(data, cb) local locked = not IsLocked(data.id) TriggerServerEvent('qb-houses:server:lockHouse', locked, data.id) lockState[data.id] = locked cb({ locked = locked }) end)