137 lines
3.6 KiB
Lua
137 lines
3.6 KiB
Lua
if Config.HouseScript ~= 'bcs-housing' then
|
|
return
|
|
end
|
|
RPC.Register('codem-phone:home:getKeyHolders', function(source, keyholders)
|
|
if not keyholders then
|
|
return {
|
|
success = false,
|
|
message = "No keyholders provided"
|
|
}
|
|
end
|
|
|
|
local KeyHoldersName = {}
|
|
for key, citizenid in ipairs(keyholders) do
|
|
local PlayerName = Core.Functions.GetName(citizenid)
|
|
if PlayerName then
|
|
KeyHoldersName[#KeyHoldersName + 1] = {
|
|
citizenid = citizenid,
|
|
name = PlayerName,
|
|
phoneNumber = GetPhoneNumberByIdentifier(citizenid)
|
|
}
|
|
end
|
|
end
|
|
|
|
return {
|
|
success = true,
|
|
keyholders = KeyHoldersName
|
|
}
|
|
end)
|
|
|
|
RPC.Register('codem-phone:home:getHouse', function(source)
|
|
local src = source
|
|
local identifier = Core.Functions.GetIdentifier(src)
|
|
if not identifier then
|
|
return {
|
|
success = false,
|
|
message = "Player not found"
|
|
}
|
|
end
|
|
|
|
local ownedHomes = {}
|
|
local result = exports.bcs_housing:GetOwnedHomes(identifier)
|
|
|
|
if result then
|
|
for _, v in pairs(result) do
|
|
local keys = {}
|
|
local holders = exports.bcs_housing:GetKeyHolders(v.identifier)
|
|
|
|
if holders then
|
|
for _, v2 in pairs(holders) do
|
|
keys[#keys + 1] = v2.identifier
|
|
end
|
|
end
|
|
|
|
ownedHomes[#ownedHomes + 1] = {
|
|
id = v.identifier,
|
|
citizenid = v.owner,
|
|
coords = { enter = v.entry },
|
|
house = v.identifier,
|
|
keyholders = keys,
|
|
label = v.name,
|
|
name = v.name,
|
|
owned = true,
|
|
tier = v.type,
|
|
}
|
|
end
|
|
end
|
|
|
|
return {
|
|
success = true,
|
|
houses = ownedHomes
|
|
}
|
|
end)
|
|
|
|
|
|
RPC.Register('codem-phone:home:addkeyholderhouse', function(source, data)
|
|
local src = source
|
|
local identifier = Core.Functions.GetIdentifier(src)
|
|
if not identifier then
|
|
return {
|
|
success = false,
|
|
message = "Player not found"
|
|
}
|
|
end
|
|
local targetID = data.targetID
|
|
local houseID = data.houseID
|
|
if not targetID or not houseID then
|
|
return {
|
|
success = false,
|
|
message = "Invalid data provided"
|
|
}
|
|
end
|
|
exports.bcs_housing:GiveKey(houseID, targetID)
|
|
return {
|
|
success = true
|
|
}
|
|
end)
|
|
|
|
RPC.Register('codem-phone:home:removekeyholderhouse', function(source, data)
|
|
local src = source
|
|
local identifier = Core.Functions.GetIdentifier(src)
|
|
if not identifier then
|
|
return {
|
|
success = false,
|
|
message = "Player not found"
|
|
}
|
|
end
|
|
local targetCitizenID = data.targetCitizenId
|
|
local houseID = data.houseID
|
|
if not targetCitizenID or not houseID then
|
|
return {
|
|
success = false,
|
|
message = "Invalid data provided"
|
|
}
|
|
end
|
|
local holders = exports.bcs_housing:GetKeyHolders(houseID)
|
|
local found = false
|
|
if holders then
|
|
for _, v in pairs(holders) do
|
|
if v.identifier == targetCitizenID then
|
|
found = true
|
|
break
|
|
end
|
|
end
|
|
end
|
|
if found then
|
|
exports.bcs_housing:RemoveKey(houseID, targetCitizenID)
|
|
return {
|
|
success = true
|
|
}
|
|
else
|
|
return {
|
|
success = false,
|
|
message = "Keyholder not found"
|
|
}
|
|
end
|
|
end)
|