From e54213398e91e26a186e7b7998ce5fedfc7859a1 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Sun, 9 Mar 2025 05:49:05 -0400 Subject: [PATCH] wip --- fxmanifest.lua | 2 + init.lua | 1 + locales/en.json | 1 + modules/inventory/ox_inventory/server.lua | 2 +- modules/shops/_default/client.lua | 100 ++++++++++++++++++++++ modules/shops/_default/server.lua | 44 ++++++++++ 6 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 modules/shops/_default/client.lua create mode 100644 modules/shops/_default/server.lua diff --git a/fxmanifest.lua b/fxmanifest.lua index 63ec190..d83beed 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -26,6 +26,7 @@ server_scripts { 'modules/managment/**/server.lua', 'modules/dispatch/**/server.lua', 'modules/clothing/**/server.lua', + 'modules/shops/**/server.lua', 'modules/notify/**/server.lua', 'init.lua', } @@ -48,6 +49,7 @@ client_scripts { 'modules/menu/*.lua', 'modules/notify/**/client.lua', 'modules/dialogue/**/client/*.lua', + 'modules/shops/**/client.lua', 'init.lua', } diff --git a/init.lua b/init.lua index d83ee02..fc9ec63 100644 --- a/init.lua +++ b/init.lua @@ -52,6 +52,7 @@ Bridge.RegisterModule("Language", Language) Bridge.RegisterModule("Doorlock", Doorlock) Bridge.RegisterModule("Phone", Phone) Bridge.RegisterModule("Dispatch", Dispatch) +Bridge.RegisterModule("Shops", Shops) --lib Bridge.RegisterModule("Tables", cLib.Tables) diff --git a/locales/en.json b/locales/en.json index 643f796..1410ada 100644 --- a/locales/en.json +++ b/locales/en.json @@ -6,6 +6,7 @@ "place_object_scroll_down": "[SCROLL DOWN] Turn left", "enter_text": "Enter Text", "no_prop_defined": "You didnt define any object to place", + "Shops": {"NotEnoughMoney": "You dont have enough money to buy this item", "PurchasedItem": "You Have Purchased ", "CurrencySymbol": "$", "Confirm":"Confirm Purchase","AreYouSure":"Are you sure you want to purchase a ", "PayByCash": "Pay by cash", "PayByCard": "Pay by card" }, "UNITTEST": { "UNITTESTA": "Im a %s %s", "UNITTEST": { diff --git a/modules/inventory/ox_inventory/server.lua b/modules/inventory/ox_inventory/server.lua index 51a5293..5749bcf 100644 --- a/modules/inventory/ox_inventory/server.lua +++ b/modules/inventory/ox_inventory/server.lua @@ -118,7 +118,7 @@ Inventory.GetItemInfo = function(item) stack = itemData.stack or "true", weight = itemData.weight or "0", description = itemData.description or "none", - image = itemData.client.image or Inventory.GetImagePath(item), + image = itemData.client and itemData.client.image or Inventory.GetImagePath(item), } return repackedTable end diff --git a/modules/shops/_default/client.lua b/modules/shops/_default/client.lua new file mode 100644 index 0000000..3ffc10a --- /dev/null +++ b/modules/shops/_default/client.lua @@ -0,0 +1,100 @@ +Shops = Shops or {} + +RegisterNetEvent('community_bridge:openShop', function(_type, _title, shopData) + if source ~= 65535 then return end + if not _title and not _title and not shopData then return end + if _type ~= 'shop' then return end + Shops.OpenShop(_title, shopData.inventory) +end) + +Shops.FinalizeCheckOut = function(shopName, item, itemLabel, price) + if not shopName and not item and not itemLabel and not price then return end + local generatedID = Ids.CreateUniqueId() + local buildMenu = { + { + title = locale('Shops.PayByCash')..tostring(price), + description = locale('Shops.AreYouSure') .. itemLabel, + icon = "fa-solid fa-money-bill-wave", + onSelect = function(_, __, ___) + TriggerServerEvent('community_bridge:completeCheckout', shopName, item, "cash") + end + }, + { + title = locale('Shops.PayByCard')..tostring(price), + description = locale('Shops.AreYouSure') .. itemLabel, + icon = "fa-solid fa-building-column", + onSelect = function(_, __, ___) + TriggerServerEvent('community_bridge:completeCheckout', shopName, item, "bank") + end + } + } + Bridge.Menu.Open({ id = generatedID, title = locale("Shops.Confirm"), options = buildMenu }, false) +end + +Shops.FinalizeCheckOut = function(shopName, item, itemLabel, price) + if not shopName and not item and not itemLabel and not price then return end + local generatedID = Ids.CreateUniqueId() + local buildMenu = { + { + title = locale('Shops.PayByCash')..tostring(price), + description = locale('Shops.AreYouSure') .. itemLabel, + icon = "fa-solid fa-money-bill-wave", + onSelect = function(_, __, ___) + TriggerServerEvent('community_bridge:completeCheckout', shopName, item, "cash") + end + }, + { + title = locale('Shops.PayByCard')..tostring(price), + description = locale('Shops.AreYouSure') .. itemLabel, + icon = "fa-solid fa-building-column", + onSelect = function(_, __, ___) + TriggerServerEvent('community_bridge:completeCheckout', shopName, item, "bank") + end + } + } + Menu.Open({ id = generatedID, title = locale("Shops.Input"), options = buildMenu }, false) +end + +--[[ +Shops.AmountSelect = function(shopName, item, itemLabel, price) + if not shopName and not item and not itemLabel and not price then return end + local generatedID = Ids.CreateUniqueId() + local buildMenu = { + { + title = locale('Shops.PayByCash')..tostring(price), + description = locale('Shops.AreYouSure') .. itemLabel, + icon = "fa-solid fa-money-bill-wave", + onSelect = function(_, __, ___) + TriggerServerEvent('community_bridge:completeCheckout', shopName, item, "cash") + end + }, + { + title = locale('Shops.PayByCard')..tostring(price), + description = locale('Shops.AreYouSure') .. itemLabel, + icon = "fa-solid fa-building-column", + onSelect = function(_, __, ___) + TriggerServerEvent('community_bridge:completeCheckout', shopName, item, "bank") + end + } + } + Menu.Open({ id = generatedID, title = locale("Shops.Input"), options = buildMenu }, false) +end +--]] + +Shops.OpenShop = function(title, shopData) + if not title and not shopData and not title then return print("No Title Passed") end + local generatedID = Ids.CreateUniqueId() + local buildMenu = {} + for _, v in pairs(shopData) do + local getItemName = Inventory.GetItemInfo(v.name).label + table.insert(buildMenu, { + title = getItemName, + description = locale('Shops.CurrencySymbol')..tostring(v.price), + icon = "fa-solid fa-basket-shopping", + onSelect = function(selected, secondary, args) + Shops.FinalizeCheckOut(title, v.name, getItemName, v.price) + end + }) + end + Menu.Open({ id = generatedID, title = title, options = buildMenu }, false) +end \ No newline at end of file diff --git a/modules/shops/_default/server.lua b/modules/shops/_default/server.lua new file mode 100644 index 0000000..d698363 --- /dev/null +++ b/modules/shops/_default/server.lua @@ -0,0 +1,44 @@ +Shops = Shops or {} + +local registeredShops = {} + +Shops.OpenShop = function(src, shopTitle) + if not shopTitle and not registeredShops[shopTitle] then return false end + TriggerClientEvent('community_bridge:openShop', src, 'shop', shopTitle, registeredShops[shopTitle]) +end + +Shops.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups) + if not shopTitle and not shopInventory and not shopCoords then return end + if registeredShops[shopTitle] then return true end + registeredShops[shopTitle] = {name = shopTitle, inventory = shopInventory, shopCoords = shopCoords, groups = shopGroups} + return true +end + +Shops.CompleteCheckout = function(src, shopName, item, paymentType) + if not src and not shopName and not item and not paymentType then return end + local ilocale = Language.Locale + local shopData = registeredShops[shopName] + if not shopData then return end + local itemData = nil + for _, data in pairs(shopData.inventory) do + if data.name == item then + itemData = data + break + end + end + if not itemData then return print("Player ID "..src.." Is Possibly A Cheater And Has Attempted To Purchase A "..item) end + if not itemData.price then return end + local balance = Framework.GetAccountBalance(src, paymentType) + if balance < itemData.price then return Notify.SendNotify(src, ilocale('Shops.NotEnoughMoney'), "error", 5000) end + if not Framework.RemoveAccountBalance(src, paymentType, itemData.price) then return end + Inventory.AddItem(src, itemData.name, 1) + local itemLabel = Inventory.GetItemInfo(itemData.name).label + Notify.SendNotify(src, ilocale('Shops.PurchasedItem')..itemLabel, "success", 5000) +end + +RegisterNetEvent("community_bridge:completeCheckout", function(shopName, item, paymentType) + local src = source + if not shopName and not item and not paymentType then return end + if not paymentType == "cash" or not paymentType == "bank" then return end + Shops.CompleteCheckout(src, shopName, item, paymentType) +end) \ No newline at end of file