How does it work?

As always, once I release free script, I want you guys to learn something from it, so I try my best to comment everything so you can learn!

Functions 🚀

Debugging Functions

These functions help you print debug messages:

function Debug(text)
if Config.Debug then
print("^3[DEBUG] "..text.."^0")
end
end

function DebugSQL(text)
if Config.DebugSQL then
print("^5[DEBUG SQL] "..text.."^0")
end
end

SQL Execution Function

Executes SQL queries based on the configured database:

function ExecuteSql(query, params, callback)
DebugSQL("Executing SQL query: " .. query)

if Config.Database == "oxmysql" then
if exports.oxmysql then
exports.oxmysql:execute(query, {}, callback)
else
DebugSQL("oxmysql is not exported. Make sure you have it installed.")
end
elseif Config.Database == "mysql-async" then
if MySQL.Async then
MySQL.Async.execute(query, {}, callback)
else
DebugSQL("mysql-async is not available. Make sure you have it installed.")
end
elseif Config.Database == "ghmattimysql" then
if exports.ghmattimysql then
exports.ghmattimysql:execute(query, {}, callback)
else
DebugSQL("ghmattimysql is not exported. Make sure you have it installed.")

Code Activation Function

Handles the activation of codes by players:

function ActivateCode(playerId, code)
local query = ("SELECT * FROM Domas_IC_Codes WHERE code = '%s';"):format(code)
local identifier = GetPlayerIdentifierByType(playerId, 'license')

ExecuteSql(query, {}, function(result)
if result[1] then
local codeData = result[1]
local activationQuery = ("SELECT * FROM Domas_IC_Players WHERE player = '%s' AND code = '%s';"):format(identifier, code)

ExecuteSql(activationQuery, {}, function(activationResult)
if not activationResult[1] then
if Config.AllowOnlyOne then
local previousActivationQuery = ("SELECT * FROM Domas_IC_Players WHERE player = '%s';"):format(identifier)
ExecuteSql(previousActivationQuery, {}, function(previousResult)

Reward Handling Function

Distributes rewards to players based on the activated code:

function HandleReward(code, playerId)
local rewardData = GetRewardByCode(code)

if rewardData then
if rewardData.type == 'money' then
local amount = rewardData.amount
AddMoney(playerId, amount)
elseif rewardData.type == 'item' then
local item = rewardData.item
local amount = rewardData.amount
GiveItem(playerId, item, amount)
elseif rewardData.type == 'null' then
Debug("Null reward - no action needed")
else
Debug("Unknown reward type:", rewardData.type)
end
else
Debug("No reward data found for code:", code)
end
end

Discord Webhook Handling Function

This feature is very good for logging. Feel free to use it everywhere you like.

function Log2Discord(kodas, playerId)
local name = GetPlayerName(playerId)
if Config.DiscordLog then
local embeds = {
{
["title"]= Config.Text['active_new'],
["type"]="rich",
["color"] = 1770588,
["footer"]= {
["text"]= Config.Text['active_text'],
},
["fields"] = {
{
name = Config.Text['active_player']..name,
value = Config.Text['active_code']..kodas,
},
}
}
}
PerformHttpRequest(Config.Webhook, function(err, text, headers) end, 'POST', json.encode({ username = name,embeds = embeds}), { ['Content-Type'] = 'application/json' })