Editable Files

server/commands.lua

local function createRandomCode()
    local newCode = nil
    while true do
        math.randomseed(GetGameTimer())
        local generatedCode = "TGI-"..os.time().."-"..GetRandomLetter(4).."-"..math.random(1000, 9999)
        local result = singleSync('SELECT code FROM tgiann_coinshop_code WHERE code = ? LIMIT 1', {generatedCode})
        if not result then 
            newCode = generatedCode 
            break
        else
            Wait(100)
        end
        Wait(0)
    end
    return newCode
end

local function createCode(codeType, amount, code)
    if not code then code = createRandomCode() end
    if GetCode(code) then
        return false, code
    else
        insertSync('INSERT INTO `tgiann_coinshop_code` (code, codeType, amount) VALUES (?, ?, ?)', {
            code, codeType, amount
        })
        return true, code
    end
end

local function createCodeCommand(src, codeType, amount, code)
    if not codeType or not amount then return end
    if codeType == "money" or codeType == "coin" then
        local created, createdCode = createCode(codeType, amount, code)
        if created then
            tgiCore.notif(src, string.format(lang.codeCreated, createdCode), "success", 60000)
        else
            tgiCore.notif(src, string.format(lang.alreadyCode, createdCode), "error", 60000)
        end
    else
        tgiCore.notif(src, lang.wrongCodeType, "error")
    end
end

local function deleteCodeCommand(src, code)
    if DeleteCode(code) then
        tgiCore.notif(src, lang.codeDeleted, "success")
    else
        tgiCore.notif(src, lang.codeNotFound, "error")
    end
end

if config.framework == "qb" then
    --Give Coin
    tgiCore.core.Commands.Add("givecoin", "Give coins to player", {
        {name="id", help="Player Server ID"}, 
        {name="amount", help="Coin Amount"}
    }, true, function(source, args)
        local id, amount = args[1], args[2]
        if id and amount and not GiveCoin(tonumber(id), tonumber(amount)) then
            tgiCore.notif(source, lang.playerIsOffline, "error")
        end
    end, {"console", "tgi"})

    --Create new code
    tgiCore.core.Commands.Add("createcode", "Create a new code", {
        {name="type", help="money/coin"}, 
        {name="amount", help="Money/Coin Amount"}, 
        {name="code", help="Usable code (not required)"}
    }, false, function(source, args)
        createCodeCommand(source, args[1], args[2], args[3])
    end, {"console", "tgi"})

    --Delete Code
    tgiCore.core.Commands.Add("deletecode", "Delete generated code", {
        {name="code", help="Generated code"}
    }, true, function(source, args)
        deleteCodeCommand(source, args[1])
    end, {"console", "tgi"})
elseif config.framework == "esx" then
    --Give Coin
    tgiCore.core.RegisterCommand({'givecoin'}, 'admin', function(xPlayer, args, showError)
        if args.playerid and args.amount and not GiveCoin(tonumber(args.playerid), tonumber(args.amount)) then
            tgiCore.notif(source, lang.playerIsOffline, "error")
        end
    end, false, {
        help = "Give coins to player",
        arguments = {
            {name = 'playerid', help = 'Player Server ID', type = 'any'},
            {name = 'amount', help = 'Coin Amount', type = 'any'},
        },
    })

    --Create new code
    tgiCore.core.RegisterCommand({'createcode'}, 'admin', function(xPlayer, args, showError)
        createCodeCommand(xPlayer.source, args.type, args.amount, args.code)
    end, false, {
        help = "Give coins to player",
        arguments = {
            {name = 'type', help = 'money/coin', type = 'any'},
            {name = 'amount', help = 'Money/Coin Amount', type = 'any'},
            {name = 'code', help = 'Usable code (not required)', type = 'any'},
        },
    })

    --Delete Code
    tgiCore.core.RegisterCommand({'deletecode'}, 'admin', function(xPlayer, args, showError)
        createCodeCommand(xPlayer.source, args.type, args.amount, args.code)
    end, false, {
        help = "Delete generated code",
        arguments = {
            {name = 'code', help = 'Generated code', type = 'any'},
        },
    })
end

server/editable.lua

server/genereteplate.lua

client/eitable.lua

language files

Last updated