130 lines
3.3 KiB
Lua
130 lines
3.3 KiB
Lua
if Config.HouseScript ~= 'origen-housing' then
|
|
return
|
|
end
|
|
|
|
local function FormatHouseData(houseList)
|
|
local formattedHouses = {}
|
|
|
|
for _, house in pairs(houseList) do
|
|
local keys = {}
|
|
|
|
if house.holders and next(house.holders) then
|
|
for identifier, holder in pairs(house.holders) do
|
|
keys[#keys + 1] = identifier
|
|
end
|
|
end
|
|
|
|
local door = exports.origen_housing:getHouseDoor(house.id)
|
|
|
|
formattedHouses[#formattedHouses + 1] = {
|
|
id = house.id,
|
|
citizenid = house.citizenid,
|
|
identifier = house.id,
|
|
uniqueHouse = house.id,
|
|
label = house.label,
|
|
tier = 1,
|
|
owned = true,
|
|
locked = true,
|
|
keyholders = keys,
|
|
coords = { x = house.coords.x, y = house.coords.y},
|
|
door = door
|
|
}
|
|
|
|
if house.doors and house.doors[door] then
|
|
formattedHouses[#formattedHouses].locked = house.doors[door].locked
|
|
end
|
|
end
|
|
|
|
return {
|
|
success = true,
|
|
houses = formattedHouses
|
|
}
|
|
end
|
|
|
|
function GetPlayerHouses()
|
|
local result = exports.origen_housing:getPlayerHouses()
|
|
if not result then return {} end
|
|
|
|
return FormatHouseData(result)
|
|
end
|
|
|
|
function GetPlayerHouseKeyHolders(keyholders)
|
|
local result = RPC.execute('codem-phone:home:getKeyHolders', keyholders)
|
|
return result
|
|
end
|
|
|
|
function SetPlayerHouseLockState(houseData)
|
|
if not houseData.door then
|
|
return {
|
|
success = false,
|
|
locked = true
|
|
}
|
|
end
|
|
|
|
|
|
local isLocked = exports.origen_housing:toggleDoor(houseData.uniqueHouse, houseData.door)
|
|
return {
|
|
success = true,
|
|
locked = isLocked and true or false
|
|
}
|
|
end
|
|
|
|
function AddKeyHolderHouse(data)
|
|
local targetID = data.targetId
|
|
local houseID = data.house.uniqueHouse
|
|
if not targetID or not houseID then
|
|
return {
|
|
success = false,
|
|
message = "Invalid data provided"
|
|
}
|
|
end
|
|
|
|
local result = exports.origen_housing:addKeyHolder(houseID, targetID)
|
|
|
|
if result then
|
|
local response = GetPlayerHouseKeyHolders(result)
|
|
|
|
if response.success then
|
|
return {
|
|
success = true,
|
|
uniqueHouse = houseID,
|
|
keyholders = response.keyholders
|
|
}
|
|
end
|
|
end
|
|
|
|
return {
|
|
success = false,
|
|
message = "Failed to add key holder"
|
|
}
|
|
end
|
|
|
|
function RemoveKeyHolderHouse(data)
|
|
local targetCitizenId = data.targetCitizenId
|
|
local houseID = tonumber(data.house.uniqueHouse)
|
|
if not targetCitizenId or not houseID then
|
|
return {
|
|
success = false,
|
|
message = "Invalid data provided"
|
|
}
|
|
end
|
|
|
|
local result = exports.origen_housing:removeKeyHolder(houseID, targetCitizenId)
|
|
|
|
if result then
|
|
local response = GetPlayerHouseKeyHolders(result)
|
|
if response.success then
|
|
return {
|
|
success = true,
|
|
uniqueHouse = houseID,
|
|
keyholders = response.keyholders
|
|
}
|
|
end
|
|
end
|
|
|
|
return {
|
|
success = false,
|
|
message = "Failed to remove key holder"
|
|
}
|
|
end
|