From c60830965105ffd9cc66d74213d530e5a4c1ee07 Mon Sep 17 00:00:00 2001 From: Rian <74205343+complexza@users.noreply.github.com> Date: Mon, 31 Jul 2023 22:52:27 +0200 Subject: [PATCH] Logs Added (#77) --- README.md | 11 +++++++++++ server/server.lua | 3 +++ server/sv_property.lua | 27 +++++++++++++++++++++++++-- shared/config.lua | 4 ++++ shared/framework.lua | 10 ++++++++++ 5 files changed, 53 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c8e474a..e2759c2 100644 --- a/README.md +++ b/README.md @@ -265,6 +265,17 @@ end) 10. Install the dependencies below. +## Logs System Setup + +1. Go to `qb-smallresources/server/logs.lua` and add this: +```lua + ['pshousing'] = 'yourdiscordwebhookhere', +``` +2. Create a webhook for the channel you want the logs to show up in. +3. Replace the placeholder with your webhook link. + +> This system only supports qb-core for now. + # Dependency 1. [bl-realtor](https://github.com/Byte-Labs-Project/bl-realtor) 2. [five-freecam](https://github.com/Deltanic/fivem-freecam) diff --git a/server/server.lua b/server/server.lua index 65a0d69..469298d 100644 --- a/server/server.lua +++ b/server/server.lua @@ -137,6 +137,9 @@ RegisterNetEvent("ps-housing:server:createNewApartment", function(aptLabel) } Debug("Creating new apartment for " .. GetPlayerName(src) .. " in " .. apartment.label) + + Framework[Config.Logs].SendLog("Creating new apartment for " .. GetPlayerName(src) .. " in " .. apartment.label) + TriggerEvent("ps-housing:server:registerProperty", propertyData) end) diff --git a/server/sv_property.lua b/server/sv_property.lua index 60545bf..67cc098 100644 --- a/server/sv_property.lua +++ b/server/sv_property.lua @@ -163,6 +163,8 @@ function Property:UpdateDescription(data) TriggerClientEvent("ps-housing:client:updateProperty", -1, "UpdateDescription", self.property_id, description) + Framework[Config.Logs].SendLog("**Changed Description** of property with id: " .. self.property_id .. " by: " .. GetPlayerName(realtorSrc)) + Debug("Changed Description of property with id: " .. self.property_id, "by: " .. GetPlayerName(realtorSrc)) end @@ -181,6 +183,8 @@ function Property:UpdatePrice(data) TriggerClientEvent("ps-housing:client:updateProperty", -1, "UpdatePrice", self.property_id, price) + Framework[Config.Logs].SendLog("**Changed Price** of property with id: " .. self.property_id .. " by: " .. GetPlayerName(realtorSrc)) + Debug("Changed Price of property with id: " .. self.property_id, "by: " .. GetPlayerName(realtorSrc)) end @@ -197,6 +201,8 @@ function Property:UpdateForSale(data) TriggerClientEvent("ps-housing:client:updateProperty", -1, "UpdateForSale", self.property_id, forsale) + Framework[Config.Logs].SendLog("**Changed For Sale** of property with id: " .. self.property_id .. " by: " .. GetPlayerName(realtorSrc)) + Debug("Changed For Sale of property with id: " .. self.property_id, "by: " .. GetPlayerName(realtorSrc)) end @@ -215,6 +221,8 @@ function Property:UpdateShell(data) TriggerClientEvent("ps-housing:client:updateProperty", -1, "UpdateShell", self.property_id, shell) + Framework[Config.Logs].SendLog("**Changed Shell** of property with id: " .. self.property_id .. " by: " .. GetPlayerName(realtorSrc)) + Debug("Changed Shell of property with id: " .. self.property_id, "by: " .. GetPlayerName(realtorSrc)) end @@ -288,6 +296,8 @@ function Property:UpdateOwner(data) TriggerClientEvent("ps-housing:client:updateProperty", -1, "UpdateOwner", self.property_id, citizenid) + Framework[Config.Logs].SendLog("**House Bought** by: **"..PlayerData.charinfo.firstname.." "..PlayerData.charinfo.lastname.."** for $"..self.propertyData.price.." from **"..realtor.PlayerData.charinfo.firstname.." "..realtor.PlayerData.charinfo.lastname.."** !") + Framework[Config.Notify].Notify(targetSrc, "You have bought the property for $"..self.propertyData.price, "success") Framework[Config.Notify].Notify(realtorSrc, "Client has bought the property for $"..self.propertyData.price, "success") end @@ -305,6 +315,8 @@ function Property:UpdateImgs(data) TriggerClientEvent("ps-housing:client:updateProperty", -1, "UpdateImgs", self.property_id, imgs) + Framework[Config.Logs].SendLog("**Changed Images** of property with id: " .. self.property_id .. " by: " .. GetPlayerName(realtorSrc)) + Debug("Changed Imgs of property with id: " .. self.property_id, "by: " .. GetPlayerName(realtorSrc)) end @@ -340,6 +352,8 @@ function Property:UpdateDoor(data) TriggerClientEvent("ps-housing:client:updateProperty", -1, "UpdateDoor", self.property_id, newDoor, data.street, data.region) + Framework[Config.Logs].SendLog("**Changed Door** of property with id: " .. self.property_id .. " by: " .. GetPlayerName(realtorSrc)) + Debug("Changed Door of property with id: " .. self.property_id, "by: " .. GetPlayerName(realtorSrc)) end @@ -384,6 +398,8 @@ function Property:UpdateGarage(data) TriggerClientEvent("ps-housing:client:updateProperty", -1, "UpdateGarage", self.property_id, garage) + Framework[Config.Logs].SendLog("**Changed Garage** of property with id: " .. self.property_id .. " by: " .. GetPlayerName(realtorSrc)) + Debug("Changed Garage of property with id: " .. self.property_id, "by: " .. GetPlayerName(realtorSrc)) end @@ -400,9 +416,11 @@ function Property:UpdateApartment(data) }) Framework[Config.Notify].Notify(realtorSrc, "Changed Apartment of property with id: " .. self.property_id .." to ".. apartment, "success") - + Framework[Config.Notify].Notify(targetSrc, "Changed Apartment to " .. apartment, "success") + Framework[Config.Logs].SendLog("**Changed Apartment** with id: " .. self.property_id .. " by: **" .. GetPlayerName(realtorSrc) .. "** for **" .. GetPlayerName(targetSrc) .."**") + TriggerClientEvent("ps-housing:client:updateProperty", -1, "UpdateApartment", self.property_id, apartment) Debug("Changed Apartment of property with id: " .. self.property_id, "by: " .. GetPlayerName(realtorSrc)) @@ -422,7 +440,9 @@ function Property:DeleteProperty(data) TriggerClientEvent("ps-housing:client:removeProperty", -1, self.property_id) Framework[Config.Notify].Notify(realtorSrc, "Property with id: " .. self.property_id .." has been removed.", "info") - + + Framework[Config.Logs].SendLog("**Property Deleted** with id: " .. self.property_id .. " by: " .. GetPlayerName(realtorSrc)) + Debug("Deleted property with id: " .. self.property_id, "by: " .. GetPlayerName(realtorSrc)) PropertiesTable[self.property_id] = nil self = nil @@ -608,6 +628,9 @@ RegisterNetEvent("ps-housing:server:buyFurniture", function(property_id, items, property:UpdateFurnitures(property.propertyData.furnitures) Framework[Config.Notify].Notify(src, "You bought furniture for $" .. price, "success") + + Framework[Config.Logs].SendLog("**Player ".. GetPlayerName(src) .. "** bought furniture for **$" .. price"**") + Debug("Player bought furniture for $" .. price, "by: " .. GetPlayerName(src)) end) diff --git a/shared/config.lua b/shared/config.lua index d01b063..f8a19b1 100644 --- a/shared/config.lua +++ b/shared/config.lua @@ -11,6 +11,7 @@ Config.Target = "ox" -- "ox" or "qb" Config.Notify = "ox" -- "ox" or "qb" Config.Radial = "ox" -- "ox" or "qb" Config.Inventory = "qb" -- "ox" or "qb" +Config.Logs = "qb" -- "qb" -- Anyone provided with keys to a property has the ability to modify its furnishings. Config.AccessCanEditFurniture = true @@ -24,6 +25,9 @@ function Debug(...) end end +-- Log System +Config.EnableLogs = true + -- Enables Dynamic Doors Config.DynamicDoors = false diff --git a/shared/framework.lua b/shared/framework.lua index b5d840a..73912ec 100644 --- a/shared/framework.lua +++ b/shared/framework.lua @@ -29,6 +29,16 @@ if IsDuplicityVersion() then -- Used for ox_inventory compat end + function Framework.qb.SendLog(message) + if Config.EnableLogs then + TriggerEvent('qb-log:server:CreateLog', 'pshousing', 'Housing System', 'blue', message) + end + end + + function Framework.ox.SendLog(message) + -- noop + end + return end