2025-06-21 07:45:56 -04:00
---@diagnostic disable: duplicate-set-field
2025-03-09 05:49:05 -04:00
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 )
2025-04-02 07:27:13 -04:00
---This is an internal event that is used to complete a transaction and offer cash/card pay
2025-03-09 06:14:38 -04:00
Shops.FinalizeCheckOut = function ( shopName , item , itemLabel , price , amount )
2025-03-09 05:49:05 -04:00
if not shopName and not item and not itemLabel and not price then return end
2025-03-09 06:14:38 -04:00
local mathStuff = tonumber ( price ) * tonumber ( amount )
2025-03-09 05:49:05 -04:00
local generatedID = Ids.CreateUniqueId ()
local buildMenu = {
{
2025-07-10 13:50:47 -04:00
title = string.format ( locale ( 'Shops.PayByCash' ), tostring ( mathStuff )),
description = string.format ( locale ( 'Shops.AreYouSure' ), itemLabel ),
icon = locale ( 'Shops.CashIcon' ),
2025-03-09 05:49:05 -04:00
onSelect = function ( _ , __ , ___ )
2025-03-09 06:14:38 -04:00
TriggerServerEvent ( 'community_bridge:completeCheckout' , shopName , item , amount , "money" )
2025-03-09 05:49:05 -04:00
end
},
{
2025-07-10 13:50:47 -04:00
title = string.format ( locale ( 'Shops.PayByCard' ), tostring ( mathStuff )),
description = string.format ( locale ( 'Shops.AreYouSure' ), itemLabel ),
icon = locale ( 'Shops.CardIcon' ),
2025-03-09 05:49:05 -04:00
onSelect = function ( _ , __ , ___ )
2025-03-09 06:14:38 -04:00
TriggerServerEvent ( 'community_bridge:completeCheckout' , shopName , item , amount , "bank" )
2025-03-09 05:49:05 -04:00
end
}
}
Menu.Open ({ id = generatedID , title = locale ( "Shops.Input" ), options = buildMenu }, false )
end
2025-04-02 07:27:13 -04:00
---This is an internal event that is used to open the amount select menu
---@param shopName string
---@param item string
---@param itemLabel string
---@param price number
2025-03-09 05:49:05 -04:00
Shops.AmountSelect = function ( shopName , item , itemLabel , price )
if not shopName and not item and not itemLabel and not price then return end
2025-03-09 06:14:38 -04:00
local numberOptions = {}
for i = 1 , 100 do
table.insert ( numberOptions , { label = tostring ( i ), value = i })
end
local _input = Input.Open ( shopName , {
{ type = 'select' , label = locale ( "Shops.PurchaseAmount" ), options = numberOptions },
})
if _input and _input [ 1 ] then
Shops.FinalizeCheckOut ( shopName , item , itemLabel , price , tostring ( _input [ 1 ]))
end
2025-03-09 05:49:05 -04:00
end
2025-04-02 07:27:13 -04:00
---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 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
---@return nil
2025-03-09 05:49:05 -04:00
Shops.OpenShop = function ( title , shopData )
2025-04-12 02:31:47 -04:00
if not title and not shopData and not title then return Prints.Error ( "No Title Passed" ) end
2025-03-09 05:49:05 -04:00
local generatedID = Ids.CreateUniqueId ()
local buildMenu = {}
for _ , v in pairs ( shopData ) do
local getItemName = Inventory.GetItemInfo ( v.name ). label
table.insert ( buildMenu , {
title = getItemName ,
2025-07-10 13:50:47 -04:00
description = string.format ( locale ( 'Shops.CurrencySymbol' ), tostring ( v.price )),
icon = locale ( 'Shops.ShopIcon' ),
2025-03-09 05:49:05 -04:00
onSelect = function ( selected , secondary , args )
2025-03-09 06:14:38 -04:00
Shops.AmountSelect ( title , v.name , getItemName , v.price )
--Shops.FinalizeCheckOut(title, v.name, getItemName, v.price)
2025-03-09 05:49:05 -04:00
end
})
end
Menu.Open ({ id = generatedID , title = title , options = buildMenu }, false )
2025-04-13 10:46:06 +01:00
end
2025-05-10 00:01:56 -04:00
return Shops