Remove example scripts and update core logic
Deleted all files in the examples directory to clean up unused or test scripts. Updated fxmanifest.lua to enable ox_lib initialization. Improved error handling and entity tracking in utility functions, added prop removal, and made minor localization and code style adjustments throughout the codebase. Significant reword of inventory module, notification module, and framework module. Added support for wasabi_uikit, added support for keep-progressbars,
This commit is contained in:
1 parent
c40a260ea2
commit
343af95794
100 files changed
+2403
-2755
No files matched your search
@@ -1,46 +1,57 @@
|
||||
---@diagnostic disable: duplicate-set-field
|
||||
Shops = Shops or {}
|
||||
|
||||
RegisterNetEvent('community_bridge:openShop', function(_type, _title, shopData)
|
||||
---This is an internal event used to be hit from server for the shop context menus. Please do not use this event directly.
|
||||
---@param shopType string
|
||||
---@param shopLabel string
|
||||
---@param shopData table
|
||||
RegisterNetEvent('community_bridge:Client:openShop', function(shopType, shopLabel, 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)
|
||||
if not shopType or not shopLabel or not shopData then return end
|
||||
if shopType ~= 'shop' then return end
|
||||
Shops.OpenShop(shopLabel, shopData.inventory)
|
||||
end)
|
||||
|
||||
---This is an internal event that is used to complete a transaction and offer cash/card pay
|
||||
---This is an internal function that is used to complete a transaction and offer cash/card pay. Please do not use this function directly.
|
||||
---@param shopName string
|
||||
---@param item string
|
||||
---@param itemLabel string
|
||||
---@param price number
|
||||
---@param amount number
|
||||
Shops.FinalizeCheckOut = function(shopName, item, itemLabel, price, amount)
|
||||
if not shopName and not item and not itemLabel and not price then return end
|
||||
local mathStuff = tonumber(price) * tonumber(amount)
|
||||
local mathStuff = (tonumber(price) * tonumber(amount))
|
||||
local generatedID = Ids.CreateUniqueId()
|
||||
local buildMenu = {
|
||||
{
|
||||
title = string.format(locale('Shops.PayByCash'), tostring(mathStuff)),
|
||||
description = string.format(locale('Shops.AreYouSure'), itemLabel),
|
||||
title = locale('Shops.PayByCash', tostring(mathStuff)),
|
||||
description = locale('Shops.AreYouSure', itemLabel),
|
||||
icon = locale('Shops.CashIcon'),
|
||||
onSelect = function(_, __, ___)
|
||||
TriggerServerEvent('community_bridge:completeCheckout', shopName, item, amount, "money")
|
||||
TriggerServerEvent('community_bridge:Server:completeCheckout', shopName, item, amount, "money")
|
||||
end
|
||||
},
|
||||
{
|
||||
title = string.format(locale('Shops.PayByCard'), tostring(mathStuff)),
|
||||
description = string.format(locale('Shops.AreYouSure'), itemLabel),
|
||||
title = locale('Shops.PayByCard', tostring(mathStuff)),
|
||||
description = locale('Shops.AreYouSure', itemLabel),
|
||||
icon = locale('Shops.CardIcon'),
|
||||
onSelect = function(_, __, ___)
|
||||
TriggerServerEvent('community_bridge:completeCheckout', shopName, item, amount, "bank")
|
||||
TriggerServerEvent('community_bridge:Server:completeCheckout', shopName, item, amount, "bank")
|
||||
end
|
||||
}
|
||||
}
|
||||
Menu.Open({ id = generatedID, title = locale("Shops.Input"), options = buildMenu }, false)
|
||||
end
|
||||
|
||||
---This is an internal event that is used to open the amount select menu
|
||||
---This is an internal functions that is used to open the amount select menu. Please do not use this function directly.
|
||||
---@param shopName string
|
||||
---@param item string
|
||||
---@param itemLabel string
|
||||
---@param price number
|
||||
Shops.AmountSelect = function(shopName, item, itemLabel, price)
|
||||
if not shopName and not item and not itemLabel and not price then return end
|
||||
if not tonumber(price) then return end
|
||||
if price <= 0 then return end
|
||||
local numberOptions = {}
|
||||
for i = 1, 100 do
|
||||
table.insert(numberOptions, {label = tostring(i), value = i})
|
||||
@@ -54,28 +65,27 @@ Shops.AmountSelect = function(shopName, item, itemLabel, price)
|
||||
end
|
||||
end
|
||||
|
||||
---This will open a shop with the passed title and data. It will create a menu with the items in the shopData table. The items will be clickable and will open a checkout menu.
|
||||
---This will open a shop with the passed shopName and data. It will create a menu with the items in the shopData table. The items will be clickable and will open a checkout menu.
|
||||
---This also verifies the shop exsists and was made first server side. This will not work when only used client side and the server side verifies the item exsists in the table as well as the shop id.
|
||||
---@param title any
|
||||
---@param shopData any
|
||||
---@param shopName string
|
||||
---@param shopData table
|
||||
---@return nil
|
||||
Shops.OpenShop = function(title, shopData)
|
||||
if not title and not shopData and not title then return Prints.Error("No Title Passed") end
|
||||
Shops.OpenShop = function(shopName, shopData)
|
||||
if not shopName and not shopData then return print("^6 No Shop Name or Shop Data Passed ^0") 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 = string.format(locale('Shops.CurrencySymbol'), tostring(v.price)),
|
||||
description = locale('Shops.CurrencySymbol', tostring(v.price)),
|
||||
icon = locale('Shops.ShopIcon'),
|
||||
onSelect = function(selected, secondary, args)
|
||||
Shops.AmountSelect(title, v.name, getItemName, v.price)
|
||||
--Shops.FinalizeCheckOut(title, v.name, getItemName, v.price)
|
||||
Shops.AmountSelect(shopName, v.name, getItemName, v.price)
|
||||
end
|
||||
})
|
||||
end
|
||||
Menu.Open({ id = generatedID, title = title, options = buildMenu }, false)
|
||||
Menu.Open({ id = generatedID, title = shopName, options = buildMenu }, false)
|
||||
end
|
||||
|
||||
return Shops
|
||||
@@ -3,41 +3,46 @@ Shops = Shops or {}
|
||||
|
||||
local registeredShops = {}
|
||||
|
||||
local Language = Language or Require("modules/locales/shared.lua")
|
||||
local locales = Language.Locale
|
||||
|
||||
---This can open a shop for the client
|
||||
---@param src number
|
||||
---@param shopTitle string
|
||||
---@param shopName string
|
||||
---@return boolean
|
||||
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])
|
||||
Shops.OpenShop = function(src, shopName)
|
||||
if not shopName and not registeredShops[shopName] then return false, print("community_bridge PLAYERID "..src.." attempted to open invalid shop: "..shopName) end
|
||||
TriggerClientEvent('community_bridge:Client:openShop', src, 'shop', shopName, registeredShops[shopName])
|
||||
return true
|
||||
end
|
||||
|
||||
---This will create a shop to use on the client side, shops must be registered server side and exsist in the shop inventory table to allow any purchases passed.
|
||||
---@param shopTitle string
|
||||
---@param shopName string
|
||||
---@param shopInventory table
|
||||
---@param shopCoords table
|
||||
---@param shopGroups table
|
||||
---@return boolean
|
||||
Shops.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
|
||||
if not shopTitle and not shopInventory and not shopCoords then return false end
|
||||
if registeredShops[shopTitle] then return true end
|
||||
registeredShops[shopTitle] = {name = shopTitle, inventory = shopInventory, shopCoords = shopCoords, groups = shopGroups}
|
||||
Shops.CreateShop = function(shopName, shopInventory, shopCoords, shopGroups)
|
||||
if not shopName and not shopInventory and not shopCoords then return false end
|
||||
if registeredShops[shopName] then return true end
|
||||
registeredShops[shopName] = {name = shopName, inventory = shopInventory, shopCoords = shopCoords, groups = shopGroups}
|
||||
return true
|
||||
end
|
||||
|
||||
---This is an internal event to complete a shop transaction, it will verify pass items and amounts are registered to the created shop.
|
||||
---This is an internal event to complete a shop transaction, it will verify pass items and amounts are registered to the created shop. Please do not use this function directly.
|
||||
---@param src number
|
||||
---@param shopName string
|
||||
---@param item string
|
||||
---@param amount number
|
||||
---@param paymentType string
|
||||
---@param account string
|
||||
---@return nil
|
||||
Shops.CompleteCheckout = function(src, shopName, item, amount, paymentType)
|
||||
if not src and not shopName and not item and not amount and not paymentType then return end
|
||||
local ilocale = Language.Locale
|
||||
Shops.CompleteCheckout = function(src, shopName, item, amount, account)
|
||||
if not src or not shopName or not item or not amount or not account then return end
|
||||
if not amount or amount <= 0 then return end
|
||||
|
||||
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
|
||||
@@ -45,22 +50,38 @@ Shops.CompleteCheckout = function(src, shopName, item, amount, paymentType)
|
||||
break
|
||||
end
|
||||
end
|
||||
if not itemData then return Prints.Error("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)
|
||||
local mathStuff = tonumber(itemData.price) * tonumber(amount)
|
||||
if balance < mathStuff then return Notify.SendNotify(src, ilocale('Shops.NotEnoughMoney'), "error", 5000) end
|
||||
if not Framework.RemoveAccountBalance(src, paymentType, mathStuff) then return end
|
||||
Inventory.AddItem(src, itemData.name, tonumber(amount))
|
||||
local itemLabel = Inventory.GetItemInfo(itemData.name).label
|
||||
Notify.SendNotify(src, ilocale('Shops.PurchasedItem')..itemLabel, "success", 5000)
|
||||
if not itemData or not itemData.price then return print("community_bridge Player ID "..src.." attempted to purchase invalid item from shop: "..shopName) end
|
||||
if itemData.count and itemData.count <= 0 then return Notify.SendNotify(src, locales('Shops.NotEnoughStock'), "error", 5000) end
|
||||
local totalCost = tonumber(itemData.price) * amount
|
||||
local balance = Framework.GetAccountBalance(src, account)
|
||||
if not balance then return end
|
||||
if balance <= 0 then return Notify.SendNotify(src, locales('Shops.NotEnoughMoney'), "error", 5000) end
|
||||
if balance < totalCost then return Notify.SendNotify(src, locales('Shops.NotEnoughMoney'), "error", 5000) end
|
||||
|
||||
if not Framework.RemoveAccountBalance(src, account, totalCost) then return end
|
||||
|
||||
local success = Inventory.AddItem(src, itemData.name, amount)
|
||||
if not success then
|
||||
Framework.AddAccountBalance(src, account, totalCost)
|
||||
return Notify.SendNotify(src, locales('Shops.PurchaseFailed'), "error", 5000)
|
||||
end
|
||||
|
||||
local itemLabel = Inventory.GetItemInfo(itemData.name).label or itemData.name
|
||||
Notify.SendNotify(src, locales('Shops.PurchasedItem', itemLabel), "success", 5000)
|
||||
end
|
||||
|
||||
RegisterNetEvent("community_bridge:completeCheckout", function(shopName, item, amount, paymentType)
|
||||
---This is an internal event to complete a checkout, complete with multiple validations. Please do not use this event directly.
|
||||
---@param shopName string
|
||||
---@param item string
|
||||
---@param amount number
|
||||
---@param account string
|
||||
RegisterNetEvent("community_bridge:Server:completeCheckout", function(shopName, item, amount, account)
|
||||
local src = source
|
||||
if not shopName and not item and not paymentType then return end
|
||||
if not paymentType == "money" or not paymentType == "bank" then return end
|
||||
Shops.CompleteCheckout(src, shopName, item, amount, paymentType)
|
||||
if not shopName or not item or not account or not amount then return end
|
||||
if account ~= "money" and account ~= "bank" then return end
|
||||
amount = tonumber(amount)
|
||||
if not amount or amount <= 0 then return end
|
||||
Shops.CompleteCheckout(src, shopName, item, amount, account)
|
||||
end)
|
||||
|
||||
return Shops
|
||||
return Shops
|
||||
Reference in new issue
Block a user