ox_inventory
ตัวอย่างรหัสที่ใช้เพิ่มไปยังทรัพยากร ox_inventory เพื่อส่งข้อมูลมายัง azael_dc-serverlogs
โปรดตรวจสอบตัวแปรของรหัสทุกครั้ง เนื่องจากเวอร์ชันของทรัพยากรในตัวอย่างอาจจะไม่มีความเข้ากันได้กับทรัพยากรในเวอร์ชันที่คุณกำลังใช้งานอยู่ และส่งผลให้ไม่มีการส่งข้อมูลไปยัง azael_dc-serverlogs เนื่องจากมีข้อผิดพลาดเกิดขึ้นจากรหัสที่คุณดำเนินการเพิ่ม
fxmanifest.lua
เปิดไฟล์ fxmanifest.lua
ภายใน ox_inventory
และดำเนินการเพิ่ม 'azael_dc-serverlogs.lua'
ภายใน server_scripts
server_scripts {
'@oxmysql/lib/MySQL.lua',
'init.lua',
'azael_dc-serverlogs.lua' -- รหัสที่ดำเนินการเพิ่ม
}
azael_dc-serverlogs.lua
ดำเนินการสร้างไฟล์ชื่อ azael_dc-serverlogs.lua
ที่อยู่เดียวกันกับไฟล์ fxmanifest.lua
ภายใน ox_inventory
และคัดลอกรหัสด้านล่างนี้ไปวางไว้ภายไฟล์ azael_dc-serverlogs.lua
--===== FiveM Script: ===================================================================
--= DC - Server Logs (Webhook)
--===== Developed By: ===================================================================
--= Azael Dev <[email protected]>
--===== Website: ========================================================================
--= https://www.azael.dev/
--===== Docs: ===========================================================================
--= https://docs2.azael.dev/cfx/script/azael_dc-serverlogs/example/other/ox_inventory
--=======================================================================================
---departments
local jobs = {
police = 'police',
ambulance = 'ambulance',
mechanic = 'mechanic',
council = 'council'
}
---azael_dc-serverlogs
---@async
---@param actionType string
---@param itemData table
---@param itemCount number
---@param fromInventory table
---@param toInventory table|nil
function azael_serverlogs(actionType, itemData, itemCount, fromInventory, toInventory)
Citizen.CreateThread(function()
local itemType = itemData.name:match('money') and 'account'
or itemData.name:match('WEAPON') and 'weapon'
or itemData.name:match('ammo') and 'ammo'
or itemData.name:match('key') and 'keys'
or 'item'
local important = itemType == 'item' and (itemCount >= 1000 and true or false)
or itemType == 'account' and (itemCount >= 100000 and true or false)
or false
local fields = (type(itemData.metadata) == 'table' and next(itemData.metadata)) and { { name = '**META DATA**', value = ('```%s```'):format(json.encode(itemData.metadata)), inline = false } } or nil
if actionType:match('admin_command') and fromInventory.id then
local event = 'OX_AdminCommands'
local text, color = actionType:match('additem') and 'เพิ่ม', 2
or actionType:match('removeitem') and 'ลบ', 1
or actionType:match('setitem') and 'กำหนด', 3
if fromInventory.id == toInventory.id then
pcall(function()
exports['azael_dc-serverlogs']:insertData({
event = event,
content = ('%s %s จำนวน %s ตนเอง'):format(text, itemData.label, itemCount),
fields = fields,
source = fromInventory.id,
color = color,
options = {
important = important
}
})
end)
else
pcall(function()
exports['azael_dc-serverlogs']:insertData({
event = event,
content = ('%s %s จำนวน %s ไปยัง %s'):format(text, itemData.label, itemCount, toInventory.label),
fields = fields,
source = fromInventory.id,
color = 7,
options = {
important = important
}
})
exports['azael_dc-serverlogs']:insertData({
event = event,
content = ('ถูก%s %s จำนวน %s โดย %s'):format(text, itemData.label, itemCount, fromInventory.label),
fields = fields,
source = toInventory.id,
color = color,
options = {
important = important
}
})
end)
end
elseif actionType == 'player_crafting' then
pcall(function()
exports['azael_dc-serverlogs']:insertData({
event = 'OX_Crafting',
content = ('คราฟ %s จำนวน %s สำเร็จ'):format(itemData.label, itemCount),
fields = fields,
source = fromInventory.id,
color = 2,
options = {
important = important
}
})
end)
elseif actionType == 'player_buyitemshop' then
pcall(function()
exports['azael_dc-serverlogs']:insertData({
event = 'OX_BuyItemShop',
content = ('ซื้อ %s จำนวน %s ที่ %s เสียค่าใช้จ่าย %s จำนวน %s'):format(itemData.label, itemCount, itemData.shop, itemData.currency, itemData.price),
fields = fields,
source = fromInventory.id,
color = 2,
options = {
important = important
}
})
end)
elseif actionType == 'player_give' then
local event = itemType == 'account' and (itemData.name == 'money' and 'OX_GiveMoney' or 'OX_GiveDirtyMoney')
or itemType == 'weapon' and 'OX_GiveWeapon'
or itemType == 'ammo' and 'OX_GiveAmmo'
or itemType == 'keys' and 'OX_GiveKeys'
or 'OX_GiveItem'
pcall(function()
exports['azael_dc-serverlogs']:insertData({
event = event,
content = ('ส่ง %s จำนวน %s ให้กับ %s'):format(itemData.label, itemCount, toInventory.label),
fields = fields,
source = fromInventory.id,
color = 1,
options = {
important = important
}
})
exports['azael_dc-serverlogs']:insertData({
event = event,
content = ('ได้รับ %s จำนวน %s จาก %s'):format(itemData.label, itemCount, fromInventory.label),
fields = fields,
source = toInventory.id,
color = 2,
options = {
important = important
}
})
end)
elseif actionType == 'player_drop' then
local event = itemType == 'account' and (itemData.name == 'money' and 'OX_RemoveMoney' or 'OX_RemoveDirtyMoney')
or itemType == 'weapon' and 'OX_RemoveWeapon'
or itemType == 'ammo' and 'OX_RemoveAmmo'
or itemType == 'keys' and 'OX_RemoveKeys'
or 'OX_RemoveItem'
pcall(function()
exports['azael_dc-serverlogs']:insertData({
event = event,
content = ('ทิ้ง %s จำนวน %s'):format(itemData.label, itemCount),
fields = fields,
source = fromInventory.id,
color = 1,
options = {
important = important
}
})
end)
elseif actionType == 'player_pickup' then
local event = itemType == 'account' and (itemData.name == 'money' and 'OX_PickupMoney' or 'OX_PickupDirtyMoney')
or itemType == 'weapon' and 'OX_PickupWeapon'
or itemType == 'ammo' and 'OX_PickupAmmo'
or itemType == 'keys' and 'OX_PickupKeys'
or 'OX_PickupItem'
pcall(function()
exports['azael_dc-serverlogs']:insertData({
event = event,
content = ('เก็บ %s จำนวน %s'):format(itemData.label, itemCount),
fields = fields,
source = fromInventory.id,
color = 2,
options = {
important = important
}
})
end)
elseif actionType == 'search_put' then
local event = itemType == 'account' and (itemData.name == 'money' and 'OX_%sPutMoney' or 'OX_%sPutDirtyMoney')
or itemType == 'weapon' and 'OX_%sPutWeapon'
or itemType == 'ammo' and 'OX_%sPutAmmo'
or itemType == 'keys' and 'OX_%sPutKeys'
or 'OX_%sPutItem'
local player = server.GetPlayerFromId(fromInventory.id)
local job = player.job.name:match(jobs.police) and 'Police'
or player.job.name:match(jobs.council) and 'Council'
or 'Citizen'
event = event:format(job)
pcall(function()
exports['azael_dc-serverlogs']:insertData({
event = event,
content = ('หน่วยงาน %s ยัด %s จำนวน %s ไปยัง %s'):format(player.job.name, itemData.label, itemCount, toInventory.label),
fields = fields,
source = fromInventory.id,
color = 2,
options = {
important = important
}
})
exports['azael_dc-serverlogs']:insertData({
event = event,
content = ('ถูกยัด %s จำนวน %s โดย %s หน่วยงาน %s'):format(itemData.label, itemCount, fromInventory.label, player.job.name),
fields = fields,
source = toInventory.id,
color = 3,
options = {
important = important
}
})
end)
elseif actionType == 'search_get' then
local event = itemType == 'account' and (itemData.name == 'money' and 'OX_%sTakeMoney' or 'OX_%sTakeDirtyMoney')
or itemType == 'weapon' and 'OX_%sTakeWeapon'
or itemType == 'ammo' and 'OX_%sTakeAmmo'
or itemType == 'keys' and 'OX_%sTakeKeys'
or 'OX_%sTakeItem'
local player = server.GetPlayerFromId(toInventory.id)
local job = player.job.name:match(jobs.police) and 'Police'
or player.job.name:match(jobs.council) and 'Council'
or 'Citizen'
event = event:format(job)
pcall(function()
exports['azael_dc-serverlogs']:insertData({
event = event,
content = ('หน่วยงาน %s ยึด %s จำนวน %s จาก %s'):format(player.job.name, itemData.label, itemCount, fromInventory.label),
fields = fields,
source = toInventory.id,
color = 2,
options = {
important = important
}
})
exports['azael_dc-serverlogs']:insertData({
event = event,
content = ('ถูกยึด %s จำนวน %s โดย %s หน่วยงาน %s'):format(itemData.label, itemCount, toInventory.label, player.job.name),
fields = fields,
source = fromInventory.id,
color = 3,
options = {
important = important
}
})
end)
elseif actionType == 'vehicle_put' then
local event = itemType == 'account' and (itemData.name == 'money' and 'OX_VehiclePutMoney' or 'OX_VehiclePutDirtyMoney')
or itemType == 'weapon' and 'OX_VehiclePutWeapon'
or itemType == 'ammo' and 'OX_VehiclePutAmmo'
or itemType == 'keys' and 'OX_VehiclePutKeys'
or 'OX_VehiclePutItem'
pcall(function()
exports['azael_dc-serverlogs']:insertData({
event = event,
content = ('นำ %s จำนวน %s เข้า %s ทะเบียน %s'):format(itemData.label, itemCount, toInventory.type, toInventory.label),
fields = fields,
source = fromInventory.id,
color = 2,
options = {
important = important
}
})
end)
elseif actionType == 'vehicle_get' then
local event = itemType == 'account' and (itemData.name == 'money' and 'OX_VehicleGetMoney' or 'OX_VehicleGetDirtyMoney')
or itemType == 'weapon' and 'OX_VehicleGetWeapon'
or itemType == 'ammo' and 'OX_VehicleGetAmmo'
or itemType == 'keys' and 'OX_VehicleGetKeys'
or 'OX_VehicleGetItem'
pcall(function()
exports['azael_dc-serverlogs']:insertData({
event = event,
content = ('นำ %s จำนวน %s ออก %s ทะเบียน %s'):format(itemData.label, itemCount, fromInventory.type, fromInventory.label),
fields = fields,
source = toInventory.id,
color = 1,
options = {
important = important
}
})
end)
elseif actionType == 'safebox_put' then
local event = itemType == 'account' and (itemData.name == 'money' and 'OX_%sVaultPutMoney' or 'OX_%sVaultPutDirtyMoney')
or itemType == 'weapon' and 'OX_%sVaultPutWeapon'
or itemType == 'ammo' and 'OX_%sVaultPutAmmo'
or itemType == 'keys' and 'OX_%sVaultPutKeys'
or 'OX_%sVaultPutItem'
local job = 'Citizen'
if type(toInventory.groups) == 'table' then
job = toInventory.groups[jobs.police] and 'Police'
or toInventory.groups[jobs.ambulance] and 'Ambulance'
or toInventory.groups[jobs.mechanic] and 'Mechanic'
or toInventory.groups[jobs.council] and 'Council'
or 'Citizen'
end
if type(fields) ~= 'table' then fields = {} end
table.insert(fields, { name = '**SAFEBOX DATA**', value = ('```ID: %s\nNAME: %s\nOWNER: %s\nGROUPS: %s```'):format(toInventory.id, toInventory.dbId, toInventory.owner, json.encode(toInventory.groups)), inline = false })
pcall(function()
exports['azael_dc-serverlogs']:insertData({
event = event:format(job),
content = ('นำ %s จำนวน %s เข้าตู้นิรภัย %s'):format(itemData.label, itemCount, toInventory.label),
fields = fields,
source = fromInventory.id,
color = 2,
options = {
important = important
}
})
end)
elseif actionType == 'safebox_get' then
local event = itemType == 'account' and (itemData.name == 'money' and 'OX_%sVaultGetMoney' or 'OX_%sVaultGetDirtyMoney')
or itemType == 'weapon' and 'OX_%sVaultGetWeapon'
or itemType == 'ammo' and 'OX_%sVaultGetAmmo'
or itemType == 'keys' and 'OX_%sVaultGetKeys'
or 'OX_%sVaultGetItem'
local job = 'Citizen'
if type(fromInventory.groups) == 'table' then
job = fromInventory.groups[jobs.police] and 'Police'
or fromInventory.groups[jobs.ambulance] and 'Ambulance'
or fromInventory.groups[jobs.mechanic] and 'Mechanic'
or fromInventory.groups[jobs.council] and 'Council'
or 'Citizen'
end
if type(fields) ~= 'table' then fields = {} end
table.insert(fields, { name = '**SAFEBOX DATA**', value = ('```ID: %s\nNAME: %s\nOWNER: %s\nGROUPS: %s```'):format(fromInventory.id, fromInventory.dbId, fromInventory.owner, json.encode(fromInventory.groups)), inline = false })
pcall(function()
exports['azael_dc-serverlogs']:insertData({
event = event:format(job),
content = ('นำ %s จำนวน %s ออกตู้นิรภัย %s'):format(itemData.label, itemCount, fromInventory.label),
fields = fields,
source = toInventory.id,
color = 1,
options = {
important = important
}
})
end)
elseif actionType == 'policeevidence_put' then
local event = itemType == 'account' and (itemData.name == 'money' and 'OX_PoliceEvidencePutMoney' or 'OX_PoliceEvidencePutDirtyMoney')
or itemType == 'weapon' and 'OX_PoliceEvidencePutWeapon'
or itemType == 'ammo' and 'OX_PoliceEvidencePutAmmo'
or itemType == 'keys' and 'OX_PoliceEvidencePutKeys'
or 'OX_PoliceEvidencePutItem'
pcall(function()
exports['azael_dc-serverlogs']:insertData({
event = event,
content = ('นำ %s จำนวน %s เข้า %s'):format(itemData.label, itemCount, toInventory.label),
fields = fields,
source = fromInventory.id,
color = 2,
options = {
important = important
}
})
end)
elseif actionType == 'policeevidence_get' then
local event = itemType == 'account' and (itemData.name == 'money' and 'OX_PoliceEvidenceGetMoney' or 'OX_PoliceEvidenceGetDirtyMoney')
or itemType == 'weapon' and 'OX_PoliceEvidenceGetWeapon'
or itemType == 'ammo' and 'OX_PoliceEvidenceGetAmmo'
or itemType == 'keys' and 'OX_PoliceEvidenceGetKeys'
or 'OX_PoliceEvidenceGetItem'
pcall(function()
exports['azael_dc-serverlogs']:insertData({
event = event,
content = ('นำ %s จำนวน %s ออก %s'):format(itemData.label, itemCount, fromInventory.label),
fields = fields,
source = toInventory.id,
color = 1,
options = {
important = important
}
})
end)
end
end)
end
server.lua
ดำเนินการเปิดไฟล์ server.lua
ใช้คำสั่ง-แอดมิน
Event | Label |
---|---|
OX_AdminCommands | ใช้คำสั่ง-แอดมิน |
1. ADDITEM
วางรหัสด้านล่างนี้ต่อจาก source = Inventory(source) or { label = 'console', owner = 'console' }
บรรทัดที่ 449
azael_serverlogs('admin_command_additem', item, count, source, inventory)
2. REMOVEITEM
วางรหัสด้านล่า งนี้ต่อจาก source = Inventory(source) or {label = 'console', owner = 'console'}
บรรทัดที่ 477
azael_serverlogs('admin_command_removeitem', item, args.count, source, inventory)
3. SETITEM
วางรหัสด้านล่างนี้ต่อจาก source = Inventory(source) or {label = 'console', owner = 'console'}
บรรทัดที่ 505
azael_serverlogs('admin_command_setitem', item, args.count, source, inventory)
crafting/server.lua
ไปยังโฟลเดอร์ modules/crafting แล้วดำเนินการเปิดไฟล์ server.lua
โต๊ะคราฟ-อุปกรณ์
Event | Label |
---|---|
OX_Crafting | โต๊ะคราฟ-อุปกรณ์ |
วางรหัสด้านล่างนี้ต่อจาก Inventory.AddItem(left, craftedItem, recipe.count or 1, recipe.metadata or {}, craftedItem.stack and toSlot or nil)
บรรทัดที่ 223
azael_serverlogs('player_crafting', { name = craftedItem.name, label = craftedItem.label, metadata = recipe.metadata }, (recipe.count or 1), left)
shops/server.lua
ไปยังโฟลเดอร์ modules/shops แล้วดำเนินการเปิดไฟล์ server.lua
ร้านค้า-ซื้อสินค้า
Event | Label |
---|---|
OX_BuyItemShop | ร้านค้า-ซื้อสินค้า |
วางรหัสด้านล่างนี้ต่อจาก if server.syncInventory then server.syncInventory(playerInv) end
บรรทัดที่ 278
azael_serverlogs('player_buyitemshop', { name = fromItem.name, label = fromItem.label, metadata = metadata, shop = shop.label, currency = currency, price = price }, count, playerInv)
inventory/server.lua
ไปยังโฟลเดอร์ modules/inventory แล้วดำเนินการเปิดไฟล์ server.lua
1. DROP ITEMS
วางรหัสด้านล่างนี้ต่อจาก if server.syncInventory then server.syncInventory(playerInventory) end
บรรทัดที่ 1557
azael_serverlogs('player_drop', toData, data.count, playerInventory)
2. STACK ITEMS
วางรหัสด้านล่างนี้ ไว้ด้านบน if server.loglevel > 0 then
บรรทัดที่ 1746
if data.fromType == 'player' or data.toType == 'player' then
if data.toType == 'drop' then
azael_serverlogs('player_drop', fromData, data.count, fromInventory)
elseif data.fromType == 'drop' then
azael_serverlogs('player_pickup', fromData, data.count, toInventory)
elseif data.toType == 'otherplayer' then
azael_serverlogs('search_put', fromData, data.count, fromInventory, toInventory)
elseif data.fromType == 'otherplayer' then
azael_serverlogs('search_get', fromData, data.count, fromInventory, toInventory)
elseif data.toType == 'glovebox' or data.toType == 'trunk' then
azael_serverlogs('vehicle_put', fromData, data.count, fromInventory, toInventory)
elseif data.fromType == 'glovebox' or data.fromType == 'trunk' then
azael_serverlogs('vehicle_get', fromData, data.count, fromInventory, toInventory)
elseif data.toType == 'stash' then
azael_serverlogs('safebox_put', fromData, data.count, fromInventory, toInventory)
elseif data.fromType == 'stash' then
azael_serverlogs('safebox_get', fromData, data.count, fromInventory, toInventory)
elseif data.toType == 'policeevidence' then
azael_serverlogs('policeevidence_put', fromData, data.count, fromInventory, toInventory)
elseif data.fromType == 'policeevidence' then
azael_serverlogs('policeevidence_get', fromData, data.count, fromInventory, toInventory)
end
end
3. MOVE ITEM TO AN EMPTY SLOT
วางรหัสด้านล่างนี้ ไว้ด้านบน if server.loglevel > 0 then
บรรทัดที่ 1796
if data.fromType == 'player' or data.toType == 'player' then
if data.toType == 'drop' then
azael_serverlogs('player_drop', fromData, data.count, fromInventory)
elseif data.fromType == 'drop' then
azael_serverlogs('player_pickup', fromData, data.count, toInventory)
elseif data.toType == 'otherplayer' then
azael_serverlogs('search_put', fromData, data.count, fromInventory, toInventory)
elseif data.fromType == 'otherplayer' then
azael_serverlogs('search_get', fromData, data.count, fromInventory, toInventory)
elseif data.toType == 'glovebox' or data.toType == 'trunk' then
azael_serverlogs('vehicle_put', fromData, data.count, fromInventory, toInventory)
elseif data.fromType == 'glovebox' or data.fromType == 'trunk' then
azael_serverlogs('vehicle_get', fromData, data.count, fromInventory, toInventory)
elseif data.toType == 'stash' then
azael_serverlogs('safebox_put', fromData, data.count, fromInventory, toInventory)
elseif data.fromType == 'stash' then
azael_serverlogs('safebox_get', fromData, data.count, fromInventory, toInventory)
elseif data.toType == 'policeevidence' then
azael_serverlogs('policeevidence_put', fromData, data.count, fromInventory, toInventory)
elseif data.fromType == 'policeevidence' then
azael_serverlogs('policeevidence_get', fromData, data.count, fromInventory, toInventory)
end
end
4. GIVE ITEMS
วางรหัสด้านล่างนี้ต่อจาก if Inventory.RemoveItem(fromInventory, item, count, data.metadata, slot) then
บรรทัดที่ 2368
azael_serverlogs('player_give', data, count, fromInventory, toInventory)