server/commands.lua
local adminPerm = config.tgiannServer and { "tgi" } or config.framework == "qb" and "god" or "admin"
tgiCore.CommandsAdd("giveitem", "Give An Item (Admin Only)", { { name = "id", help = "Player ID" }, { name = "item", help = "Name of the item (not a label)" }, { name = "amount", help = "Amount of items" } }, false, function(source, args)
local src = source
local id = tonumber(args[1])
local Player = config.tgiannServer and tgiCore.getPlayerById(id) or tgiCore.getPlayer(id)
local amount = tonumber(args[3]) or 1
local itemData = itemList[tostring(args[2]):lower()]
if Player then
local targetSrc = tgiCore.getSource(Player)
local pInventory = GetInventory(targetSrc, "player")
if itemData then
if pInventory.Functions.CanCarryItem(itemData["name"], amount) then
if pInventory.Functions.AddItem(itemData["name"], amount) then
pInventory.Functions.Save()
tgiCore.notif(src, "Item Given ID:" .. tgiCore.getCid(Player) .. " | " .. amount .. "x " .. itemData["name"] .. "", "success")
TriggerEvent("tgiann-core:discordLog", webhooks.adminLog, string.format("/giveitem %s %s %s", id, args[2], amount), src, targetSrc)
else
tgiCore.notif(src, "Player Is Full", "error")
end
else
tgiCore.notif(src, "Player Is Full", "error")
end
else
tgiCore.notif(src, "There is no such item", "error")
end
else
tgiCore.notif(src, "Player Offline", "error")
end
end, adminPerm)
tgiCore.CommandsAdd('clearinv', 'Clear Players Inventory (Admin Only)', { { name = 'id', help = 'Player ID' } }, false, function(source, args)
local src = source
if args[1] then
local Player = config.tgiannServer and tgiCore.getPlayerById(tonumber(args[1])) or tgiCore.getPlayer(tonumber(args[1]))
if Player then
local targetSrc = tgiCore.getSource(Player)
local pInventory = GetInventory(targetSrc, "player")
pInventory.Functions.ClearInventory()
tgiCore.notif(src, "Player's Inventory Deleted", "error")
TriggerEvent("tgiann-core:discordLog", webhooks.adminLog, string.format("/clearinv %s (Target Online)", args[1]), src, targetSrc)
else
local row = MySQL.single.await('SELECT `inventory`, `citizenid` FROM `tgiann_inventory_player` WHERE `citizenid` = ? LIMIT 1', { args[1] })
if row then
MySQL.update('UPDATE tgiann_inventory_player SET inventory = ? WHERE citizenid = ?', { "[]", row.citizenid })
tgiCore.notif(src, "Player's Inventory Deleted", "error")
TriggerEvent("tgiann-core:discordLog", webhooks.adminLog, string.format("/clearinv %s (Target Offline)", args[1]), src)
else
tgiCore.notif(src, "There is no such player", "error")
end
end
else
local Player = tgiCore.getPlayer(src)
if Player then
local pInventory = GetInventory(tgiCore.getSource(Player), "player")
pInventory.Functions.ClearInventory()
TriggerEvent("tgiann-core:discordLog", webhooks.adminLog, "/clearinv (Self Inventory)", src)
else
tgiCore.notif(src, "Player Offline", "error")
end
end
end, adminPerm)
tgiCore.CommandsAdd("backpack", "Set Backpack Level", { { name = "id", help = "Player ID" }, { name = "level", help = "1-2-3" } }, true, function(source, args)
local src = source
local backpack = tonumber(args[2])
if backpack then
local max = #config.backpack
if backpack > 0 and backpack <= max then
local xPlayer = config.tgiannServer and tgiCore.getPlayerById(tonumber(args[1])) or tgiCore.getPlayer(tonumber(args[1]))
if xPlayer then
local targetSrc = tgiCore.getSource(xPlayer)
MySQL.insert('INSERT INTO tgiann_inventory_player (citizenid, lvl) VALUES (:citizenid, :lvl) ON DUPLICATE KEY UPDATE citizenid = :citizenid, lvl = :lvl', {
citizenid = tgiCore.getCid(xPlayer),
lvl = backpack,
})
local pInventory = GetInventory(targetSrc, "player")
if pInventory then
local data = config.backpack[backpack]
pInventory.Functions.UpdateData({
MaxSlots = data.slots,
MaxWeight = data.weight
})
end
tgiCore.notif(src, "Backpack Level Seted", "success")
TriggerEvent("tgiann-core:discordLog", webhooks.adminLog, string.format("/backpack %s %s", args[1], backpack), src, targetSrc)
else
tgiCore.notif(src, "Player Offline", "error")
end
else
tgiCore.notif(src, string.format("Backpack Level Can Be Max %s", max), "error")
end
else
tgiCore.notif(src, "You Have To Write a Level", "error")
end
end, adminPerm)
tgiCore.CommandsAdd("deleteinv", "Deletes Inventory", { { name = "id", help = "Inventory Name/Plate" }, { name = "invType", help = "Inventory Type(trunk, glovebox, stash)" } }, true, function(source, args)
local src = source
local invType = args[2]
local invId = args[1]
if DeleteInventory(invType, invId) then
tgiCore.notif(src, "Inventory Deleted! " .. secondInventoryId, "success")
TriggerEvent("tgiann-core:discordLog", webhooks.adminLog, string.format("/deleteinv %s %s", invType, invId), src)
else
tgiCore.notif(src, "There Is No Such Inventory!", "error")
end
end, adminPerm)
tgiCore.CommandsAdd("openinv", "Open a Inventory", { { name = "id", help = "Inventory Name/Plate" }, { name = "invType", help = "Inventory Type(trunk, glovebox, stash)" } }, true, function(source, args)
local src = source
local invType = args[2]
local invId = args[1]
OpenInventory(src, invType, invId, {
maxweight = 999999999999,
slots = 1000,
})
TriggerEvent("tgiann-core:discordLog", webhooks.adminLog, string.format("/openinv %s %s", invType, invId), src)
end, adminPerm)
local checkItemAmount = 0
local checkItemTotalAmount = 0
local function checkItemListAdd(name, amount, findItem)
if name == findItem then
checkItemAmount = checkItemAmount + amount
end
end
local function checkItemListPrint(inventoryType, inventoryName, findItem, findAmount)
if checkItemAmount > findAmount then
print(string.format("Env Tip: %s | %s | Item: %s | Adet: %s", inventoryType, inventoryName, findItem, checkItemAmount))
checkItemTotalAmount = checkItemTotalAmount + checkItemAmount
end
checkItemAmount = 0
end
tgiCore.CommandsAdd("checkitem", "Checks One Item in All Inventories", { { name = "item", help = "Item Name" }, { name = "minamount", help = "Min Amount" } }, true, function(source, args)
local findItem = args[1]
local findAmount = tonumber(args[2])
local src = source
checkItemTotalAmount = 0
if itemList[findItem] then
local result = MySQL.query.await('SELECT inventory, citizenid, citizenid FROM tgiann_inventory_player')
if result then
for i = 1, #result do
local resultData = result[i]
resultData.inventory = json.decode(resultData.inventory)
if resultData.inventory then
for slot, data in pairs(resultData.inventory) do
checkItemListAdd(data.name, data.amount, findItem)
end
checkItemListPrint("Player", resultData.citizenid, findItem, findAmount)
end
end
end
local result = MySQL.query.await('SELECT * FROM tgiann_inventory_stashitems')
if result then
for i = 1, #result do
local resultData = result[i]
resultData.items = json.decode(resultData.items)
for slot, data in pairs(resultData.items) do
checkItemListAdd(data.name, data.amount, findItem)
end
checkItemListPrint("stash", resultData.stash, findItem, findAmount)
end
end
local result = MySQL.query.await('SELECT * FROM tgiann_inventory_trunkitems')
if result then
for i = 1, #result do
local resultData = result[i]
resultData.items = json.decode(resultData.items)
for slot, data in pairs(resultData.items) do
checkItemListAdd(data.name, data.amount, findItem)
end
checkItemListPrint("trunk", resultData.plate, findItem, findAmount)
end
end
local result = MySQL.query.await('SELECT * FROM tgiann_inventory_gloveboxitems')
if result then
for i = 1, #result do
local resultData = result[i]
resultData.items = json.decode(resultData.items)
for slot, data in pairs(resultData.items) do
checkItemListAdd(data.name, data.amount, findItem)
end
checkItemListPrint("glovebox", resultData.plate, findItem, findAmount)
end
end
--[[ local result = MySQL.query.await('SELECT id, item, amount FROM tgiann_market_sell')
if result then
for i=1, #result do
local resultData = result[i]
checkItemListAdd(resultData.item, resultData.amount, findItem)
checkItemListPrint("tgiann_market_sell", resultData.id, findItem, findAmount)
end
end
local result = MySQL.query.await('SELECT id, item, amount FROM tgiann_market_item_storage')
if result then
for i=1, #result do
local resultData = result[i]
checkItemListAdd(resultData.item, resultData.amount, findItem)
checkItemListPrint("tgiann_market_item_storage", resultData.id, findItem, findAmount)
end
end
]]
print(string.format("Total Amount: %s", checkItemTotalAmount))
else
tgiCore.notif(src, "There is no such item!", "error")
end
end, adminPerm)
tgiCore.CommandsAdd("items", "Lists all Items available in the server", {}, false, function(source, args)
OpenInventory(source, "shop", "admin", "admin")
end, adminPerm)
Last updated