mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:08:54 +00:00
Merge pull request #1433 from Arctos2win/dev
feat(esx_core): ✨ make adding other inventories more easy + little refactor
This commit is contained in:
@@ -148,8 +148,7 @@ local function ApplyConfig()
|
||||
DisableNPCs()
|
||||
end
|
||||
|
||||
RegisterNetEvent("esx:playerLoaded")
|
||||
AddEventHandler("esx:playerLoaded", function(xPlayer, _, skin)
|
||||
RegisterNetEvent("esx:playerLoaded", function(xPlayer, _, skin)
|
||||
ESX.PlayerData = xPlayer
|
||||
|
||||
if not Config.Multichar then
|
||||
@@ -193,14 +192,11 @@ AddEventHandler("esx:playerLoaded", function(xPlayer, _, skin)
|
||||
StartServerSyncLoops()
|
||||
end)
|
||||
|
||||
|
||||
RegisterNetEvent("esx:onPlayerLogout")
|
||||
AddEventHandler("esx:onPlayerLogout", function()
|
||||
RegisterNetEvent("esx:onPlayerLogout", function()
|
||||
ESX.PlayerLoaded = false
|
||||
end)
|
||||
|
||||
RegisterNetEvent("esx:setMaxWeight")
|
||||
AddEventHandler("esx:setMaxWeight", function(newMaxWeight)
|
||||
RegisterNetEvent("esx:setMaxWeight", function(newMaxWeight)
|
||||
ESX.SetPlayerData("maxWeight", newMaxWeight)
|
||||
end)
|
||||
|
||||
@@ -227,7 +223,7 @@ end)
|
||||
AddEventHandler("esx:restoreLoadout", function()
|
||||
ESX.SetPlayerData("ped", PlayerPedId())
|
||||
|
||||
if not Config.OxInventory then
|
||||
if not Config.CustomInventory then
|
||||
local ammoTypes = {}
|
||||
RemoveAllPedWeapons(ESX.PlayerData.ped, true)
|
||||
|
||||
@@ -277,8 +273,7 @@ AddStateBagChangeHandler("VehicleProperties", nil, function(bagName, _, value)
|
||||
ESX.Game.SetVehicleProperties(vehicle, value)
|
||||
end)
|
||||
|
||||
RegisterNetEvent("esx:setAccountMoney")
|
||||
AddEventHandler("esx:setAccountMoney", function(account)
|
||||
RegisterNetEvent("esx:setAccountMoney", function(account)
|
||||
for i = 1, #ESX.PlayerData.accounts do
|
||||
if ESX.PlayerData.accounts[i].name == account.name then
|
||||
ESX.PlayerData.accounts[i] = account
|
||||
@@ -289,9 +284,8 @@ AddEventHandler("esx:setAccountMoney", function(account)
|
||||
ESX.SetPlayerData("accounts", ESX.PlayerData.accounts)
|
||||
end)
|
||||
|
||||
if not Config.OxInventory then
|
||||
RegisterNetEvent("esx:addInventoryItem")
|
||||
AddEventHandler("esx:addInventoryItem", function(item, count, showNotification)
|
||||
if not Config.CustomInventory then
|
||||
RegisterNetEvent("esx:addInventoryItem", function(item, count, showNotification)
|
||||
for k, v in ipairs(ESX.PlayerData.inventory) do
|
||||
if v.name == item then
|
||||
ESX.UI.ShowInventoryItemNotification(true, v.label, count - v.count)
|
||||
@@ -305,8 +299,7 @@ if not Config.OxInventory then
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent("esx:removeInventoryItem")
|
||||
AddEventHandler("esx:removeInventoryItem", function(item, count, showNotification)
|
||||
RegisterNetEvent("esx:removeInventoryItem", function(item, count, showNotification)
|
||||
for i = 1, #ESX.PlayerData.inventory do
|
||||
if ESX.PlayerData.inventory[i].name == item then
|
||||
ESX.UI.ShowInventoryItemNotification(false, ESX.PlayerData.inventory[i].label, ESX.PlayerData.inventory[i].count - count)
|
||||
@@ -320,51 +313,43 @@ if not Config.OxInventory then
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent("esx:addWeapon")
|
||||
AddEventHandler("esx:addWeapon", function()
|
||||
RegisterNetEvent("esx:addWeapon", function()
|
||||
error("event ^5'esx:addWeapon'^1 Has Been Removed. Please use ^5xPlayer.addWeapon^1 Instead!")
|
||||
end)
|
||||
|
||||
RegisterNetEvent("esx:addWeaponComponent")
|
||||
AddEventHandler("esx:addWeaponComponent", function()
|
||||
|
||||
RegisterNetEvent("esx:addWeaponComponent", function()
|
||||
error("event ^5'esx:addWeaponComponent'^1 Has Been Removed. Please use ^5xPlayer.addWeaponComponent^1 Instead!")
|
||||
end)
|
||||
|
||||
RegisterNetEvent("esx:setWeaponAmmo")
|
||||
AddEventHandler("esx:setWeaponAmmo", function()
|
||||
RegisterNetEvent("esx:setWeaponAmmo", function()
|
||||
error("event ^5'esx:setWeaponAmmo'^1 Has Been Removed. Please use ^5xPlayer.addWeaponAmmo^1 Instead!")
|
||||
end)
|
||||
|
||||
RegisterNetEvent("esx:setWeaponTint")
|
||||
AddEventHandler("esx:setWeaponTint", function(weapon, weaponTintIndex)
|
||||
RegisterNetEvent("esx:setWeaponTint", function(weapon, weaponTintIndex)
|
||||
SetPedWeaponTintIndex(ESX.PlayerData.ped, joaat(weapon), weaponTintIndex)
|
||||
end)
|
||||
|
||||
RegisterNetEvent("esx:removeWeapon")
|
||||
AddEventHandler("esx:removeWeapon", function()
|
||||
RegisterNetEvent("esx:removeWeapon", function()
|
||||
error("event ^5'esx:removeWeapon'^1 Has Been Removed. Please use ^5xPlayer.removeWeapon^1 Instead!")
|
||||
end)
|
||||
|
||||
RegisterNetEvent("esx:removeWeaponComponent")
|
||||
AddEventHandler("esx:removeWeaponComponent", function(weapon, weaponComponent)
|
||||
RegisterNetEvent("esx:removeWeaponComponent", function(weapon, weaponComponent)
|
||||
local componentHash = ESX.GetWeaponComponent(weapon, weaponComponent).hash
|
||||
RemoveWeaponComponentFromPed(ESX.PlayerData.ped, joaat(weapon), componentHash)
|
||||
end)
|
||||
end
|
||||
|
||||
RegisterNetEvent("esx:setJob")
|
||||
AddEventHandler("esx:setJob", function(Job)
|
||||
RegisterNetEvent("esx:setJob", function(Job)
|
||||
ESX.SetPlayerData("job", Job)
|
||||
end)
|
||||
|
||||
RegisterNetEvent("esx:setGroup")
|
||||
AddEventHandler("esx:setGroup", function(group)
|
||||
RegisterNetEvent("esx:setGroup", function(group)
|
||||
ESX.SetPlayerData("group", group)
|
||||
end)
|
||||
|
||||
if not Config.OxInventory then
|
||||
RegisterNetEvent("esx:createPickup")
|
||||
AddEventHandler("esx:createPickup", function(pickupId, label, coords, itemType, name, components, tintIndex)
|
||||
if not Config.CustomInventory then
|
||||
RegisterNetEvent("esx:createPickup", function(pickupId, label, coords, itemType, name, components, tintIndex)
|
||||
local function setObjectProperties(object)
|
||||
SetEntityAsMissionEntity(object, true, false)
|
||||
PlaceObjectOnGroundProperly(object)
|
||||
@@ -398,16 +383,14 @@ if not Config.OxInventory then
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent("esx:createMissingPickups")
|
||||
AddEventHandler("esx:createMissingPickups", function(missingPickups)
|
||||
RegisterNetEvent("esx:createMissingPickups", function(missingPickups)
|
||||
for pickupId, pickup in pairs(missingPickups) do
|
||||
TriggerEvent("esx:createPickup", pickupId, pickup.label, vector3(pickup.coords.x, pickup.coords.y, pickup.coords.z - 1.0), pickup.type, pickup.name, pickup.components, pickup.tintIndex)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
RegisterNetEvent("esx:registerSuggestions")
|
||||
AddEventHandler("esx:registerSuggestions", function(registeredCommands)
|
||||
RegisterNetEvent("esx:registerSuggestions", function(registeredCommands)
|
||||
for name, command in pairs(registeredCommands) do
|
||||
if command.suggestion then
|
||||
TriggerEvent("chat:addSuggestion", ("/%s"):format(name), command.suggestion.help, command.suggestion.arguments)
|
||||
@@ -415,9 +398,8 @@ AddEventHandler("esx:registerSuggestions", function(registeredCommands)
|
||||
end
|
||||
end)
|
||||
|
||||
if not Config.OxInventory then
|
||||
RegisterNetEvent("esx:removePickup")
|
||||
AddEventHandler("esx:removePickup", function(pickupId)
|
||||
if not Config.CustomInventory then
|
||||
RegisterNetEvent("esx:removePickup", function(pickupId)
|
||||
if pickups[pickupId] and pickups[pickupId].obj then
|
||||
ESX.Game.DeleteObject(pickups[pickupId].obj)
|
||||
pickups[pickupId] = nil
|
||||
@@ -426,37 +408,35 @@ if not Config.OxInventory then
|
||||
end
|
||||
|
||||
function StartServerSyncLoops()
|
||||
if not Config.OxInventory then
|
||||
-- keep track of ammo
|
||||
|
||||
CreateThread(function()
|
||||
local currentWeapon = { Ammo = 0 }
|
||||
while ESX.PlayerLoaded do
|
||||
local sleep = 1500
|
||||
if GetSelectedPedWeapon(ESX.PlayerData.ped) ~= -1569615261 then
|
||||
sleep = 1000
|
||||
local _, weaponHash = GetCurrentPedWeapon(ESX.PlayerData.ped, true)
|
||||
local weapon = ESX.GetWeaponFromHash(weaponHash)
|
||||
if weapon then
|
||||
local ammoCount = GetAmmoInPedWeapon(ESX.PlayerData.ped, weaponHash)
|
||||
if weapon.name ~= currentWeapon.name then
|
||||
if Config.CustomInventory then return end
|
||||
-- keep track of ammo
|
||||
CreateThread(function()
|
||||
local currentWeapon = { Ammo = 0 }
|
||||
while ESX.PlayerLoaded do
|
||||
local sleep = 1500
|
||||
if GetSelectedPedWeapon(ESX.PlayerData.ped) ~= -1569615261 then
|
||||
sleep = 1000
|
||||
local _, weaponHash = GetCurrentPedWeapon(ESX.PlayerData.ped, true)
|
||||
local weapon = ESX.GetWeaponFromHash(weaponHash)
|
||||
if weapon then
|
||||
local ammoCount = GetAmmoInPedWeapon(ESX.PlayerData.ped, weaponHash)
|
||||
if weapon.name ~= currentWeapon.name then
|
||||
currentWeapon.Ammo = ammoCount
|
||||
currentWeapon.name = weapon.name
|
||||
else
|
||||
if ammoCount ~= currentWeapon.Ammo then
|
||||
currentWeapon.Ammo = ammoCount
|
||||
currentWeapon.name = weapon.name
|
||||
else
|
||||
if ammoCount ~= currentWeapon.Ammo then
|
||||
currentWeapon.Ammo = ammoCount
|
||||
TriggerServerEvent("esx:updateWeaponAmmo", weapon.name, ammoCount)
|
||||
end
|
||||
TriggerServerEvent("esx:updateWeaponAmmo", weapon.name, ammoCount)
|
||||
end
|
||||
end
|
||||
end
|
||||
Wait(sleep)
|
||||
end
|
||||
end)
|
||||
end
|
||||
Wait(sleep)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
if not Config.OxInventory and Config.EnableDefaultInventory then
|
||||
if not Config.CustomInventory and Config.EnableDefaultInventory then
|
||||
ESX.RegisterInput("showinv", TranslateCap("keymap_showinventory"), "keyboard", "F2", function()
|
||||
if not ESX.PlayerData.dead then
|
||||
ESX.ShowInventory()
|
||||
@@ -470,7 +450,7 @@ if not Config.EnableWantedLevel then
|
||||
SetMaxWantedLevel(0)
|
||||
end
|
||||
|
||||
if not Config.OxInventory then
|
||||
if not Config.CustomInventory then
|
||||
CreateThread(function()
|
||||
while true do
|
||||
local Sleep = 1500
|
||||
@@ -515,9 +495,7 @@ if not Config.OxInventory then
|
||||
end
|
||||
|
||||
----- Admin commands from esx_adminplus
|
||||
|
||||
RegisterNetEvent("esx:tpm")
|
||||
AddEventHandler("esx:tpm", function()
|
||||
RegisterNetEvent("esx:tpm", function()
|
||||
local GetEntityCoords = GetEntityCoords
|
||||
local GetGroundZFor_3dCoord = GetGroundZFor_3dCoord
|
||||
local GetFirstBlipInfoId = GetFirstBlipInfoId
|
||||
@@ -649,8 +627,7 @@ local function noclipThread()
|
||||
end
|
||||
end
|
||||
|
||||
RegisterNetEvent("esx:noclip")
|
||||
AddEventHandler("esx:noclip", function()
|
||||
RegisterNetEvent("esx:noclip", function()
|
||||
ESX.TriggerServerCallback("esx:isUserAdmin", function(admin)
|
||||
if not admin then
|
||||
return
|
||||
@@ -674,13 +651,11 @@ AddEventHandler("esx:noclip", function()
|
||||
end)
|
||||
end)
|
||||
|
||||
RegisterNetEvent("esx:killPlayer")
|
||||
AddEventHandler("esx:killPlayer", function()
|
||||
RegisterNetEvent("esx:killPlayer", function()
|
||||
SetEntityHealth(ESX.PlayerData.ped, 0)
|
||||
end)
|
||||
|
||||
RegisterNetEvent("esx:repairPedVehicle")
|
||||
AddEventHandler("esx:repairPedVehicle", function()
|
||||
RegisterNetEvent("esx:repairPedVehicle", function()
|
||||
local ped = ESX.PlayerData.ped
|
||||
local vehicle = GetVehiclePedIsIn(ped, false)
|
||||
SetVehicleEngineHealth(vehicle, 1000)
|
||||
@@ -689,8 +664,7 @@ AddEventHandler("esx:repairPedVehicle", function()
|
||||
SetVehicleDirtLevel(vehicle, 0)
|
||||
end)
|
||||
|
||||
RegisterNetEvent("esx:freezePlayer")
|
||||
AddEventHandler("esx:freezePlayer", function(input)
|
||||
RegisterNetEvent("esx:freezePlayer", function(input)
|
||||
if input == "freeze" then
|
||||
SetEntityCollision(ESX.PlayerData.ped, false, false)
|
||||
FreezeEntityPosition(ESX.PlayerData.ped, true)
|
||||
|
||||
@@ -8,3 +8,6 @@ AddEventHandler("esx:getSharedObject", function()
|
||||
local Invoke = GetInvokingResource()
|
||||
error(("Resource ^5%s^1 Used the ^5getSharedObject^1 Event, this event ^1no longer exists!^1 Visit https://documentation.esx-framework.org/tutorials/tutorials-esx/sharedevent for how to fix!"):format(Invoke))
|
||||
end)
|
||||
|
||||
-- backwards compatibility (DO NOT TOUCH !)
|
||||
Config.OxInventory = Config.CustomInventory == "ox"
|
||||
@@ -4,8 +4,7 @@ local txAdminLocale = GetConvar("txAdmin-locale", "en")
|
||||
local esxLocale = GetConvar("esx:locale", "invalid")
|
||||
|
||||
Config.Locale = (esxLocale ~= "invalid") and esxLocale or (txAdminLocale ~= "custom" and txAdminLocale) or "en"
|
||||
|
||||
Config.OxInventory = GetResourceState("ox_inventory") ~= 'missing'
|
||||
Config.CustomInventory = false
|
||||
|
||||
Config.Accounts = {
|
||||
bank = {
|
||||
|
||||
@@ -31,6 +31,7 @@ server_scripts {
|
||||
'server/main.lua',
|
||||
'server/commands.lua',
|
||||
|
||||
'server/bridge/**/*.lua',
|
||||
'server/modules/actions.lua',
|
||||
'server/modules/npwd.lua',
|
||||
'server/modules/createJob.lua'
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
if Config.CustomInventory ~= "ox" then return end
|
||||
|
||||
MySQL.ready(function()
|
||||
TriggerEvent("__cfx_export_ox_inventory_Items", function(ref)
|
||||
if ref then
|
||||
ESX.Items = ref()
|
||||
end
|
||||
end)
|
||||
|
||||
AddEventHandler("ox_inventory:itemList", function(items)
|
||||
ESX.Items = items
|
||||
end)
|
||||
end)
|
||||
|
||||
function ESX.GetItemLabel(item)
|
||||
item = exports.ox_inventory:Items(item)
|
||||
if item then
|
||||
return item.label
|
||||
end
|
||||
end
|
||||
|
||||
function setPlayerInventory(playerId, xPlayer, inventory, isNew)
|
||||
exports.ox_inventory:setPlayerInventory(xPlayer, inventory)
|
||||
if isNew then
|
||||
local shared = json.decode(GetConvar("inventory:accounts", '["money"]'))
|
||||
|
||||
for i = 1, #shared do
|
||||
local name = shared[i]
|
||||
local account = Config.StartingAccountMoney[name]
|
||||
if account then
|
||||
exports.ox_inventory:AddItem(playerId, name, account)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,38 +1,38 @@
|
||||
local Inventory
|
||||
|
||||
if Config.OxInventory then
|
||||
AddEventHandler("ox_inventory:loadInventory", function(module)
|
||||
Inventory = module
|
||||
end)
|
||||
end
|
||||
if Config.OxInventory ~= "ox" then end
|
||||
|
||||
AddEventHandler("ox_inventory:loadInventory", function(module)
|
||||
Inventory = module
|
||||
end)
|
||||
|
||||
Core.PlayerFunctionOverrides.OxInventory = {
|
||||
getInventory = function(self)
|
||||
return function(minimal)
|
||||
if minimal then
|
||||
local minimalInventory = {}
|
||||
if not minimal then
|
||||
return self.inventory
|
||||
end
|
||||
|
||||
for k, v in pairs(self.inventory) do
|
||||
if v.count and v.count > 0 then
|
||||
local metadata = v.metadata
|
||||
local minimalInventory = {}
|
||||
|
||||
if v.metadata and next(v.metadata) == nil then
|
||||
metadata = nil
|
||||
end
|
||||
for k, v in pairs(self.inventory) do
|
||||
if v.count and v.count > 0 then
|
||||
local metadata = v.metadata
|
||||
|
||||
minimalInventory[#minimalInventory + 1] = {
|
||||
name = v.name,
|
||||
count = v.count,
|
||||
slot = k,
|
||||
metadata = metadata,
|
||||
}
|
||||
if v.metadata and next(v.metadata) == nil then
|
||||
metadata = nil
|
||||
end
|
||||
end
|
||||
|
||||
return minimalInventory
|
||||
minimalInventory[#minimalInventory + 1] = {
|
||||
name = v.name,
|
||||
count = v.count,
|
||||
slot = k,
|
||||
metadata = metadata,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
return self.inventory
|
||||
return minimalInventory
|
||||
end
|
||||
end,
|
||||
|
||||
@@ -45,19 +45,18 @@ Core.PlayerFunctionOverrides.OxInventory = {
|
||||
setAccountMoney = function(self)
|
||||
return function(accountName, money, reason)
|
||||
reason = reason or "unknown"
|
||||
if money >= 0 then
|
||||
local account = self.getAccount(accountName)
|
||||
if money < 0 then return end
|
||||
local account = self.getAccount(accountName)
|
||||
|
||||
if account then
|
||||
money = account.round and ESX.Math.Round(money) or money
|
||||
self.accounts[account.index].money = money
|
||||
if not account then return end
|
||||
|
||||
self.triggerEvent("esx:setAccountMoney", account)
|
||||
TriggerEvent("esx:setAccountMoney", self.source, accountName, money, reason)
|
||||
if Inventory.accounts[accountName] then
|
||||
Inventory.SetItem(self.source, accountName, money)
|
||||
end
|
||||
end
|
||||
money = account.round and ESX.Math.Round(money) or money
|
||||
self.accounts[account.index].money = money
|
||||
|
||||
self.triggerEvent("esx:setAccountMoney", account)
|
||||
TriggerEvent("esx:setAccountMoney", self.source, accountName, money, reason)
|
||||
if Inventory.accounts[accountName] then
|
||||
Inventory.SetItem(self.source, accountName, money)
|
||||
end
|
||||
end
|
||||
end,
|
||||
@@ -65,18 +64,17 @@ Core.PlayerFunctionOverrides.OxInventory = {
|
||||
addAccountMoney = function(self)
|
||||
return function(accountName, money, reason)
|
||||
reason = reason or "unknown"
|
||||
if money > 0 then
|
||||
local account = self.getAccount(accountName)
|
||||
if money < 1 then return end
|
||||
|
||||
if account then
|
||||
money = account.round and ESX.Math.Round(money) or money
|
||||
self.accounts[account.index].money = self.accounts[account.index].money + money
|
||||
self.triggerEvent("esx:setAccountMoney", account)
|
||||
TriggerEvent("esx:addAccountMoney", self.source, accountName, money, reason)
|
||||
if Inventory.accounts[accountName] then
|
||||
Inventory.AddItem(self.source, accountName, money)
|
||||
end
|
||||
end
|
||||
local account = self.getAccount(accountName)
|
||||
if not account then return end
|
||||
|
||||
money = account.round and ESX.Math.Round(money) or money
|
||||
self.accounts[account.index].money = self.accounts[account.index].money + money
|
||||
self.triggerEvent("esx:setAccountMoney", account)
|
||||
TriggerEvent("esx:addAccountMoney", self.source, accountName, money, reason)
|
||||
if Inventory.accounts[accountName] then
|
||||
Inventory.AddItem(self.source, accountName, money)
|
||||
end
|
||||
end
|
||||
end,
|
||||
@@ -84,18 +82,17 @@ Core.PlayerFunctionOverrides.OxInventory = {
|
||||
removeAccountMoney = function(self)
|
||||
return function(accountName, money, reason)
|
||||
reason = reason or "unknown"
|
||||
if money > 0 then
|
||||
local account = self.getAccount(accountName)
|
||||
if money < 1 then return end
|
||||
|
||||
if account then
|
||||
money = account.round and ESX.Math.Round(money) or money
|
||||
self.accounts[account.index].money = self.accounts[account.index].money - money
|
||||
self.triggerEvent("esx:setAccountMoney", account)
|
||||
TriggerEvent("esx:removeAccountMoney", self.source, accountName, money, reason)
|
||||
if Inventory.accounts[accountName] then
|
||||
Inventory.RemoveItem(self.source, accountName, money)
|
||||
end
|
||||
end
|
||||
local account = self.getAccount(accountName)
|
||||
if not account then return end
|
||||
|
||||
money = account.round and ESX.Math.Round(money) or money
|
||||
self.accounts[account.index].money = self.accounts[account.index].money - money
|
||||
self.triggerEvent("esx:setAccountMoney", account)
|
||||
TriggerEvent("esx:removeAccountMoney", self.source, accountName, money, reason)
|
||||
if Inventory.accounts[accountName] then
|
||||
Inventory.RemoveItem(self.source, accountName, money)
|
||||
end
|
||||
end
|
||||
end,
|
||||
@@ -207,15 +204,14 @@ Core.PlayerFunctionOverrides.OxInventory = {
|
||||
self.weight, self.maxWeight = weight, maxWeight
|
||||
self.inventory = items
|
||||
|
||||
if money then
|
||||
for accountName, amount in pairs(money) do
|
||||
local account = self.getAccount(accountName)
|
||||
if not money then return end
|
||||
for accountName, amount in pairs(money) do
|
||||
local account = self.getAccount(accountName)
|
||||
|
||||
if account and ESX.Math.Round(account.money) ~= amount then
|
||||
account.money = amount
|
||||
self.triggerEvent("esx:setAccountMoney", account)
|
||||
TriggerEvent("esx:setAccountMoney", self.source, accountName, amount, "Sync account with item")
|
||||
end
|
||||
if account and ESX.Math.Round(account.money) ~= amount then
|
||||
account.money = amount
|
||||
self.triggerEvent("esx:setAccountMoney", account)
|
||||
TriggerEvent("esx:setAccountMoney", self.source, accountName, amount, "Sync account with item")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
---@param coords table | vector4
|
||||
---@param metadata table
|
||||
function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory, weight, job, loadout, name, coords, metadata)
|
||||
local targetOverrides = Config.PlayerFunctionOverride and Core.PlayerFunctionOverrides[Config.PlayerFunctionOverride] or {}
|
||||
|
||||
---@class xPlayer
|
||||
local self = {}
|
||||
|
||||
@@ -912,9 +910,11 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
self.triggerEvent('esx:updatePlayerData', 'metadata', self.metadata)
|
||||
end
|
||||
|
||||
for fnName, fn in pairs(targetOverrides) do
|
||||
self[fnName] = fn(self)
|
||||
end
|
||||
for _, funcs in pairs(Core.PlayerFunctionOverrides) do
|
||||
for fnName, fn in pairs(funcs) do
|
||||
self[fnName] = fn(self)
|
||||
end
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -282,7 +282,7 @@ ESX.RegisterCommand(
|
||||
}
|
||||
)
|
||||
|
||||
if not Config.OxInventory then
|
||||
if not Config.CustomInventory then
|
||||
ESX.RegisterCommand(
|
||||
"giveitem",
|
||||
"admin",
|
||||
@@ -430,7 +430,7 @@ ESX.RegisterCommand("refreshjobs", "admin", function()
|
||||
ESX.RefreshJobs()
|
||||
end, true, { help = TranslateCap("command_clearall") })
|
||||
|
||||
if not Config.OxInventory then
|
||||
if not Config.CustomInventory then
|
||||
ESX.RegisterCommand(
|
||||
"clearinventory",
|
||||
"admin",
|
||||
|
||||
@@ -17,8 +17,7 @@ RegisterNetEvent("esx:onPlayerSpawn", function()
|
||||
ESX.Players[source].spawned = true
|
||||
end)
|
||||
|
||||
if Config.OxInventory then
|
||||
Config.PlayerFunctionOverride = "OxInventory"
|
||||
if Config.CustomInventory then
|
||||
SetConvarReplicated("inventory:framework", "esx")
|
||||
SetConvarReplicated("inventory:weight", tostring(Config.MaxWeight * 1000))
|
||||
end
|
||||
@@ -35,25 +34,11 @@ end
|
||||
|
||||
MySQL.ready(function()
|
||||
Core.DatabaseConnected = true
|
||||
if not Config.OxInventory then
|
||||
if not Config.CustomInventory then
|
||||
local items = MySQL.query.await("SELECT * FROM items")
|
||||
for _, v in ipairs(items) do
|
||||
ESX.Items[v.name] = { label = v.label, weight = v.weight, rare = v.rare, canRemove = v.can_remove }
|
||||
end
|
||||
else
|
||||
TriggerEvent("__cfx_export_ox_inventory_Items", function(ref)
|
||||
if ref then
|
||||
ESX.Items = ref()
|
||||
end
|
||||
end)
|
||||
|
||||
AddEventHandler("ox_inventory:itemList", function(items)
|
||||
ESX.Items = items
|
||||
end)
|
||||
|
||||
while not next(ESX.Items) do
|
||||
Wait(0)
|
||||
end
|
||||
end
|
||||
|
||||
ESX.RefreshJobs()
|
||||
@@ -66,8 +51,7 @@ MySQL.ready(function()
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent("esx:clientLog")
|
||||
AddEventHandler("esx:clientLog", function(msg)
|
||||
RegisterNetEvent("esx:clientLog", function(msg)
|
||||
if Config.EnableDebug then
|
||||
print(("[^2TRACE^7] %s^7"):format(msg))
|
||||
end
|
||||
|
||||
@@ -546,13 +546,6 @@ end
|
||||
---@param item string
|
||||
---@return string?
|
||||
function ESX.GetItemLabel(item)
|
||||
if Config.OxInventory then
|
||||
item = exports.ox_inventory:Items(item)
|
||||
if item then
|
||||
return item.label
|
||||
end
|
||||
end
|
||||
|
||||
if ESX.Items[item] then
|
||||
return ESX.Items[item].label
|
||||
else
|
||||
@@ -574,7 +567,7 @@ function ESX.GetUsableItems()
|
||||
return Usables
|
||||
end
|
||||
|
||||
if not Config.OxInventory then
|
||||
if not Config.CustomInventory then
|
||||
---@param itemType string
|
||||
---@param name string
|
||||
---@param count integer
|
||||
@@ -612,17 +605,10 @@ end
|
||||
---@return boolean
|
||||
function Core.IsPlayerAdmin(playerId)
|
||||
playerId = tostring(playerId)
|
||||
if (IsPlayerAceAllowed(playerId, "command") or GetConvar("sv_lan", "") == "true") and true or false then
|
||||
if (IsPlayerAceAllowed(playerId, "command") or GetConvar("sv_lan", "") == "true") then
|
||||
return true
|
||||
end
|
||||
|
||||
local xPlayer = ESX.Players[playerId]
|
||||
|
||||
if xPlayer then
|
||||
if Config.AdminGroups[xPlayer.group] then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
local xPlayer = ESX.Players[playerId]
|
||||
return (xPlayer and Config.AdminGroups[xPlayer.group] and true) or false
|
||||
end
|
||||
|
||||
+189
-198
@@ -46,24 +46,24 @@ end
|
||||
|
||||
local function onPlayerJoined(playerId)
|
||||
local identifier = ESX.GetIdentifier(playerId)
|
||||
if identifier then
|
||||
if ESX.GetPlayerFromIdentifier(identifier) then
|
||||
DropPlayer(
|
||||
playerId,
|
||||
("there was an error loading your character!\nError code: identifier-active-ingame\n\nThis error is caused by a player on this server who has the same identifier as you have. Make sure you are not playing on the same Rockstar account.\n\nYour Rockstar identifier: %s"):format(
|
||||
identifier
|
||||
)
|
||||
if not identifier then
|
||||
return DropPlayer(playerId, "there was an error loading your character!\nError code: identifier-missing-ingame\n\nThe cause of this error is not known, your identifier could not be found. Please come back later or report this problem to the server administration team.")
|
||||
end
|
||||
|
||||
if ESX.GetPlayerFromIdentifier(identifier) then
|
||||
DropPlayer(
|
||||
playerId,
|
||||
("there was an error loading your character!\nError code: identifier-active-ingame\n\nThis error is caused by a player on this server who has the same identifier as you have. Make sure you are not playing on the same Rockstar account.\n\nYour Rockstar identifier: %s"):format(
|
||||
identifier
|
||||
)
|
||||
else
|
||||
local result = MySQL.scalar.await("SELECT 1 FROM users WHERE identifier = ?", { identifier })
|
||||
if result then
|
||||
loadESXPlayer(identifier, playerId, false)
|
||||
else
|
||||
createESXPlayer(identifier, playerId)
|
||||
end
|
||||
end
|
||||
)
|
||||
else
|
||||
DropPlayer(playerId, "there was an error loading your character!\nError code: identifier-missing-ingame\n\nThe cause of this error is not known, your identifier could not be found. Please come back later or report this problem to the server administration team.")
|
||||
local result = MySQL.scalar.await("SELECT 1 FROM users WHERE identifier = ?", { identifier })
|
||||
if result then
|
||||
loadESXPlayer(identifier, playerId, false)
|
||||
else
|
||||
createESXPlayer(identifier, playerId)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -83,8 +83,7 @@ if Config.Multichar then
|
||||
end
|
||||
end)
|
||||
else
|
||||
RegisterNetEvent("esx:onPlayerJoined")
|
||||
AddEventHandler("esx:onPlayerJoined", function()
|
||||
RegisterNetEvent("esx:onPlayerJoined", function()
|
||||
local _source = source
|
||||
while not next(ESX.Jobs) do
|
||||
Wait(50)
|
||||
@@ -188,7 +187,7 @@ function loadESXPlayer(identifier, playerId, isNew)
|
||||
}
|
||||
|
||||
-- Inventory
|
||||
if not Config.OxInventory then
|
||||
if not Config.CustomInventory then
|
||||
local inventory = (result.inventory and result.inventory ~= "") and json.decode(result.inventory) or {}
|
||||
|
||||
for name, item in pairs(ESX.Items) do
|
||||
@@ -225,22 +224,23 @@ function loadESXPlayer(identifier, playerId, isNew)
|
||||
end
|
||||
|
||||
-- Loadout
|
||||
if not Config.OxInventory then
|
||||
if result.loadout and result.loadout ~= "" then
|
||||
local loadout = json.decode(result.loadout)
|
||||
if not Config.CustomInventory then
|
||||
if not result.loadout or result.loadout == "" then
|
||||
return
|
||||
end
|
||||
|
||||
for name, weapon in pairs(loadout) do
|
||||
local label = ESX.GetWeaponLabel(name)
|
||||
local loadout = json.decode(result.loadout)
|
||||
for name, weapon in pairs(loadout) do
|
||||
local label = ESX.GetWeaponLabel(name)
|
||||
|
||||
if label then
|
||||
userData.loadout[#userData.loadout + 1] = {
|
||||
name = name,
|
||||
ammo = weapon.ammo,
|
||||
label = label,
|
||||
components = weapon.components or {},
|
||||
tintIndex = weapon.tintIndex or 0,
|
||||
}
|
||||
end
|
||||
if label then
|
||||
userData.loadout[#userData.loadout + 1] = {
|
||||
name = name,
|
||||
ammo = weapon.ammo,
|
||||
label = label,
|
||||
components = weapon.components or {},
|
||||
tintIndex = weapon.tintIndex or 0,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -290,22 +290,12 @@ function loadESXPlayer(identifier, playerId, isNew)
|
||||
userData.maxWeight = xPlayer.getMaxWeight()
|
||||
xPlayer.triggerEvent("esx:playerLoaded", userData, isNew, userData.skin)
|
||||
|
||||
if not Config.OxInventory then
|
||||
if not Config.CustomInventory then
|
||||
xPlayer.triggerEvent("esx:createMissingPickups", Core.Pickups)
|
||||
else
|
||||
exports.ox_inventory:setPlayerInventory(xPlayer, userData.inventory)
|
||||
if isNew then
|
||||
local shared = json.decode(GetConvar("inventory:accounts", '["money"]'))
|
||||
|
||||
for i = 1, #shared do
|
||||
local name = shared[i]
|
||||
local account = Config.StartingAccountMoney[name]
|
||||
if account then
|
||||
exports.ox_inventory:AddItem(playerId, name, account)
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif setPlayerInventory then
|
||||
setPlayerInventory(playerId, xPlayer, userData.inventory, isNew)
|
||||
end
|
||||
|
||||
xPlayer.triggerEvent("esx:registerSuggestions", Core.RegisteredCommands)
|
||||
print(('[^2INFO^0] Player ^5"%s"^0 has connected to the server. ID: ^5%s^7'):format(xPlayer.getName(), playerId))
|
||||
end
|
||||
@@ -372,9 +362,8 @@ AddEventHandler("esx:playerLogout", function(playerId, cb)
|
||||
TriggerClientEvent("esx:onPlayerLogout", playerId)
|
||||
end)
|
||||
|
||||
if not Config.OxInventory then
|
||||
RegisterNetEvent("esx:updateWeaponAmmo")
|
||||
AddEventHandler("esx:updateWeaponAmmo", function(weaponName, ammoCount)
|
||||
if not Config.CustomInventory then
|
||||
RegisterNetEvent("esx:updateWeaponAmmo", function(weaponName, ammoCount)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
if xPlayer then
|
||||
@@ -382,8 +371,7 @@ if not Config.OxInventory then
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent("esx:giveInventoryItem")
|
||||
AddEventHandler("esx:giveInventoryItem", function(target, itemType, itemName, itemCount)
|
||||
RegisterNetEvent("esx:giveInventoryItem", function(target, itemType, itemName, itemCount)
|
||||
local playerId = source
|
||||
local sourceXPlayer = ESX.GetPlayerFromId(playerId)
|
||||
local targetXPlayer = ESX.GetPlayerFromId(target)
|
||||
@@ -396,200 +384,203 @@ if not Config.OxInventory then
|
||||
if itemType == "item_standard" then
|
||||
local sourceItem = sourceXPlayer.getInventoryItem(itemName)
|
||||
|
||||
if itemCount > 0 and sourceItem.count >= itemCount then
|
||||
if targetXPlayer.canCarryItem(itemName, itemCount) then
|
||||
sourceXPlayer.removeInventoryItem(itemName, itemCount)
|
||||
targetXPlayer.addInventoryItem(itemName, itemCount)
|
||||
|
||||
sourceXPlayer.showNotification(TranslateCap("gave_item", itemCount, sourceItem.label, targetXPlayer.name))
|
||||
targetXPlayer.showNotification(TranslateCap("received_item", itemCount, sourceItem.label, sourceXPlayer.name))
|
||||
else
|
||||
sourceXPlayer.showNotification(TranslateCap("ex_inv_lim", targetXPlayer.name))
|
||||
end
|
||||
else
|
||||
sourceXPlayer.showNotification(TranslateCap("imp_invalid_quantity"))
|
||||
if itemCount < 1 or sourceItem.count < itemCount then
|
||||
return sourceXPlayer.showNotification(TranslateCap("imp_invalid_quantity"))
|
||||
end
|
||||
|
||||
if not targetXPlayer.canCarryItem(itemName, itemCount) then
|
||||
return sourceXPlayer.showNotification(TranslateCap("ex_inv_lim", targetXPlayer.name))
|
||||
end
|
||||
|
||||
sourceXPlayer.removeInventoryItem(itemName, itemCount)
|
||||
targetXPlayer.addInventoryItem(itemName, itemCount)
|
||||
|
||||
sourceXPlayer.showNotification(TranslateCap("gave_item", itemCount, sourceItem.label, targetXPlayer.name))
|
||||
targetXPlayer.showNotification(TranslateCap("received_item", itemCount, sourceItem.label, sourceXPlayer.name))
|
||||
elseif itemType == "item_account" then
|
||||
if itemCount > 0 and sourceXPlayer.getAccount(itemName).money >= itemCount then
|
||||
sourceXPlayer.removeAccountMoney(itemName, itemCount, "Gave to " .. targetXPlayer.name)
|
||||
targetXPlayer.addAccountMoney(itemName, itemCount, "Received from " .. sourceXPlayer.name)
|
||||
if itemCount < 1 or sourceXPlayer.getAccount(itemName).money < itemCount then
|
||||
return sourceXPlayer.showNotification(TranslateCap("imp_invalid_amount"))
|
||||
end
|
||||
|
||||
sourceXPlayer.showNotification(TranslateCap("gave_account_money", ESX.Math.GroupDigits(itemCount), Config.Accounts[itemName].label, targetXPlayer.name))
|
||||
targetXPlayer.showNotification(TranslateCap("received_account_money", ESX.Math.GroupDigits(itemCount), Config.Accounts[itemName].label, sourceXPlayer.name))
|
||||
else
|
||||
sourceXPlayer.showNotification(TranslateCap("imp_invalid_amount"))
|
||||
end
|
||||
sourceXPlayer.removeAccountMoney(itemName, itemCount, "Gave to " .. targetXPlayer.name)
|
||||
targetXPlayer.addAccountMoney(itemName, itemCount, "Received from " .. sourceXPlayer.name)
|
||||
|
||||
sourceXPlayer.showNotification(TranslateCap("gave_account_money", ESX.Math.GroupDigits(itemCount), Config.Accounts[itemName].label, targetXPlayer.name))
|
||||
targetXPlayer.showNotification(TranslateCap("received_account_money", ESX.Math.GroupDigits(itemCount), Config.Accounts[itemName].label, sourceXPlayer.name))
|
||||
elseif itemType == "item_weapon" then
|
||||
if sourceXPlayer.hasWeapon(itemName) then
|
||||
local weaponLabel = ESX.GetWeaponLabel(itemName)
|
||||
if not targetXPlayer.hasWeapon(itemName) then
|
||||
local _, weapon = sourceXPlayer.getWeapon(itemName)
|
||||
local _, weaponObject = ESX.GetWeapon(itemName)
|
||||
itemCount = weapon.ammo
|
||||
local weaponComponents = ESX.Table.Clone(weapon.components)
|
||||
local weaponTint = weapon.tintIndex
|
||||
if weaponTint then
|
||||
targetXPlayer.setWeaponTint(itemName, weaponTint)
|
||||
end
|
||||
if weaponComponents then
|
||||
for _, v in pairs(weaponComponents) do
|
||||
targetXPlayer.addWeaponComponent(itemName, v)
|
||||
end
|
||||
end
|
||||
sourceXPlayer.removeWeapon(itemName)
|
||||
targetXPlayer.addWeapon(itemName, itemCount)
|
||||
if not sourceXPlayer.hasWeapon(itemName) then
|
||||
return
|
||||
end
|
||||
|
||||
if weaponObject.ammo and itemCount > 0 then
|
||||
local ammoLabel = weaponObject.ammo.label
|
||||
sourceXPlayer.showNotification(TranslateCap("gave_weapon_withammo", weaponLabel, itemCount, ammoLabel, targetXPlayer.name))
|
||||
targetXPlayer.showNotification(TranslateCap("received_weapon_withammo", weaponLabel, itemCount, ammoLabel, sourceXPlayer.name))
|
||||
else
|
||||
sourceXPlayer.showNotification(TranslateCap("gave_weapon", weaponLabel, targetXPlayer.name))
|
||||
targetXPlayer.showNotification(TranslateCap("received_weapon", weaponLabel, sourceXPlayer.name))
|
||||
end
|
||||
else
|
||||
sourceXPlayer.showNotification(TranslateCap("gave_weapon_hasalready", targetXPlayer.name, weaponLabel))
|
||||
targetXPlayer.showNotification(TranslateCap("received_weapon_hasalready", sourceXPlayer.name, weaponLabel))
|
||||
local weaponLabel = ESX.GetWeaponLabel(itemName)
|
||||
if targetXPlayer.hasWeapon(itemName) then
|
||||
sourceXPlayer.showNotification(TranslateCap("gave_weapon_hasalready", targetXPlayer.name, weaponLabel))
|
||||
targetXPlayer.showNotification(TranslateCap("received_weapon_hasalready", sourceXPlayer.name, weaponLabel))
|
||||
return
|
||||
end
|
||||
|
||||
local _, weapon = sourceXPlayer.getWeapon(itemName)
|
||||
local _, weaponObject = ESX.GetWeapon(itemName)
|
||||
itemCount = weapon.ammo
|
||||
local weaponComponents = ESX.Table.Clone(weapon.components)
|
||||
local weaponTint = weapon.tintIndex
|
||||
|
||||
if weaponTint then
|
||||
targetXPlayer.setWeaponTint(itemName, weaponTint)
|
||||
end
|
||||
|
||||
if weaponComponents then
|
||||
for _, v in pairs(weaponComponents) do
|
||||
targetXPlayer.addWeaponComponent(itemName, v)
|
||||
end
|
||||
end
|
||||
|
||||
sourceXPlayer.removeWeapon(itemName)
|
||||
targetXPlayer.addWeapon(itemName, itemCount)
|
||||
|
||||
if weaponObject.ammo and itemCount > 0 then
|
||||
local ammoLabel = weaponObject.ammo.label
|
||||
sourceXPlayer.showNotification(TranslateCap("gave_weapon_withammo", weaponLabel, itemCount, ammoLabel, targetXPlayer.name))
|
||||
targetXPlayer.showNotification(TranslateCap("received_weapon_withammo", weaponLabel, itemCount, ammoLabel, sourceXPlayer.name))
|
||||
else
|
||||
sourceXPlayer.showNotification(TranslateCap("gave_weapon", weaponLabel, targetXPlayer.name))
|
||||
targetXPlayer.showNotification(TranslateCap("received_weapon", weaponLabel, sourceXPlayer.name))
|
||||
end
|
||||
elseif itemType == "item_ammo" then
|
||||
if sourceXPlayer.hasWeapon(itemName) then
|
||||
local _, weapon = sourceXPlayer.getWeapon(itemName)
|
||||
if not sourceXPlayer.hasWeapon(itemName) then
|
||||
return
|
||||
end
|
||||
|
||||
if targetXPlayer.hasWeapon(itemName) then
|
||||
local _, weaponObject = ESX.GetWeapon(itemName)
|
||||
local _, weapon = sourceXPlayer.getWeapon(itemName)
|
||||
|
||||
if weaponObject.ammo then
|
||||
local ammoLabel = weaponObject.ammo.label
|
||||
if not targetXPlayer.hasWeapon(itemName) then
|
||||
sourceXPlayer.showNotification(TranslateCap("gave_weapon_noweapon", targetXPlayer.name))
|
||||
targetXPlayer.showNotification(TranslateCap("received_weapon_noweapon", sourceXPlayer.name, weapon.label))
|
||||
end
|
||||
|
||||
if weapon.ammo >= itemCount then
|
||||
sourceXPlayer.removeWeaponAmmo(itemName, itemCount)
|
||||
targetXPlayer.addWeaponAmmo(itemName, itemCount)
|
||||
local _, weaponObject = ESX.GetWeapon(itemName)
|
||||
|
||||
sourceXPlayer.showNotification(TranslateCap("gave_weapon_ammo", itemCount, ammoLabel, weapon.label, targetXPlayer.name))
|
||||
targetXPlayer.showNotification(TranslateCap("received_weapon_ammo", itemCount, ammoLabel, weapon.label, sourceXPlayer.name))
|
||||
end
|
||||
end
|
||||
else
|
||||
sourceXPlayer.showNotification(TranslateCap("gave_weapon_noweapon", targetXPlayer.name))
|
||||
targetXPlayer.showNotification(TranslateCap("received_weapon_noweapon", sourceXPlayer.name, weapon.label))
|
||||
end
|
||||
if not weaponObject.ammo then return end
|
||||
|
||||
local ammoLabel = weaponObject.ammo.label
|
||||
if weapon.ammo >= itemCount then
|
||||
sourceXPlayer.removeWeaponAmmo(itemName, itemCount)
|
||||
targetXPlayer.addWeaponAmmo(itemName, itemCount)
|
||||
|
||||
sourceXPlayer.showNotification(TranslateCap("gave_weapon_ammo", itemCount, ammoLabel, weapon.label, targetXPlayer.name))
|
||||
targetXPlayer.showNotification(TranslateCap("received_weapon_ammo", itemCount, ammoLabel, weapon.label, sourceXPlayer.name))
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent("esx:removeInventoryItem")
|
||||
AddEventHandler("esx:removeInventoryItem", function(itemType, itemName, itemCount)
|
||||
RegisterNetEvent("esx:removeInventoryItem", function(itemType, itemName, itemCount)
|
||||
local playerId = source
|
||||
local xPlayer = ESX.GetPlayerFromId(playerId)
|
||||
|
||||
if itemType == "item_standard" then
|
||||
if itemCount == nil or itemCount < 1 then
|
||||
xPlayer.showNotification(TranslateCap("imp_invalid_quantity"))
|
||||
else
|
||||
local xItem = xPlayer.getInventoryItem(itemName)
|
||||
|
||||
if itemCount > xItem.count or xItem.count < 1 then
|
||||
xPlayer.showNotification(TranslateCap("imp_invalid_quantity"))
|
||||
else
|
||||
xPlayer.removeInventoryItem(itemName, itemCount)
|
||||
local pickupLabel = ("%s [%s]"):format(xItem.label, itemCount)
|
||||
ESX.CreatePickup("item_standard", itemName, itemCount, pickupLabel, playerId)
|
||||
xPlayer.showNotification(TranslateCap("threw_standard", itemCount, xItem.label))
|
||||
end
|
||||
if not itemCount or itemCount < 1 then
|
||||
return xPlayer.showNotification(TranslateCap("imp_invalid_quantity"))
|
||||
end
|
||||
|
||||
local xItem = xPlayer.getInventoryItem(itemName)
|
||||
|
||||
if itemCount > xItem.count or xItem.count < 1 then
|
||||
return xPlayer.showNotification(TranslateCap("imp_invalid_quantity"))
|
||||
end
|
||||
|
||||
xPlayer.removeInventoryItem(itemName, itemCount)
|
||||
local pickupLabel = ("%s [%s]"):format(xItem.label, itemCount)
|
||||
ESX.CreatePickup("item_standard", itemName, itemCount, pickupLabel, playerId)
|
||||
xPlayer.showNotification(TranslateCap("threw_standard", itemCount, xItem.label))
|
||||
elseif itemType == "item_account" then
|
||||
if itemCount == nil or itemCount < 1 then
|
||||
xPlayer.showNotification(TranslateCap("imp_invalid_amount"))
|
||||
else
|
||||
return xPlayer.showNotification(TranslateCap("imp_invalid_amount"))
|
||||
end
|
||||
local account = xPlayer.getAccount(itemName)
|
||||
|
||||
if itemCount > account.money or account.money < 1 then
|
||||
xPlayer.showNotification(TranslateCap("imp_invalid_amount"))
|
||||
else
|
||||
xPlayer.removeAccountMoney(itemName, itemCount, "Threw away")
|
||||
local pickupLabel = ("%s [%s]"):format(account.label, TranslateCap("locale_currency", ESX.Math.GroupDigits(itemCount)))
|
||||
ESX.CreatePickup("item_account", itemName, itemCount, pickupLabel, playerId)
|
||||
xPlayer.showNotification(TranslateCap("threw_account", ESX.Math.GroupDigits(itemCount), string.lower(account.label)))
|
||||
end
|
||||
if itemCount > account.money or account.money < 1 then
|
||||
return xPlayer.showNotification(TranslateCap("imp_invalid_amount"))
|
||||
end
|
||||
|
||||
xPlayer.removeAccountMoney(itemName, itemCount, "Threw away")
|
||||
local pickupLabel = ("%s [%s]"):format(account.label, TranslateCap("locale_currency", ESX.Math.GroupDigits(itemCount)))
|
||||
ESX.CreatePickup("item_account", itemName, itemCount, pickupLabel, playerId)
|
||||
xPlayer.showNotification(TranslateCap("threw_account", ESX.Math.GroupDigits(itemCount), string.lower(account.label)))
|
||||
elseif itemType == "item_weapon" then
|
||||
itemName = string.upper(itemName)
|
||||
|
||||
if xPlayer.hasWeapon(itemName) then
|
||||
local _, weapon = xPlayer.getWeapon(itemName)
|
||||
local _, weaponObject = ESX.GetWeapon(itemName)
|
||||
-- luacheck: ignore weaponPickupLabel
|
||||
local weaponPickupLabel = ""
|
||||
local components = ESX.Table.Clone(weapon.components)
|
||||
xPlayer.removeWeapon(itemName)
|
||||
if not xPlayer.hasWeapon(itemName) then return end
|
||||
|
||||
if weaponObject.ammo and weapon.ammo > 0 then
|
||||
local ammoLabel = weaponObject.ammo.label
|
||||
weaponPickupLabel = ("%s [%s %s]"):format(weapon.label, weapon.ammo, ammoLabel)
|
||||
xPlayer.showNotification(TranslateCap("threw_weapon_ammo", weapon.label, weapon.ammo, ammoLabel))
|
||||
else
|
||||
weaponPickupLabel = ("%s"):format(weapon.label)
|
||||
xPlayer.showNotification(TranslateCap("threw_weapon", weapon.label))
|
||||
end
|
||||
local _, weapon = xPlayer.getWeapon(itemName)
|
||||
local _, weaponObject = ESX.GetWeapon(itemName)
|
||||
-- luacheck: ignore weaponPickupLabel
|
||||
local weaponPickupLabel = ""
|
||||
local components = ESX.Table.Clone(weapon.components)
|
||||
xPlayer.removeWeapon(itemName)
|
||||
|
||||
ESX.CreatePickup("item_weapon", itemName, weapon.ammo, weaponPickupLabel, playerId, components, weapon.tintIndex)
|
||||
if weaponObject.ammo and weapon.ammo > 0 then
|
||||
local ammoLabel = weaponObject.ammo.label
|
||||
weaponPickupLabel = ("%s [%s %s]"):format(weapon.label, weapon.ammo, ammoLabel)
|
||||
xPlayer.showNotification(TranslateCap("threw_weapon_ammo", weapon.label, weapon.ammo, ammoLabel))
|
||||
else
|
||||
weaponPickupLabel = ("%s"):format(weapon.label)
|
||||
xPlayer.showNotification(TranslateCap("threw_weapon", weapon.label))
|
||||
end
|
||||
|
||||
ESX.CreatePickup("item_weapon", itemName, weapon.ammo, weaponPickupLabel, playerId, components, weapon.tintIndex)
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent("esx:useItem")
|
||||
AddEventHandler("esx:useItem", function(itemName)
|
||||
RegisterNetEvent("esx:useItem", function(itemName)
|
||||
local source = source
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
local count = xPlayer.getInventoryItem(itemName).count
|
||||
|
||||
if count > 0 then
|
||||
ESX.UseItem(source, itemName)
|
||||
else
|
||||
xPlayer.showNotification(TranslateCap("act_imp"))
|
||||
end
|
||||
if count < 1 then
|
||||
return xPlayer.showNotification(TranslateCap("act_imp"))
|
||||
end
|
||||
|
||||
ESX.UseItem(source, itemName)
|
||||
end)
|
||||
|
||||
RegisterNetEvent("esx:onPickup")
|
||||
AddEventHandler("esx:onPickup", function(pickupId)
|
||||
RegisterNetEvent("esx:onPickup", function(pickupId)
|
||||
local pickup, xPlayer, success = Core.Pickups[pickupId], ESX.GetPlayerFromId(source)
|
||||
|
||||
if pickup then
|
||||
local playerPickupDistance = #(pickup.coords - xPlayer.getCoords(true))
|
||||
if playerPickupDistance > 5.0 then
|
||||
print(("[^3WARNING^7] Player Detected Cheating (Out of range pickup): ^5%s^7"):format(xPlayer.getIdentifier()))
|
||||
return
|
||||
if not pickup then return end
|
||||
|
||||
local playerPickupDistance = #(pickup.coords - xPlayer.getCoords(true))
|
||||
if playerPickupDistance > 5.0 then
|
||||
print(("[^3WARNING^7] Player Detected Cheating (Out of range pickup): ^5%s^7"):format(xPlayer.getIdentifier()))
|
||||
return
|
||||
end
|
||||
|
||||
if pickup.type == "item_standard" then
|
||||
if not xPlayer.canCarryItem(pickup.name, pickup.count) then
|
||||
return xPlayer.showNotification(TranslateCap("threw_cannot_pickup"))
|
||||
end
|
||||
|
||||
xPlayer.addInventoryItem(pickup.name, pickup.count)
|
||||
success = true
|
||||
elseif pickup.type == "item_account" then
|
||||
success = true
|
||||
xPlayer.addAccountMoney(pickup.name, pickup.count, "Picked up")
|
||||
elseif pickup.type == "item_weapon" then
|
||||
if xPlayer.hasWeapon(pickup.name) then
|
||||
return xPlayer.showNotification(TranslateCap("threw_weapon_already"))
|
||||
end
|
||||
|
||||
if pickup.type == "item_standard" then
|
||||
if xPlayer.canCarryItem(pickup.name, pickup.count) then
|
||||
xPlayer.addInventoryItem(pickup.name, pickup.count)
|
||||
success = true
|
||||
else
|
||||
xPlayer.showNotification(TranslateCap("threw_cannot_pickup"))
|
||||
end
|
||||
elseif pickup.type == "item_account" then
|
||||
success = true
|
||||
xPlayer.addAccountMoney(pickup.name, pickup.count, "Picked up")
|
||||
elseif pickup.type == "item_weapon" then
|
||||
if xPlayer.hasWeapon(pickup.name) then
|
||||
xPlayer.showNotification(TranslateCap("threw_weapon_already"))
|
||||
else
|
||||
success = true
|
||||
xPlayer.addWeapon(pickup.name, pickup.count)
|
||||
xPlayer.setWeaponTint(pickup.name, pickup.tintIndex)
|
||||
success = true
|
||||
xPlayer.addWeapon(pickup.name, pickup.count)
|
||||
xPlayer.setWeaponTint(pickup.name, pickup.tintIndex)
|
||||
|
||||
for _, v in ipairs(pickup.components) do
|
||||
xPlayer.addWeaponComponent(pickup.name, v)
|
||||
end
|
||||
end
|
||||
for _, v in ipairs(pickup.components) do
|
||||
xPlayer.addWeaponComponent(pickup.name, v)
|
||||
end
|
||||
end
|
||||
|
||||
if success then
|
||||
Core.Pickups[pickupId] = nil
|
||||
TriggerClientEvent("esx:removePickup", -1, pickupId)
|
||||
end
|
||||
if success then
|
||||
Core.Pickups[pickupId] = nil
|
||||
TriggerClientEvent("esx:removePickup", -1, pickupId)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
RegisterNetEvent("esx_skin:save", function(skin)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
if not ESX.GetConfig().OxInventory then
|
||||
if not ESX.GetConfig().CustomInventory then
|
||||
local defaultMaxWeight = ESX.GetConfig().MaxWeight
|
||||
local backpackModifier = Config.BackpackWeight[skin.bags_1]
|
||||
|
||||
@@ -18,10 +18,10 @@ RegisterNetEvent("esx_skin:save", function(skin)
|
||||
})
|
||||
end)
|
||||
|
||||
RegisterServerEvent("esx_skin:setWeight", function(skin)
|
||||
RegisterNetEvent("esx_skin:setWeight", function(skin)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
|
||||
if not ESX.GetConfig().OxInventory then
|
||||
if not ESX.GetConfig().CustomInventory then
|
||||
local defaultMaxWeight = ESX.GetConfig().MaxWeight
|
||||
local backpackModifier = Config.BackpackWeight[skin.bags_1]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user