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:
x
function Debug(text) if Config.Debug then print("^3[DEBUG] "..text.."^0") endendfunction DebugSQL(text) if Config.DebugSQL then print("^5[DEBUG SQL] "..text.."^0") endendSQL 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.") end else DebugSQL("Invalid database option in Config.Database") endendCode 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) if not previousResult[1] then ProcessCodeActivation(playerId, identifier, codeData) else Notify(Config.Text['only_one'], playerId) end end) else ProcessCodeActivation(playerId, identifier, codeData) end else Debug("Code has already been activated by this player.") Notify(Config.Text['already_used'], playerId) end end) else Debug("Invalid code.") Notify(Config.Text['no_code'], playerId) end end)endReward 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) endendDiscord 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' }) endendWas this page helpful?