Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added New features, fix some issues #31

Merged
merged 5 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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!
Expand Down
119 changes: 86 additions & 33 deletions client/MainHousing.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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')
Expand All @@ -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
Expand Down Expand Up @@ -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)
75 changes: 56 additions & 19 deletions client/MenuSetup/furnitureMenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@ function FurnitureMenu(houseId)
style = {}
})

-- Register a back button to return to the previous menu
furnitureMainMenu:RegisterElement('button', {
label = _U("buyOwnerFurn"),
style = {}
}, function()
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', {
Expand All @@ -51,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

Expand Down Expand Up @@ -142,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

Expand Down Expand Up @@ -198,7 +205,11 @@ function IndFurnitureTypeMenu(type, houseId)
})

BCCHousingMenu:Open({
startupPage = furnitureTypeMenu
startupPage = furnitureTypeMenu,
sound = {
action = "SELECT",
soundset = "RDRO_Character_Creator_Sounds"
}
})
end

Expand Down Expand Up @@ -229,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
Expand Down Expand Up @@ -291,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)
Expand Down Expand Up @@ -367,13 +388,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
Expand Down Expand Up @@ -424,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
Expand Down Expand Up @@ -469,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)
Expand All @@ -490,4 +527,4 @@ AddEventHandler('bcc-housing:SellOwnedFurnMenu', function(houseId, furnTable)
else
devPrint("Error: furnTable is not a table")
end
end)
end)
Loading