From ce4e84bff8878004639df7a51907a9ec2d96e387 Mon Sep 17 00:00:00 2001 From: iseeyoucopy Date: Sun, 25 Aug 2024 15:26:33 +0100 Subject: [PATCH 1/5] Fix: Furniture Not Selling After Purchase This update addresses an issue where furniture purchased and placed by a player could not be sold immediately unless the resource was restarted. The issue was caused by the CreatedFurniture table not properly tracking newly placed furniture entities due to an improper handling of entity creation and storage. --- client/MenuSetup/furnitureMenu.lua | 27 ++++++++++++++++++++------ server/services/houses.lua | 31 ++++++++++++++++++++++++------ 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/client/MenuSetup/furnitureMenu.lua b/client/MenuSetup/furnitureMenu.lua index 9106acf..b1cbc2d 100644 --- a/client/MenuSetup/furnitureMenu.lua +++ b/client/MenuSetup/furnitureMenu.lua @@ -14,7 +14,6 @@ function FurnitureMenu(houseId) style = {} }) - -- Register a back button to return to the previous menu furnitureMainMenu:RegisterElement('button', { label = _U("buyOwnerFurn"), style = {} @@ -22,12 +21,12 @@ function FurnitureMenu(houseId) buyFurnitureMenu(houseId) end) - -- Register a back button to return to the previous menu furnitureMainMenu:RegisterElement('button', { label = _U("sellOwnerFurn"), style = {} }, function() - GetOwnedFurniture(houseId) + -- Trigger server event to fetch furniture data for the house + TriggerServerEvent('bcc-housing:GetOwnerFurniture', houseId) end) furnitureMainMenu:RegisterElement('line', { @@ -367,13 +366,29 @@ function closeToHouse(object) -- make sure the obj is close to house before plac end RegisterNetEvent('bcc-housing:ClientFurnBought', function(furnitureCreatedTable, entId) + -- Assuming `furnObj` should be the furniture entity created by the player + local furnObj = NetworkGetEntityFromNetworkId(entId) + + -- Make sure the furniture entity is valid before inserting it into the table + if DoesEntityExist(furnObj) then + table.insert(CreatedFurniture, furnObj) + else + devPrint("Error: Furniture entity does not exist, could not add to CreatedFurniture.") + VORPcore.NotifyRightTip(_U("furnNotPlaced"), 4000) + return + end + + -- Insert furniture details into the database TriggerServerEvent('bcc-housing:InsertFurnitureIntoDB', furnitureCreatedTable, HouseId) + + -- Store the furniture entity for potential deletion later TriggerServerEvent('bcc-housing:StoreFurnForDeletion', entId, HouseId) - table.insert(CreatedFurniture, furnObj) - furnObj = nil + + -- Notify the player that the furniture has been placed VORPcore.NotifyRightTip(_U("furnPlaced"), 4000) end) + RegisterNetEvent('bcc-housing:ClientFurnBoughtFail', function() DeleteObject(furnObj) furnObj = nil @@ -490,4 +505,4 @@ AddEventHandler('bcc-housing:SellOwnedFurnMenu', function(houseId, furnTable) else devPrint("Error: furnTable is not a table") end -end) +end) \ No newline at end of file diff --git a/server/services/houses.lua b/server/services/houses.lua index 1b4e00f..da2d39e 100644 --- a/server/services/houses.lua +++ b/server/services/houses.lua @@ -334,21 +334,40 @@ RegisterServerEvent('bcc-housing:GetOwnerFurniture', function(houseId) if result and #result > 0 then local houseData = result[1] - local furnitureData = houseData.furniture or '[]' + local furnitureData = houseData.furniture + -- Handle the case where furnitureData is "none" + if furnitureData == "none" or furnitureData == nil or furnitureData == "" then + VORPcore.NotifyRightTip(_source, _U("noFurn"), 4000) + devPrint("No furniture found for house ID: " .. tostring(houseId)) + return + end + + -- Attempt to decode the furniture data if it's not "none" local furniture, decodeErr = json.decode(furnitureData) - if not decodeErr and furniture then - if #furniture > 0 then - TriggerClientEvent('bcc-housing:SellOwnedFurnMenu', _source, furniture) - else + if furniture then + -- If the furniture table is empty, notify the player + if #furniture == 0 then VORPcore.NotifyRightTip(_source, _U("noFurn"), 4000) + devPrint("No furniture found for house ID: " .. tostring(houseId)) + else + -- Log and trigger the event if furniture is found + for i, item in ipairs(furniture) do + devPrint(string.format("Furniture Item %d: Model: %s, DisplayName: %s", i, item.model, item.displayName)) + end + devPrint("Triggering SellOwnedFurnMenu event for house ID: " .. tostring(houseId) .. " with " .. tostring(#furniture) .. " items.") + TriggerClientEvent('bcc-housing:SellOwnedFurnMenu', _source, houseId, furniture) end else - devPrint("Error decoding furniture data: " .. tostring(decodeErr)) + -- Log the decoding error and notify the player + devPrint("Error decoding furniture data: " .. tostring(decodeErr) .. ". Raw data: " .. tostring(furnitureData)) VORPcore.NotifyRightTip(_source, "Error loading furniture data.", 4000) end + else + -- Notify the player if no house data was found VORPcore.NotifyRightTip(_source, _U("noFurn"), 4000) + devPrint("No house data found for house ID: " .. tostring(houseId)) end end) From d8e2dca82ef225b03d50d51d84cdb14f54b8ebe0 Mon Sep 17 00:00:00 2001 From: iseeyoucopy Date: Sun, 25 Aug 2024 21:02:13 +0100 Subject: [PATCH 2/5] new feature and small updates - added new feature Private property check - added sound to the furniture menu - enable menufocus for furniture menu - missing localization keys for language - removed ClientCloseAllMenus, we don't need that --- client/MainHousing.lua | 119 +++++++++++++++++++++-------- client/MenuSetup/furnitureMenu.lua | 48 ++++++++---- config.lua | 5 ++ languages/de_lang.lua | 1 + languages/en_lang.lua | 1 + languages/fr_lang.lua | 1 + languages/ro_lang.lua | 1 + server/services/houses.lua | 10 ++- 8 files changed, 136 insertions(+), 50 deletions(-) diff --git a/client/MainHousing.lua b/client/MainHousing.lua index 44333a6..878d294 100644 --- a/client/MainHousing.lua +++ b/client/MainHousing.lua @@ -1,7 +1,7 @@ ---Insert Your Main Client Side Code Here +-- Insert Your Main Client Side Code Here HouseCoords, HouseRadius, HouseId, AdminAllowed, Owner, HouseBlips, OwnedHotels, TpHouse, TpHouseInstance = nil, nil, nil, false, nil, {}, {}, nil, nil -RegisterCommand(Config.AdminManagementMenuCommand, function() --house creation command +RegisterCommand(Config.AdminManagementMenuCommand, function() -- house creation command if AdminAllowed then HouseManagementMenu() end @@ -14,25 +14,26 @@ if Config.DevMode then end else -- Define devPrint as a no-op function if DevMode is not enabled - function devPrint(message) end + function devPrint(message) + end end -RegisterNetEvent('vorp:SelectedCharacter') --init loading +RegisterNetEvent('vorp:SelectedCharacter') -- init loading AddEventHandler('vorp:SelectedCharacter', function() - local player = GetPlayerServerId(tonumber(PlayerId())) --credit vorp_admin + local player = GetPlayerServerId(tonumber(PlayerId())) -- credit vorp_admin Wait(200) - TriggerServerEvent("bcc-housing:getPlayersInfo", player) --credit vorp_admin + TriggerServerEvent("bcc-housing:getPlayersInfo", player) -- credit vorp_admin TriggerServerEvent('bcc-housing:AdminCheck') TriggerServerEvent('bcc-housing:HotelDbRegistry') TriggerServerEvent('bcc-housing:CheckIfHasHouse') end) -CreateThread(function() --Devmode area +CreateThread(function() -- Devmode area if Config.DevMode then RegisterCommand('HousingDev', function() - local player = GetPlayerServerId(tonumber(PlayerId())) --credit vorp_admin + local player = GetPlayerServerId(tonumber(PlayerId())) -- credit vorp_admin Wait(200) - TriggerServerEvent("bcc-housing:getPlayersInfo", player) --credit vorp_admin + TriggerServerEvent("bcc-housing:getPlayersInfo", player) -- credit vorp_admin TriggerServerEvent('bcc-housing:AdminCheck') TriggerServerEvent('bcc-housing:HotelDbRegistry') TriggerServerEvent('bcc-housing:CheckIfHasHouse') @@ -52,52 +53,62 @@ AddEventHandler('bcc-housing:OwnsHouseClientHandler', function(houseTable, owner end devPrint("House information set for House ID: " .. tostring(HouseId)) - + -- ManageHouse Menu Setup TriggerEvent('bcc-housing:FurnCheckHandler') + --TriggerEvent('bcc-housing:PrivatePropertyCheckHandler') local blip = BccUtils.Blips:SetBlip(_U("houseBlip"), 'blip_mp_base', 0.2, HouseCoords.x, HouseCoords.y, HouseCoords.z) table.insert(HouseBlips, blip) showManageOpt(HouseCoords.x, HouseCoords.y, HouseCoords.z, HouseId) -- Ensure HouseId is passed here end) -RegisterNetEvent('bcc-housing:AdminClientCatch', function(var) --admin check catch +RegisterNetEvent('bcc-housing:AdminClientCatch', function(var) -- admin check catch if var then AdminAllowed = true end end) -AddEventHandler('bcc-housing:FurnCheckHandler', function() --event to spawn, and del furniture based on distance to house - devPrint("Starting furniture check handler") - while true do - Wait(2000) - local plc = GetEntityCoords(PlayerPedId()) - local dist = GetDistanceBetweenCoords(plc.x, plc.y, plc.z, HouseCoords.x, HouseCoords.y, HouseCoords.z, true) - if dist < HouseRadius + 20 then - --devPrint("Player is near the house. Spawning furniture.") - TriggerServerEvent('bcc-housing:FurniturePlacedCheck', HouseId, false, true) - Wait(1500) - elseif dist > HouseRadius + 100 then - devPrint("Player is far from the house. Deleting furniture.") - TriggerServerEvent('bcc-housing:FurniturePlacedCheck', HouseId, true) +AddEventHandler('bcc-housing:FurnCheckHandler', + function() -- event to spawn, and del furniture based on distance to house + devPrint("Starting furniture check handler") + while true do Wait(2000) + local plc = GetEntityCoords(PlayerPedId()) + local dist = GetDistanceBetweenCoords(plc.x, plc.y, plc.z, HouseCoords.x, HouseCoords.y, HouseCoords.z, true) + if dist < HouseRadius + 20 then + -- devPrint("Player is near the house. Spawning furniture.") + TriggerServerEvent('bcc-housing:FurniturePlacedCheck', HouseId, false, true) + Wait(1500) + elseif dist > HouseRadius + 100 then + devPrint("Player is far from the house. Deleting furniture.") + TriggerServerEvent('bcc-housing:FurniturePlacedCheck', HouseId, true) + Wait(2000) + end end - end -end) + end) ---Hotel area -- +-- Hotel area -- RegisterNetEvent('bcc-housing:MainHotelHandler', function() devPrint("Initializing main hotel handler") local PromptGroup = BccUtils.Prompts:SetupPromptGroup() - local firstprompt = PromptGroup:RegisterPrompt(_U("promptBuy"), 0x760A9C6F, 1, 1, true, 'hold', { timedeventhash = "MEDIUM_TIMED_EVENT" }) + local firstprompt = PromptGroup:RegisterPrompt(_U("promptBuy"), 0x760A9C6F, 1, 1, true, 'hold', { + timedeventhash = "MEDIUM_TIMED_EVENT" + }) local PromptGroup2 = BccUtils.Prompts:SetupPromptGroup() - local firstprompt2 = PromptGroup2:RegisterPrompt(_U("promptEnterHotel"), 0x760A9C6F, 1, 1, true, 'hold', { timedeventhash = "MEDIUM_TIMED_EVENT" }) + local firstprompt2 = PromptGroup2:RegisterPrompt(_U("promptEnterHotel"), 0x760A9C6F, 1, 1, true, 'hold', { + timedeventhash = "MEDIUM_TIMED_EVENT" + }) local PromptGroup3 = BccUtils.Prompts:SetupPromptGroup() - local firstprompt3 = PromptGroup3:RegisterPrompt(_U("hotelInvName"), 0x760A9C6F, 1, 1, true, 'hold', { timedeventhash = "MEDIUM_TIMED_EVENT" }) + local firstprompt3 = PromptGroup3:RegisterPrompt(_U("hotelInvName"), 0x760A9C6F, 1, 1, true, 'hold', { + timedeventhash = "MEDIUM_TIMED_EVENT" + }) local PromptGroup4 = BccUtils.Prompts:SetupPromptGroup() - local firstprompt4 = PromptGroup4:RegisterPrompt(_U("promptLeaveHotel"), 0x760A9C6F, 1, 1, true, 'hold', { timedeventhash = "MEDIUM_TIMED_EVENT" }) + local firstprompt4 = PromptGroup4:RegisterPrompt(_U("promptLeaveHotel"), 0x760A9C6F, 1, 1, true, 'hold', { + timedeventhash = "MEDIUM_TIMED_EVENT" + }) local inHotel, hotelInside, instanceNumber, coordsWhenEntered = false, nil, 0, nil while true do @@ -149,14 +160,56 @@ RegisterNetEvent('bcc-housing:MainHotelHandler', function() devPrint("Leaving hotel: " .. tostring(hotelInside.hotelId)) SetEntityCoords(PlayerPedId(), coordsWhenEntered.x, coordsWhenEntered.y, coordsWhenEntered.z) inHotel = false - VORPcore.instancePlayers(0) --removes the player from instance + VORPcore.instancePlayers(0) -- removes the player from instance end end end end end) -RegisterNetEvent('bcc-housing:HousingTableUpdate', function(houseId) --event to update the housing table +RegisterNetEvent('bcc-housing:PrivatePropertyCheckHandler') +AddEventHandler('bcc-housing:PrivatePropertyCheckHandler', function(houseCoords, houseRadius) + -- Check if the property check is enabled + if not Config.EnablePrivatePropertyCheck then + devPrint("Private property check is disabled in the config.") + return -- Exit the handler if the check is disabled + end + devPrint("Starting private property check handler") + + local privatePropertyRadius = houseRadius + 20 -- Adjust the radius as needed + local isInsidePrivateProperty = false -- Track if the player is currently inside the property + local lastNotificationTime = 0 -- Track the last time a notification was shown + + while true do + Wait(0) -- Run the loop continuously + + local playerCoords = GetEntityCoords(PlayerPedId()) + local distanceToHouse = GetDistanceBetweenCoords(playerCoords.x, playerCoords.y, playerCoords.z, houseCoords.x, + houseCoords.y, houseCoords.z, true) + + if distanceToHouse < privatePropertyRadius then + if not isInsidePrivateProperty then + -- First time entering the property + VORPcore.NotifyBottomRight("You are entering private property!", 4000) + isInsidePrivateProperty = true + devPrint("Player has entered private property.") + lastNotificationTime = GetGameTimer() -- Set the time for the first notification + elseif GetGameTimer() - lastNotificationTime >= 10000 then + -- Show the message every 10 seconds + VORPcore.NotifyLeft("Private Property", "You are on a private property", "menu_textures", + "menu_icon_alert", "red", 4000) + lastNotificationTime = GetGameTimer() -- Update the time for the next notification + end + elseif isInsidePrivateProperty then + -- Player has left the property + VORPcore.NotifyBottomRight("You are leaving private property!", 10000) + isInsidePrivateProperty = false + devPrint("Player has left private property.") + end + end +end) + +RegisterNetEvent('bcc-housing:HousingTableUpdate', function(houseId) -- event to update the housing table devPrint("Updating housing table with house ID: " .. tostring(houseId)) table.insert(OwnedHotels, houseId) end) diff --git a/client/MenuSetup/furnitureMenu.lua b/client/MenuSetup/furnitureMenu.lua index b1cbc2d..3549cd9 100644 --- a/client/MenuSetup/furnitureMenu.lua +++ b/client/MenuSetup/furnitureMenu.lua @@ -50,7 +50,11 @@ function FurnitureMenu(houseId) -- Open the menu with the configured main page BCCHousingMenu:Open({ - startupPage = furnitureMainMenu + startupPage = furnitureMainMenu, + sound = { + action = "SELECT", + soundset = "RDRO_Character_Creator_Sounds" + } }) end @@ -141,7 +145,11 @@ function buyFurnitureMenu(houseId) -- Open the menu with the configured main page BCCHousingMenu:Open({ - startupPage = buyFurnitureMenu + startupPage = buyFurnitureMenu, + sound = { + action = "SELECT", + soundset = "RDRO_Character_Creator_Sounds" + } }) end @@ -197,7 +205,11 @@ function IndFurnitureTypeMenu(type, houseId) }) BCCHousingMenu:Open({ - startupPage = furnitureTypeMenu + startupPage = furnitureTypeMenu, + sound = { + action = "SELECT", + soundset = "RDRO_Character_Creator_Sounds" + } }) end @@ -228,9 +240,11 @@ function PlaceFurnitureIntoWorldMenu(model, cost, displayName, sellPrice) -- Slider for adjustment precision furniturePlacementMenu:RegisterElement('slider', { label = _U("amountToMove"), + slot = 'header', + start = 0.2, min = 0, - max = 5, - step = 0.1, + max = 10, + steps = 0.1, value = amountToMove }, function(data) amountToMove = data.value @@ -290,10 +304,18 @@ function PlaceFurnitureIntoWorldMenu(model, cost, displayName, sellPrice) slot = "footer", style = {} }) - BCCHousingMenu:Open({ - startupPage = furniturePlacementMenu + cursorFocus = false, + menuFocus = true, + startupPage = furniturePlacementMenu, + sound = { + action = "SELECT", + soundset = "RDRO_Character_Creator_Sounds" + } }) + --BCCHousingMenu:Open({ + --startupPage = furniturePlacementMenu + --}) end function MoveFurniture(obj, direction, moveAmount) @@ -439,7 +461,7 @@ function SellOwnedFurnitureMenu(houseId,furnTable) DeleteEntity(entity) table.remove(CreatedFurniture, idx) TriggerServerEvent('bcc-housing:FurnSoldRemoveFromTable', v, houseId, furnTable, k) - VORPcore.NotifyRightTip(_U("furnSold"), 4000) + --VORPcore.NotifyRightTip(_U("furnSold"), 4000) sold = true break end @@ -484,14 +506,14 @@ function SellOwnedFurnitureMenu(houseId,furnTable) -- Open the menu with the configured page BCCHousingMenu:Open({ - startupPage = sellFurnMenu + startupPage = sellFurnMenu, + sound = { + action = "SELECT", + soundset = "RDRO_Character_Creator_Sounds" + } }) end -RegisterNetEvent('bcc-housing:ClientCloseAllMenus', function() - BCCHousingMenu:Close() -end) - function GetOwnedFurniture(houseId) devPrint("Requesting furniture for house ID: " .. tostring(houseId)) TriggerServerEvent('bcc-housing:GetOwnerFurniture', houseId) diff --git a/config.lua b/config.lua index 4684d15..8039554 100644 --- a/config.lua +++ b/config.lua @@ -9,6 +9,7 @@ Config = { TaxResetDay = 24, --This MUST be the day after TaxDay set above!!! (do not change either of these dates if the current date is one of the 2 for ex if its the 22 or 23rd day do not change these dates it will break the code) WebhookLink = '', --insert your webhook link here if you want webhooks AdminManagementMenuCommand = 'HousingManager', --the name of the command for admins to manage all houses + EnablePrivatePropertyCheck = false, -- Set to true to enable, false to disable, this is for if you want to see a message that you enterd on a private property Hotels = { { hotelId = 1, --Make sure this is a unique number for each hotel (once set do not change it will break!) @@ -197,6 +198,10 @@ Config = { Interior2 = { exitCoords = { x = -63.74, y = 14.05, z = 76.6 }, furnRadius = 10 + }, + Interior3 = { + exitCoords = { x = -60.36, y = 1238.86, z = 170.79 }, + furnRadius = 10 } } } diff --git a/languages/de_lang.lua b/languages/de_lang.lua index 1f67ffa..3ee4d40 100644 --- a/languages/de_lang.lua +++ b/languages/de_lang.lua @@ -98,6 +98,7 @@ Locales["de_lang"] = { noFurn = 'Du hast keine Möbel', sellFor = 'Verkaufspreis: ', furnSold = 'Möbelstück verkaut', + furnNotSold = 'Furniture not sold', taxAmount = 'Steuern', taxAmount_desc = '', taxAmountSet = 'Steuerhöhe gesetzt', diff --git a/languages/en_lang.lua b/languages/en_lang.lua index 62f8fdb..0c007a9 100644 --- a/languages/en_lang.lua +++ b/languages/en_lang.lua @@ -98,6 +98,7 @@ Locales["en_lang"] = { noFurn = 'You do not own any furniture', sellFor = 'Sell For: ', furnSold = 'Furniture Sold', + furnNotSold = 'Furniture not sold', taxAmount = 'Tax Amount', taxAmount_desc = 'Set the amount the house will have to pay in taxes.', taxAmountSet = 'Tax amount set', diff --git a/languages/fr_lang.lua b/languages/fr_lang.lua index ca455e5..6f1f807 100644 --- a/languages/fr_lang.lua +++ b/languages/fr_lang.lua @@ -98,6 +98,7 @@ Locales["fr_lang"] = { noFurn = 'Vous ne possédez aucun meuble', sellFor = 'Vendre pour : ', furnSold = 'Meubles vendus', + furnNotSold = 'Furniture not sold', taxAmount = 'Montant de la taxe', taxAmount_desc = 'Définir le montant que la maison devra payer en taxes.', taxAmountSet = 'Montant de la taxe défini', diff --git a/languages/ro_lang.lua b/languages/ro_lang.lua index 1a60ca6..dd22503 100644 --- a/languages/ro_lang.lua +++ b/languages/ro_lang.lua @@ -98,6 +98,7 @@ Locales["ro_lang"] = { noFurn = 'Nu detii niciun mobilier', sellFor = 'Vinde Pentru: ', furnSold = 'Mobilier Vandut', + furnNotSold = 'Nu ai putut vinde mobilierul', taxAmount = 'Suma Taxei', taxAmount_desc = 'Seteaza suma pe care casa va trebui sa o plateasca In taxe.', taxAmountSet = 'Suma Taxei Stabilita', diff --git a/server/services/houses.lua b/server/services/houses.lua index da2d39e..a922c79 100644 --- a/server/services/houses.lua +++ b/server/services/houses.lua @@ -53,6 +53,8 @@ AddEventHandler('bcc-housing:CheckIfHasHouse', function(passedSource) if #result > 0 then for k, v in pairs(result) do + TriggerClientEvent('bcc-housing:PrivatePropertyCheckHandler', _source, json.decode(v.house_coords), v.house_radius_limit) + local data = { id = 'Player_' .. tostring(v.houseid) .. '_bcc-houseinv', name = _U("houseInv"), @@ -400,7 +402,7 @@ RegisterServerEvent('bcc-housing:FurnSoldRemoveFromTable', function(furnTable, h VORPcore.NotifyRightTip(_source, _U("furnNotSoldInvalid"), 4000) end - TriggerClientEvent('bcc-housing:ClientCloseAllMenus', _source) + TriggerClientEvent('bcc-housing:SellOwnedFurnMenu', _source, houseId, wholeFurnTable) end) RegisterServerEvent('bcc-housing:LedgerHandling') @@ -623,16 +625,16 @@ AddEventHandler('bcc-housing:RemovePlayerAccess', function(houseId, playerId) }, function(affectedRows) if affectedRows > 0 then devPrint("Removed player access successfully for Player ID: " .. tostring(playerId)) + TriggerClientEvent('bcc-housing:ClientRecHouseLoad', src) VORPcore.NotifyRightTip(src, "Removed player access successfully for Player ID: " .. tostring(playerId)) else devPrint("Failed to update database with new allowed IDs list.") - VORPcore.NotifyRightTip(src, 'Failed to update database with new allowed IDs list.') - --TriggerClientEvent('bcc-housing:PlayerAccessRemovalFailed', src, houseId, playerId, "Database update failed.") + VORPcore.NotifyRightTip(src, "Update failed, please try again.", 4000) end end) else devPrint("No house found with ID: " .. tostring(houseId) .. " or allowed_ids is empty.") - TriggerClientEvent('bcc-housing:PlayerAccessRemovalFailed', src, houseId, playerId, "No such house ID or empty allowed list.") + VORPcore.NotifyRightTip(src, "No such house ID or empty allowed list.", 4000) end end) end) From 1e62a407600249410ef722df56ff9f8c26d528eb Mon Sep 17 00:00:00 2001 From: iseeyoucopy Date: Mon, 26 Aug 2024 13:10:32 +0100 Subject: [PATCH 3/5] Fix Ledger Back Button Behavior for Non-Owner Players - The fix ensures that the menu correctly reflects the player's role (owner vs. non-owner) when they navigate through the housing menu. --- client/MenuSetup/manageHouseMenu.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/client/MenuSetup/manageHouseMenu.lua b/client/MenuSetup/manageHouseMenu.lua index 3225adb..03eca62 100644 --- a/client/MenuSetup/manageHouseMenu.lua +++ b/client/MenuSetup/manageHouseMenu.lua @@ -6,6 +6,7 @@ RegisterNetEvent('bcc-housing:ReceiveAccessibleHouses') AddEventHandler('bcc-housing:ReceiveAccessibleHouses', function(accessibleHouses) devPrint("Received accessible houses list from server") PlayerAccessibleHouses = accessibleHouses + end) -- Function to check if the player has access to a specific house @@ -292,7 +293,7 @@ AddEventHandler('bcc-housing:openmenu', function(houseId, isOwner) style = {} }, function() if houseId then - TriggerEvent('bcc-housing:addLedger', houseId) + TriggerEvent('bcc-housing:addLedger', houseId, isOwner) else devPrint("Error: HouseId is undefined or invalid.") end @@ -325,7 +326,7 @@ function enterOrExitHouse(enter, tpHouseIndex) end RegisterNetEvent('bcc-housing:addLedger') -AddEventHandler('bcc-housing:addLedger', function(houseId) +AddEventHandler('bcc-housing:addLedger', function(houseId, isOwner) devPrint("Adding ledger for House ID: " .. tostring(houseId)) local AddLedgerPage = BCCHousingMenu:RegisterPage('add_ledger_page') local amountToInsert = nil @@ -374,7 +375,8 @@ AddEventHandler('bcc-housing:addLedger', function(houseId) slot = "footer", style = {} }, function() - TriggerEvent('bcc-housing:openmenu', houseId, true) + -- Reopen the menu with the correct ownership status + TriggerEvent('bcc-housing:openmenu', houseId, isOwner) end) AddLedgerPage:RegisterElement('bottomline', { From de555e2dc95a129f8970ec24d5414605853da822 Mon Sep 17 00:00:00 2001 From: iseeyoucopy Date: Mon, 26 Aug 2024 13:17:33 +0100 Subject: [PATCH 4/5] update Readme --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1cb7e33..8909931 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ - Can add as many furniture items as you want in the config! - House owners can buy furniture and place it around thier house! - House owners can sell the furniture they bought! +- House owners can give and/or remove access to players +- When players approach a house, they will receive a notification indicating that they have entered private property. - Easy to translate! - In depth webhooks! - Built in hotel system! @@ -34,8 +36,8 @@ - Database will run automatically! # Custom Interiors Coords (Credits to punchedgang/siddwell740) -Siddin3 = {x = -1103.15, y = -2252.92, z = 50.65} -Siddin4 = {x = -63.74, y = 14.05, z = 76.6} +- Siddin3 = {x = -1103.15, y = -2252.92, z = 50.65} +- Siddin4 = {x = -63.74, y = 14.05, z = 76.6} # Side Notes - This is a massive project there is most likely oversights if you have any suggestions or bugs report them asap! From e13aaacb098450b9da666572d97f1062cae75f66 Mon Sep 17 00:00:00 2001 From: iseeyoucopy Date: Mon, 26 Aug 2024 13:38:57 +0100 Subject: [PATCH 5/5] few more changes - Beautified the configuration file for better readability and more info. - Updated the Discord webhook to include customizable titles and avatars. - Added a configurable keybinding for managing houses. - Incremented the version number. --- client/functions.lua | 112 ++++++++++++++++++----------------- config.lua | 96 ++++++++++++++++++++---------- fxmanifest.lua | 2 +- server/helpers/functions.lua | 2 +- 4 files changed, 125 insertions(+), 87 deletions(-) diff --git a/client/functions.lua b/client/functions.lua index 06b480a..f32caf6 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -1,84 +1,86 @@ ----- Pulling Essentials ----- VORPcore = exports.vorp_core:GetCore() -FeatherMenu = exports['feather-menu'].initiate() -BccUtils = exports['bcc-utils'].initiate() +FeatherMenu = exports["feather-menu"].initiate() +BccUtils = exports["bcc-utils"].initiate() +MiniGame = exports["bcc-minigames"].initiate() -BCCHousingMenu = FeatherMenu:RegisterMenu('bcc:housing:mainmenu', { - top = '5%', - left = '5%', - ['720width'] = '500px', - ['1080width'] = '600px', - ['2kwidth'] = '700px', - ['4kwidth'] = '900px', - style = {}, - contentslot = { - style = { - ['height'] = '450px', - ['min-height'] = '250px' +BCCHousingMenu = FeatherMenu:RegisterMenu("bcc:housing:mainmenu", + { + top = "5%", + left = "5%", + ["720width"] = "500px", + ["1080width"] = "600px", + ["2kwidth"] = "700px", + ["4kwidth"] = "900px", + style = {}, + contentslot = { + style = { + ["height"] = "450px", + ["min-height"] = "250px" + } + }, + draggable = true + }, + { + opened = function() + DisplayRadar(false) + end, + closed = function() + DisplayRadar(true) + end } - }, - draggable = true -}, { - opened = function() - DisplayRadar(false) - end, - closed = function() - DisplayRadar(true) - end, -}) - -BccUtils = exports['bcc-utils'].initiate() -MiniGame = exports['bcc-minigames'].initiate() +) -------- Get Players Function -------- function GetPlayers() - TriggerServerEvent("bcc-housing:GetPlayers") - local playersData = {} - RegisterNetEvent("bcc-housing:SendPlayers", function(result) - playersData = result - end) - while next(playersData) == nil do - Wait(10) - end - return playersData + TriggerServerEvent("bcc-housing:GetPlayers") + local playersData = {} + RegisterNetEvent("bcc-housing:SendPlayers", function(result) + playersData = result + end) + + while next(playersData) == nil do + Wait(10) + end + return playersData end function GetPlayersWithAccess(houseId, callback) - devPrint("Requesting players with access for House ID: " .. tostring(houseId)) - - RegisterNetEvent("bcc-housing:ReceivePlayersWithAccess", function(result) - -- Debugging the data received from the server - devPrint("Received players data from server for House ID: " .. tostring(houseId)) - devPrint("Number of players with access received: " .. tostring(#result)) - - -- Trigger the callback with the results - callback(result) - end) + devPrint("Requesting players with access for House ID: " .. tostring(houseId)) + + RegisterNetEvent("bcc-housing:ReceivePlayersWithAccess", function(result) + -- Debugging the data received from the server + devPrint("Received players data from server for House ID: " .. tostring(houseId)) + devPrint("Number of players with access received: " .. tostring(#result)) + + -- Trigger the callback with the results + callback(result) + end) - -- Trigger the server event to fetch players with access - TriggerServerEvent("bcc-housing:getPlayersWithAccess", houseId) + -- Trigger the server event to fetch players with access + TriggerServerEvent("bcc-housing:getPlayersWithAccess", houseId) end function showManageOpt(x, y, z, houseId) local PromptGroup = BccUtils.Prompts:SetupPromptGroup() - local firstprompt = PromptGroup:RegisterPrompt(_U("openOwnerManage"), 0x760A9C6F, 1, 1, true, 'hold', { timedeventhash = "MEDIUM_TIMED_EVENT" }) - + local firstprompt = PromptGroup:RegisterPrompt(_U("openOwnerManage"), Config.keys.manage, 1, 1, true, 'hold', { timedeventhash = "MEDIUM_TIMED_EVENT" }) + devPrint("Setting up manage options for House ID: " .. tostring(houseId) .. " at coordinates: " .. tostring(x) .. ", " .. tostring(y) .. ", " .. tostring(z)) - + while true do Wait(5) - if BreakHandleLoop then + if BreakHandleLoop then devPrint("Breaking handle loop for House ID: " .. tostring(houseId)) - break + break end - + local plc = GetEntityCoords(PlayerPedId()) local dist = GetDistanceBetweenCoords(plc.x, plc.y, plc.z, x, y, z, true) if dist < 2 then PromptGroup:ShowGroup(_U("house")) - + if firstprompt:HasCompleted() then devPrint("Prompt completed. Opening housing management menu for House ID: " .. tostring(houseId)) TriggerServerEvent('bcc-housing:getHouseOwner', houseId) diff --git a/config.lua b/config.lua index 8039554..f9ebba4 100644 --- a/config.lua +++ b/config.lua @@ -1,59 +1,88 @@ Config = { - defaultlang = 'en_lang', --set your language here - adminGroup = 'admin', --set your admin group here - DevMode = false, --False on live server + -- Set your language here + defaultlang = 'en_lang', + ----------------------------------------------------- + + -- Set your admin group here + adminGroup = 'admin', + ----------------------------------------------------- + + DevMode = true, --False on live server + ----------------------------------------------------- + + --Maximum allowed houses per character Setup = { - MaxHousePerChar = 2, --Maximum allowed houses per character + MaxHousePerChar = 2, }, - TaxDay = 23, --This is the number day of each month that taxes will be collected on - TaxResetDay = 24, --This MUST be the day after TaxDay set above!!! (do not change either of these dates if the current date is one of the 2 for ex if its the 22 or 23rd day do not change these dates it will break the code) - WebhookLink = '', --insert your webhook link here if you want webhooks + ----------------------------------------------------- + + -- Tax Day for checking the ledger and collect + TaxDay = 23, --This is the number day of each month that taxes will be collected on + TaxResetDay = 24, --This MUST be the day after TaxDay set above!!! (do not change either of these dates if the current date is one of the 2 for ex if its the 22 or 23rd day do not change these dates it will break the code) + ----------------------------------------------------- + + -- Discord Webhooks + WebhookLink = '', --insert your webhook link here if you want webhooks + WebhookTitle = 'BCC-Housing', + WebhookAvatar = '', + ----------------------------------------------------- + + -- Admin Commands AdminManagementMenuCommand = 'HousingManager', --the name of the command for admins to manage all houses - EnablePrivatePropertyCheck = false, -- Set to true to enable, false to disable, this is for if you want to see a message that you enterd on a private property + EnablePrivatePropertyCheck = true, -- Set to true to enable, false to disable, this is for if you want to see a message that you enterd on a private property + keys = { + manage = 0x760A9C6F -- [G] Manage House + }, + ----------------------------------------------------- + + -- Hotels Hotels = { { - hotelId = 1, --Make sure this is a unique number for each hotel (once set do not change it will break!) + hotelId = 1, --Make sure this is a unique number for each hotel (once set do not change it will break!) location = { x = -322.12, y = 767.12, z = 121.63 }, --location of where you will buy and enter the hotel room - cost = 40, --cost to buy the hotel room - invSpace = 100, --Amount of inventory room the hotel will have + cost = 40, --cost to buy the hotel room + invSpace = 100, --Amount of inventory room the hotel will have }, { - hotelId = 2, --Make sure this is a unique number for each hotel (once set do not change it will break!) + hotelId = 2, --Make sure this is a unique number for each hotel (once set do not change it will break!) location = { x = 1343.59, y = -1302.07, z = 77.42 }, --location of where you will buy and enter the hotel room - cost = 40, --cost to buy the hotel room - invSpace = 100, --Amount of inventory room the hotel will have + cost = 40, --cost to buy the hotel room + invSpace = 100, --Amount of inventory room the hotel will have }, { - hotelId = 3, --Make sure this is a unique number for each hotel (once set do not change it will break!) + hotelId = 3, --Make sure this is a unique number for each hotel (once set do not change it will break!) location = { x = 2671.97, y = -1219.82, z = 53.3 }, --location of where you will buy and enter the hotel room - cost = 40, --cost to buy the hotel room - invSpace = 100, --Amount of inventory room the hotel will have + cost = 40, --cost to buy the hotel room + invSpace = 100, --Amount of inventory room the hotel will have }, { - hotelId = 4, --Make sure this is a unique number for each hotel (once set do not change it will break!) + hotelId = 4, --Make sure this is a unique number for each hotel (once set do not change it will break!) location = { x = 2769.85, y = -1337.6, z = 46.46 }, --location of where you will buy and enter the hotel room - cost = 40, --cost to buy the hotel room - invSpace = 100, --Amount of inventory room the hotel will have + cost = 40, --cost to buy the hotel room + invSpace = 100, --Amount of inventory room the hotel will have }, { - hotelId = 5, --Make sure this is a unique number for each hotel (once set do not change it will break!) + hotelId = 5, --Make sure this is a unique number for each hotel (once set do not change it will break!) location = { x = -1778.39, y = -375.34, z = 159.91 }, --location of where you will buy and enter the hotel room - cost = 40, --cost to buy the hotel room - invSpace = 100, --Amount of inventory room the hotel will have + cost = 40, --cost to buy the hotel room + invSpace = 100, --Amount of inventory room the hotel will have }, { - hotelId = 6, --Make sure this is a unique number for each hotel (once set do not change it will break!) + hotelId = 6, --Make sure this is a unique number for each hotel (once set do not change it will break!) location = { x = -790.34, y = -1264.38, z = 43.63 }, --location of where you will buy and enter the hotel room - cost = 40, --cost to buy the hotel room - invSpace = 100, --Amount of inventory room the hotel will have + cost = 40, --cost to buy the hotel room + invSpace = 100, --Amount of inventory room the hotel will have }, { - hotelId = 7, --Make sure this is a unique number for each hotel (once set do not change it will break!) + hotelId = 7, --Make sure this is a unique number for each hotel (once set do not change it will break!) location = { x = 2958.83, y = 483.01, z = 47.77 }, --location of where you will buy and enter the hotel room - cost = 40, --cost to buy the hotel room - invSpace = 100, --Amount of inventory room the hotel will have + cost = 40, --cost to buy the hotel room + invSpace = 100, --Amount of inventory room the hotel will have }, }, + ----------------------------------------------------- + + -- Furnitures Furniture = { chairs = { { propModel = 'p_chair14x', displayName = 'Gardenchar', costToBuy = 50, sellFor = 30 }, @@ -185,11 +214,18 @@ Config = { { propModel = 'p_lightpostnbx01x', displayName = 'Lightpole 6', costToBuy = 20, sellFor = 10 }, } }, - ALlowedJobs = { --these are jobs that will be able to make houses just like the admins can above useful for real estate jobs + ----------------------------------------------------- + + -- These are jobs that will be able to make houses just like the admins can above useful for real estate jobs + ALlowedJobs = { { jobname = '' --the job name }, --to add more just copy this table paste and change job name }, + ----------------------------------------------------- + -- TP Houses + -- Here you need to add coordinates for interiors which doors cannot be open, you need to enter in the house with Noclip and get the coords + -- Make sure you add the cordinates before create the TP House TpInteriors = { Interior1 = { exitCoords = { x = -1103.15, y = -2252.92, z = 50.65 }, diff --git a/fxmanifest.lua b/fxmanifest.lua index 3d0e134..c8f841b 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -45,4 +45,4 @@ dependency { -- u can set doors but if u set one with an id first it will break so u have to set one without an id first then add id doors -version '1.0.6' +version '1.0.7' diff --git a/server/helpers/functions.lua b/server/helpers/functions.lua index 5d60499..2dc727d 100644 --- a/server/helpers/functions.lua +++ b/server/helpers/functions.lua @@ -2,7 +2,7 @@ VORPcore = exports.vorp_core:GetCore() BccUtils = exports['bcc-utils'].initiate() -Discord = BccUtils.Discord.setup(Config.WebhookLink, 'bcc-housing', '') +Discord = BccUtils.Discord.setup(Config.WebhookLink, Config.WebhookTitle, Config.WebhookAvatar) DbUpdated = false -- Use this to stop taxes from running till db has been made