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
function addVehicleToDatabase(xPlayer, citizenId, data, vehicleProps, plate)
if config.framework == "esx" then
queryData = {
query = 'INSERT INTO '..config.vehicleTableName..' (owner, plate, vehicle) VALUES (?, ?, ?)',
value = {
citizenId,
plate,
json.encode(vehicleProps),
}
}
elseif config.framework == "qb" then
queryData = {
query = 'INSERT INTO '..config.vehicleTableName..' (license, citizenid, vehicle, hash, mods, plate, garage, state) VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
value = {
tgiCore.getPlayerData(xPlayer).license,
citizenId,
data.model,
GetHashKey(data.model),
json.encode(vehicleProps),
plate,
"pillboxgarage",
0,
}
}
end
insert(queryData.query, queryData.value)
end
server/genereteplate.lua
local NumberCharset, Charset = {}, {}
for i = 48, 57 do NumberCharset[#NumberCharset+1] = string.char(i) end
for i = 65, 90 do Charset[#Charset+1] = string.char(i) end
function GetRandomNumber(length)
Wait(0)
math.randomseed(GetGameTimer())
if length > 0 then
return GetRandomNumber(length - 1) .. NumberCharset[math.random(1, #NumberCharset)]
else
return ''
end
end
function GetRandomLetter(length)
Wait(0)
math.randomseed(GetGameTimer())
if length > 0 then
return GetRandomLetter(length - 1) .. Charset[math.random(1, #Charset)]
else
return ''
end
end
function GeneratePlate()
local newPlate = nil
while true do
math.randomseed(GetGameTimer())
local generatedPlate = string.upper(GetRandomNumber(3) .. GetRandomLetter(3) .. GetRandomNumber(2))
local result = singleSync('SELECT plate FROM '..config.vehicleTableName..' WHERE plate = ? LIMIT 1', {generatedPlate})
if not result then
newPlate = generatedPlate
break
else
Wait(100)
end
Wait(0)
end
return newPlate
end
client/eitable.lua
local function getCarLabel(data)
local hash = GetHashKey(data.model)
local name = GetLabelText(GetDisplayNameFromVehicleModel(hash))
local carName = name == "NULL" and GetDisplayNameFromVehicleModel(hash) or name
return carName
end
function updateConfig(items)
for _, data in pairs(config.shopItems) do
for i=1, #data do
if not data[i].label then
if data[i].type == "car" then
data[i].label = getCarLabel(data[i])
elseif data[i].type == "item" then
if not data[i].amount then data[i].amount = 1 end
if not data[i].label then data[i].label = data[i].amount.."x "..items[data[i].itemName].label end
if not data[i].img then data[i].imgUrl = "nui://"..config.itemIMGLocation.."/"..data[i].itemName..config.itemImgExtension end
end
end
end
end
end
function notify(text, time)
postUi("app-main", "notify", {
text = text,
time = time or 3000
})
end
RegisterNetEvent('tgiann-coinshop:notify')
AddEventHandler('tgiann-coinshop:notify', notify)
function testDriveVehicleSpawned(vehicle, plate)
TriggerEvent("x-hotwire:give-keys", vehicle)
TriggerEvent("tgiann-hotwire:give-keys-with-carid", vehicle)
TriggerEvent("vehiclekeys:client:SetOwner", plate)
end
function buyVehicleSpawned(vehicle, plate)
TriggerEvent("x-hotwire:give-keys", vehicle)
TriggerEvent("tgiann-hotwire:give-keys-with-carid", vehicle)
TriggerEvent("vehiclekeys:client:SetOwner", plate)
end
function openUi()
SetNuiFocus(true, true)
tgiCore.cbFunction("tgiann-coinshop:getShopAndUserData", function(data, stocks)
postUi("app-main", "open", {
stocks = stocks,
userData = data,
config = config,
})
end)
end
exports("openUi", openUi)
function closeUi(fullUi, cb)
SetNuiFocus(false, false)
if fullUi then
postUi("app-main", "close")
end
if cb then cb("") end
end
RegisterNUICallback("closeUi", closeUi)
if config.openCommand.enable then RegisterCommand(config.openCommand.command, openUi) end
language files
config.langs.en = {
playerIsOffline = "Player Offline",
no = "No",
yes = "Yes",
popUpHeaderText = "Do you want to buy {0}?",
testDrive = "Test Drive",
testDriveTimer = "%s Seconds test drive started!",
testDriveHeader = "Do you want to test the vehicle for ${0} ?",
noTestDriveZone = "You're too far away from the test drive location! Location got marked on the map",
dollar = "$",
coin = "C",
daily = "{0} Daily",
stock = "Stock",
infStock = "Timeless",
noStockNotif = "There is no stock for the thing you want to buy",
noStockText = "Out of Stock",
noStockBuy = "Out of Stock!",
shortByHigh = "From Low to High Price",
shortByLow = "From High to Low Price",
headerMain = "Home page",
headerBuyBoin = "Buy Coin",
budget = "Price",
shortBy = "Sort by",
tags = "Tags",
clear = "Clear",
filter = "Filter",
buy = "Buy",
noTags = "No Tag",
useCode = "Use Code",
buyCoinDesc =
"You can buy codes from this webpage www.mysite.com/buy-roleplay-coin You can use your code on this page and add balance to your account.!",
buyCoinPlaceholder = "TGI-123XYZ3219955",
noMoneyBank = "You don't have enough money on your bank!",
noMoneyCoin = "You don't have enough Coins!",
codeCreated = "Code created! Your code: %s",
wrongCodeType = "Code type must be 'money' or 'coin' ",
alreadyCode = "This code was already created before; %s",
codeDeleted = "Code deleted!",
codeNotFound = "Code not found!",
codeIsInvalid = "Code invalid!",
codeUsed = "Code used! You got %s%s on your account",
reBuy = "Buy again",
day = "Day",
days = "Days",
hour = "Hour",
hours = "Hours",
minute = "Minute",
minutes = "Minutes",
second = "Seconds",
}
Last updated