Make sure to check the qb.lua and esx.lua files for examples on how to implement the script for your framework. They are always up to date with the latest changes.
Framework functions
getIdentifier
This function is used to retrieve a player's identifier to manage and verify tickets.
It is not necessary to modify this function.
-- This is an example from the brnx-cinemasystem esx.lua file
-- @param source: number
function getIdentifier(source)
return GetPlayerIdentifierByType(source, 'license')
end
getBalance
This function is used to retrieve the amount of money a player has in their bank or wallet.
-- This is an example from the brnx-cinemasystem esx.lua file
-- @param source: number
function getBalance(source)
local xPlayer = ESX.GetPlayerFromId(source)
return xPlayer?.getAccount("bank")?.money or 0
end
buyTicket
This function is used to purchase tickets at the cinema counter.
-- This is an example from the brnx-cinemasystem esx.lua file
local INSERT_TICKET <const> = 'INSERT IGNORE INTO brnx_cinema_tickets (identifier, room, schedule) values (?, ?, ?)'
-- @param source: number
-- @param data: table
function buyTicket(source, data)
local xPlayer = ESX.GetPlayerFromId(source)
if (xPlayer) then
local identifier = getIdentifier(source)
local hasTicket = hasTicket(identifier, data.hour)
if (not hasTicket) then
local dataFilm = config.films[data.cinema][data.index]
if (dataFilm.price) and getBalance(source) >= dataFilm.price then
local _insert = { schedule = data.hour, room = tostring(data.room), date = (os.time()*1000) }
table.insert(Tickets[identifier], _insert)
TriggerClientEvent('brnx-cinemasystem:insertTickets', source, _insert)
oxmysql:insert_async(INSERT_TICKET, { identifier, data.room, data.hour })
TriggerClientEvent('brnx-cinemasystem:notify', source, 'success', L('SHOP.PURCHASE_TICKET', {
name = dataFilm.name,
hour = data.hour,
room = data.room
}))
xPlayer.removeAccountMoney("bank", dataFilm.price)
return true
else
TriggerClientEvent('brnx-cinemasystem:notify', source, 'denied', L('SHOP.NO_MONEY'))
end
else
TriggerClientEvent('brnx-cinemasystem:notify', source, 'denied', L('SHOP.HAS_TICKET'))
end
end
return false
end
data:
index: number
hour: string
room: string
cinema: string
buyItem
This function is used to purchase items from the cinema store.
-- This is an example from the brnx-cinemasystem esx.lua file
-- @param source: number
-- @param data: table
-- @param shopOpened: string
function buyItem(source, data, shopOpened)
local xPlayer = ESX.GetPlayerFromId(source)
if (xPlayer) then
local dataShop = config.shop[shopOpened]
if (dataShop) and dataShop[data.index] then
local newData = dataShop[data.index]
if (newData.price) and getBalance(source) >= newData.price then
TriggerClientEvent('brnx-cinemasystem:notify', source, 'success', L('SHOP.PURCHASE', {
name = newData.name,
price = formatCurrency(newData.price, L('CURRENCY'))
}))
xPlayer.removeAccountMoney("bank", newData.price)
return true
end
end
end
return false
end