Merge pull request #167 from Tinky124/patch-2

fix(es_extended/server/main.lua): fix giving weapon components + tints, feat(es_extended/server/main.lua): add distance check
This commit is contained in:
Mycroft
2022-04-08 15:54:40 +01:00
committed by GitHub
2 changed files with 17 additions and 2 deletions
+2
View File
@@ -20,3 +20,5 @@ Config.EnablePVP = true -- Allow Player to player combat
Config.Multichar = true -- Enable support for esx_multicharacter
Config.Identity = true -- Select a characters identity data before they have loaded in (this happens by default with multichar)
Config.DistanceGive = 4.0 -- Max distance when giving items, weapons etc.
+15 -2
View File
@@ -360,6 +360,11 @@ if not Config.OxInventory then
local playerId = source
local sourceXPlayer = ESX.GetPlayerFromId(playerId)
local targetXPlayer = ESX.GetPlayerFromId(target)
local distance = #(GetEntityCoords(GetPlayerPed(playerId)) - GetEntityCoords(GetPlayerPed(target)))
if not sourceXPlayer then return end
if not targetXPlayer then print("Cheating: " .. GetPlayerName(playerId)) return end
if distance > Config.DistanceGive then print("Cheating: " .. GetPlayerName(playerId)) return end
if type == 'item_standard' then
local sourceItem = sourceXPlayer.getInventoryItem(itemName)
@@ -390,12 +395,20 @@ if not Config.OxInventory then
elseif type == '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 k, v in pairs(weaponComponents) do
targetXPlayer.addWeaponComponent(itemName, v)
end
end
sourceXPlayer.removeWeapon(itemName)
targetXPlayer.addWeapon(itemName, itemCount)