if Config.HouseScript ~= "bcs_housing" then return end --- Which types of home the script can actually lock. local LOCKABLE = { shell = true, ipl = true } local function KeyholdersOf(homeId) local holders = exports['bcs_housing']:GetKeyHolders(homeId) return HouseKeys(holders, function(_, holder) if type(holder) ~= 'table' then return nil end return HouseKey(holder.identifier, holder.name) end) end --- The first key defined on a house, which is what a new holder is given. local function FirstKeyName(homeId) local keys = exports['bcs_housing']:GetKeyList(homeId) if type(keys) ~= 'table' then return nil end for name in pairs(keys) do return name end return nil end local function Format(home, owned) local props = home.properties or home local configuration = home.configuration or props.configuration local coords = props.entry or home.entry local homeId = home.identifier or props.identifier local kind = home.type or props.type local lockable = kind ~= nil and LOCKABLE[kind] == true local locked = nil if lockable then locked = exports['bcs_housing']:isLocked(homeId) == true end return HouseEntry({ id = homeId, label = props.name, owned = owned, price = props.price, garage = configuration and configuration.garage and true or false, keyholders = owned and KeyholdersOf(homeId) or {}, coords = coords, canLocate = true, canTransfer = owned and (home.permission == nil or home.permission.transfer ~= false), canGiveKey = owned, canRemoveKey = owned, canLock = owned and lockable, locked = locked }) end RegisterNuiCallback("gksphone:home:fetchHouseData", function(data, cb) local out = {} local seen = {} local owned = exports['bcs_housing']:GetOwnedHomes() if type(owned) == 'table' then for i = 1, #owned do local entry = Format(owned[i], true) seen[entry.id] = true out[#out + 1] = entry end end local keyed = exports['bcs_housing']:GetOwnedHomeKeys() if type(keyed) == 'table' then for i = 1, #keyed do local home = keyed[i] local id = home.identifier or (home.properties and home.properties.identifier) if id and not seen[id] then seen[id] = true out[#out + 1] = Format(home, false) end end end Debugprint('bcs_housing houses', out) cb(out) end) RegisterNUICallback('gksphone:home:transferHouse', function(data, cb) Debugprint('bcs_housing transfer', data) CallBackServerTrigger('gksphone:server:getCizitinIDSource', function(citizenid, source) if not citizenid or not source then cb(false) return end TriggerServerEvent('Housing:server:TransferOwner', data.id, tonumber(source)) cb('ok') end, data.phoneNumber) end) RegisterNUICallback('gksphone:home:houseLocation', function(data, cb) exports['bcs_housing']:SetWaypoint(data.id) exports["gksphone"]:ToastNotification( _T(LastItemData?.info?.phoneLang, "HouseAPP.APP_HOUSE_SETGPS")) cb('ok') end) RegisterNUICallback('gksphone:home:giveKey', function(data, cb) local keyName = FirstKeyName(data.id) if not keyName then cb(false) return end CallBackServerTrigger('gksphone:server:getCizitinIDSource', function(_, target) if not target then cb(false) return end local ok = exports['bcs_housing']:AddKeyHolder(data.id, tonumber(target), keyName) cb(ok and 'ok' or false) end, data.phoneNumber) end) RegisterNUICallback('gksphone:home:removeKey', function(data, cb) if not data.holderId then cb(false) return end local ok = exports['bcs_housing']:RemoveKeyHolder(data.id, data.holderId) cb(ok and 'ok' or false) end) RegisterNUICallback('gksphone:home:toggleLock', function(data, cb) exports['bcs_housing']:LockHome(data.id) cb({ locked = exports['bcs_housing']:isLocked(data.id) == true }) end)