-- Exports the function "GetPlayerHouseId". This function returns the house ID of the player's current house.-- If the player is inside a house, it gets the house ID of that house. Otherwise, it returns nil.---@return number | nillocalfunctionGetPlayerHouseId()return Client.Player?.inHouse?.houseId
end-- Exports the function "GetPlayerHouse". This function returns the house the player is currently in.-- If the player is inside a house, it gets the information of that house. Otherwise, it returns nil.---@return InHouseType | nillocalfunctionGetPlayerHouse()return Client.Player?.inHouse
end-- Defines a local function "GetPlayerHouses". This function returns the houses owned by the player.-- If the player owns any houses, it gets the list of those houses. Otherwise, it returns nil.localfunctionGetPlayerHouses()return Client.Player?.ownedHouses
end-- Updates the specified indicator for a given house by adding or subtracting the provided value.-- The `houseId` parameter specifies the ID of the house.-- The `indicator` parameter specifies which indicator to update (e.g., "electricity", "power", "gas", or "water").-- The `value` parameter specifies the amount to add to (positive value) or subtract from (negative value) the current indicator value.-- The function returns the updated indicator value.---@param houseId number---@param indicator "electricity"|"power"|"gas"|"water"---@param value number---@return numberlocalfunctionUpdateHouseIndicator(indicator, value)if Client.Player.inHouse thenlocal response = Client.Functions.CallbackAwait(_e("Server:UpdateIndicator"),
indicator, value, Client.Player.inHouse.houseId)
if response.errorthen
Client.Functions.SendNotify(locale("error", response.error), "error")
returnfalseendreturntrueendend---Get available houses---@return tablelocalfunctionGetAvailableHouses()local defaultHouses = Client.Functions.GetDefaultHouses()
local soldHouses = Client.Functions.GetSoldHouses()
local soldHousesIds = {}
for _, house inpairs(soldHouses) doif house ~= nilthentable.insert(soldHousesIds, house.houseId)
endendlocal availableHouses = {}
for _, house inpairs(defaultHouses) doif house ~= nilandnot lib.table.contains(soldHousesIds, house.houseId) thentable.insert(availableHouses, house)
endendreturn availableHouses
end---@param houseId number---@param houseType "square"|"rectangle"|"furnished"|nillocalfunctionPurchaseHouse(houseId, houseType)ifnot houseId thenreturnfalseendifnot houseType then
houseType = "furnished"end
Client.Functions.Callback(_e("Server:PurchaseHouse"), function(response)ifnot response.errorthen
Client.Functions.SendNotify(locale("house_purchased", houseId), "success")
returntrueelse
Client.Functions.SendNotify(locale("error", response.error), "error")
returnfalseendend, houseId, houseType)
end
exports("GetPlayerHouseId", GetPlayerHouseId)
exports("GetPlayerHouse", GetPlayerHouse)
exports("GetPlayerHousePlacedFurnitures", function()if Client?.Player?.inHouse thenreturn Client?.Player?.Furniture?.createdFurnitures
endreturn {}
end)
exports("GetPlayerHouses", GetPlayerHouses)
exports("UpdateHouseIndicator", UpdateHouseIndicator)
exports("GetAvailableHouses", GetAvailableHouses)
exports("PurchaseHouse", PurchaseHouse)
localfunctionGetHouseById(houseId)return Server.SoldHouses[houseId]
end-- Updates the specified indicator for a given house by adding or subtracting the provided value.-- The `houseId` parameter specifies the ID of the house.-- The `indicator` parameter specifies which indicator to update (e.g., "electricity", "power", "gas", or "water").-- The `value` parameter specifies the amount to add to (positive value) or subtract from (negative value) the current indicator value.-- The function returns the updated indicator value.---@param houseId number---@param indicator "electricity"|"power"|"gas"|"water"---@param value number---@return numberlocalfunctionUpdateHouseIndicator(houseId, indicator, value)ifnot Utils.DefaultHouses[houseId] thenreturnfalseendifnot Config.Indicators[indicator] thenreturnfalseendlocal House = Server.SoldHouses[houseId]
ifnot House?.indicators[indicator] or (House.indicators[indicator] + value < 0) thenreturnfalseendreturn Server.Functions.UpdateHouseIndicator(indicator, value, houseId)
end---@param houseId number---@param indicator "electricity"|"power"|"gas"|"water"---@return numberlocalfunctionGetHouseIndicatorValue(houseId, indicator)local House = Server.SoldHouses[houseId]
if House thenlocal indicator = House.indicators?[indicator]
if indicator thenreturn indicator
endendreturn0endlocalfunctionGetAvailableHouses()local defaultHouses = Utils.DefaultHouses
local soldHouses = Server.SoldHouses
local soldHousesIds = {}
for _, house inpairs(soldHouses) doif house ~= nilthentable.insert(soldHousesIds, house.houseId)
endendlocal availableHouses = {}
for _, house inpairs(defaultHouses) doif house ~= nilandnot lib.table.contains(soldHousesIds, house.houseId) thentable.insert(availableHouses, house)
endendreturn availableHouses
end
exports("GetHouseById", GetHouseById)
exports("UpdateHouseIndicator", UpdateHouseIndicator)
exports("GetAvailableHouses", GetAvailableHouses)