server/editable.lua
-- banLog: banOpenOtherPlayerInventory, banGiveItemSelf, banGiveMinusAmount, banRemoveMinusAmount, banCustomShop
function ban(src, banLog, msg)
TriggerClientEvent("tgiann-anticheat:ban", src, { -- Example Code
adminMessage = msg,
ban = 131487,
kickMessage = "Cheating!"
})
end
function isPlayerVehicle(plate)
local table = config.framework == "qb" and "player_vehicles" or "owned_vehicles"
local owner = config.framework == "qb" and "citizenid" or "owner"
local result = MySQL.single.await('SELECT ' .. owner .. ' from ' .. table .. ' WHERE plate = ?', { plate })
return result and result[owner] or false
end
function isAdmin(src)
if config.framework == "qb" then
return IsPlayerAceAllowed(src, "admin") or IsPlayerAceAllowed(src, "god")
else
local xPlayer = tgiCore.getPlayer(src)
return xPlayer.getGroup(src) == "admin"
end
end
-- for money as item
local function setMoney(src, itemData)
if itemData.name == "money_item" then
local xPlayer = tgiCore.getPlayer(src)
if not xPlayer then return end
local pInventory = GetInventory(src, "player")
if not pInventory then return end
local totalAmount = pInventory.Functions.GetItemTotalAmount("money_item")
if config.framework == "esx" then
xPlayer.setAccountMoney("money", totalAmount, "inventory money as item", true)
elseif config.framework == "qb" then
xPlayer.Functions.SetMoney("cash", totalAmount, "inventory money as item", true)
end
end
end
function addItemDetect(src, itemData)
if not itemData then return end
if string.match(itemData.name:lower(), "weapon") then
TriggerClientEvent('inventory:client:addWeapon', src, true, true, itemData.slot)
else
if config.moneyAsItem then setMoney(src, itemData) end
TriggerClientEvent('tgiann-inventory:addedItem', src, itemData.name)
end
end
--if the value is false, the use of the item is canceled
function useItemEditable(src, itemData, itemSharedData)
local decayableItemsData = config.decayableItems[itemData.name]
if decayableItemsData then
local durability = itemData.info?.durability and getDurabilityPercent(itemData.info.durability, decayableItemsData, os.time()) or 1
if durability <= 0 then
tgiCore.notif(src, lang.cantUseThisItem, "error")
return false
end
end
if itemData.name == "myCustomUseItem" then
TriggerClientEvent('myCustomEvent', src, itemData.name)
return false -- We make it false because we do not want the main use item function to continue
end
return true
end
function removeItemDetect(src, itemData)
if not itemData then return end
if string.match(itemData.name:lower(), "weapon") then
TriggerClientEvent('inventory:client:removeWeapon', src, true, true, itemData.slot)
elseif itemData.name:lower() == "kemer" then
TriggerClientEvent('tgiann-hud:removeKemer', src)
elseif itemData.name:lower() == "megaphone" then
TriggerClientEvent('tgiann-megaphone:drop', src)
elseif itemData.name:lower() == "scooter" then
TriggerClientEvent('tgiann-scooter:drop', src)
else
if config.moneyAsItem then setMoney(src, itemData) end
TriggerClientEvent('tgiann-inventory:dropItem', src, itemData.name)
end
end
local function setQbItemInfo(itemData, info, Player)
if config.framework == "esx" then return info end
if itemData.name == "id_card" then
info.citizenid = Player.PlayerData.citizenid
info.firstname = Player.PlayerData.charinfo.firstname
info.lastname = Player.PlayerData.charinfo.lastname
info.birthdate = Player.PlayerData.charinfo.birthdate
info.gender = Player.PlayerData.charinfo.gender
info.nationality = Player.PlayerData.charinfo.nationality
elseif itemData.name == "driver_license" then
info.firstname = Player.PlayerData.charinfo.firstname
info.lastname = Player.PlayerData.charinfo.lastname
info.birthdate = Player.PlayerData.charinfo.birthdate
info.type = "Class C Driver License"
elseif itemData.name == "harness" then
info.uses = 20
elseif itemData.name == "markedbills" then
info.worth = math.random(5000, 10000)
elseif itemData.name == "labkey" then
info.lab = exports["qb-methlab"]:GenerateRandomLab()
elseif itemData.name == "printerdocument" then
info.url = "https://cdn.discordapp.com/attachments/870094209783308299/870104331142189126/Logo_-_Display_Picture_-_Stylized_-_Red.png"
end
return info
end
function setItemInfo(itemData, info, Player)
if not info or info == "" or (type(info) == "table" and not next(info)) then
info = {}
if itemData.type == 'weapon' then
info = {
serie = GetRandomItemId(),
durabilityPercent = 100,
ammo = 0,
usedTotalAmmo = 0
}
elseif itemData.name == 'armor' or itemData.name == 'policearmor' or itemData.name == 'advarmor' then
info = {
durabilityPercent = 100,
armor = 100,
}
elseif GetResourceState("tgiann-food-jobs") == "started" and exports["tgiann-food-jobs"]:items()[itemData.name] then
info = exports["tgiann-food-jobs"]:customItemMetadata(tgiCore.getSource(Player), tgiCore.getCid(Player))
elseif config.decayableItems[itemData.name] then
info.type = "decayableItems"
info.durability = os.time()
info.durabilitySecond = config.decayableItems[itemData.name]
elseif config.maxUseAmount[itemData.name] then
info.type = "maxUseAmount"
info.maxUseAmount = config.maxUseAmount[itemData.name].amount
else
info = setQbItemInfo(itemData, info, Player)
end
end
return info
end
function itemBought(xPlayer, shopName, itemData, newItemData)
if config.tgiannServer and shopName == "police" then
if string.find(itemData.name, "weapon") then
local label = itemList[itemData.name].label
MySQL.insert('INSERT INTO tgiann_mdt_shop (name, itemname, itemserial, time) VALUES (?, ?, ?, ?) ', { xPlayer.PlayerData.charinfo.firstname .. " " .. xPlayer.PlayerData.charinfo.lastname, label, newItemData.info.serie or "Eşya", os.time() })
end
end
end
tgiCore.CreateUseableItem("kposet", function(source, item)
local src = source
local xPlayer = tgiCore.getPlayer(src)
if not item.info.id then
item.info = { id = "kposet" .. tgiCore.getCid(xPlayer) .. math.random(1000000000, 9000000000), data = { maxweight = 0, slots = 15 } }
UpdateItemMetadata(src, "kposet", item.slot, item.info)
end
TriggerClientEvent("tgiann-inventory:open:secendory", tgiCore.getSource(xPlayer), item.info)
end)
tgiCore.CreateUseableItem("bkposet", function(source, item)
local src = source
local xPlayer = tgiCore.getPlayer(src)
if not item.info.id then
item.info = { id = "bkposet" .. tgiCore.getCid(xPlayer) .. math.random(1000000000, 9000000000), data = { maxweight = 0, slots = 40 } }
UpdateItemMetadata(src, "bkposet", item.slot, item.info)
end
TriggerClientEvent("tgiann-inventory:open:secendory", tgiCore.getSource(xPlayer), item.info)
end)
Last updated