server/commands.lua

local adminPerm = 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 id = tonumber(args[1])
	local Player = tgiCore.getPlayer(id)
	local amount = tonumber(args[3]) or 1
	local itemData = itemList[tostring(args[2]):lower()]
	if Player then
		local pInventory = GetInventory(tgiCore.getSource(Player), "player")
		if itemData then
			if pInventory.Functions.AddItem(itemData["name"], amount) then
				pInventory.Functions.Save()
				tgiCore.notif(source, "Item Given ID:" ..tgiCore.getCid(Player).." | "..amount.."x "..itemData["name"].. "")
			else
				tgiCore.notif(source, "Player Is Full")
			end
		else
			tgiCore.notif(source, "There is no such item")
		end
	else
		tgiCore.notif(source, "Player Offline")
	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 = tgiCore.getPlayer(tonumber(args[1]))
		if Player then
			local pInventory = GetInventory(tgiCore.getSource(Player), "player")
			pInventory.Functions.ClearInventory()
			tgiCore.notif(src, "SYSTEM", "error", "Player's Inventory Deleted")
		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, "SYSTEM", "error", "Player's Inventory Deleted")
			else
				tgiCore.notif(src, "SYSTEM", "error", "There is no such player")
			end
		end
	else
		local Player = tgiCore.getPlayer(src)
		if Player then
			local pInventory = GetInventory(tgiCore.getSource(Player), "player")
			pInventory.Functions.ClearInventory()
		else
			tgiCore.notif(src, "Player Offline")
		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 backpack = tonumber(args[2])
	if backpack then
		local max = #Config.backpack
		if backpack > 0 and backpack <= max then
			local xPlayer = tgiCore.getPlayer(tonumber(args[1]))
			if xPlayer then
				print("a")
				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(tgiCore.getSource(xPlayer), "player")
				if pInventory then
					local data = Config.backpack[backpack]
					pInventory.Functions.UpdateData({
						MaxSlots = data.slots,
						MaxWeight = data.weight
					})
				end
				tgiCore.notif(source, "Backpack Level Seted")
			else
				tgiCore.notif(source, "Player Offline")
			end
		else
			tgiCore.notif(source, string.format("Backpack Level Can Be Max %s", max))
		end
	else
		tgiCore.notif(source, "You Have To Write a Level")
	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 invType = args[2]
	local invId = args[1]
	if DeleteInventory(invType, invId) then
		tgiCore.notif(source, "Inventory Deleted! "..secondInventoryId)
	else
		tgiCore.notif(source, "There Is No Such Inventory!")
	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 invType = args[2]
	local invId = args[1]
	OpenInventory(source, invType, invId, {
        maxweight = 999999999999,
        slots = 1000,
    })
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 = querySync('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 = querySync('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 = querySync('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 = querySync('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 = querySync('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 = querySync('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!")
	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