diff --git a/resources/[essential]/es_extended/client/functions.lua b/resources/[essential]/es_extended/client/functions.lua index 1ae278af..4e215f1d 100644 --- a/resources/[essential]/es_extended/client/functions.lua +++ b/resources/[essential]/es_extended/client/functions.lua @@ -320,6 +320,11 @@ ESX.Game.DeleteVehicle = function(vehicle) DeleteVehicle(vehicle) end +ESX.Game.DeleteObject = function(object) + SetEntityAsMissionEntity(object, false, true) + DeleteObject(object) +end + ESX.Game.SpawnVehicle = function(modelName, coords, heading, cb) local model = (type(modelName) == 'number' and modelName or GetHashKey(modelName)) diff --git a/resources/[essential]/es_extended/client/main.lua b/resources/[essential]/es_extended/client/main.lua index d0266595..1d9ffa1e 100644 --- a/resources/[essential]/es_extended/client/main.lua +++ b/resources/[essential]/es_extended/client/main.lua @@ -16,6 +16,7 @@ local PlayerLoaded = false local LoadoutLoaded = false local IsPaused = false local LastLoadout = {} +local Pickups = {} RegisterNetEvent('esx:playerLoaded') AddEventHandler('esx:playerLoaded', function(xPlayer) @@ -249,7 +250,65 @@ AddEventHandler('esx:spawnVehicle', function(model) end) --- Pickup Weapon +RegisterNetEvent('esx:spawnObject') +AddEventHandler('esx:spawnObject', function(model) + + local playerPed = GetPlayerPed(-1) + local coords = GetEntityCoords(playerPed) + local forward = GetEntityForwardVector(playerPed) + local x, y, z = table.unpack(coords + forward * 1.0) + + ESX.Game.SpawnObject(model, { + x = x, + y = y, + z = z + }, function(obj) + SetEntityHeading(obj, GetEntityHeading(playerPed)) + PlaceObjectOnGroundProperly(obj) + end) + +end) + +RegisterNetEvent('esx:pickup') +AddEventHandler('esx:pickup', function(id, label) + + local playerPed = GetPlayerPed(-1) + local coords = GetEntityCoords(playerPed) + local forward = GetEntityForwardVector(playerPed) + local x, y, z = table.unpack(coords + forward * -2.0) + + ESX.Game.SpawnLocalObject('prop_money_bag_01', { + x = x, + y = y, + z = z - 2.0, + }, function(obj) + + SetEntityAsMissionEntity(obj, true, false) + + PlaceObjectOnGroundProperly(obj) + + Pickups[id] = { + id = id, + obj = obj, + label = label, + inRange = false, + coords = { + x = x, + y = y, + z = z + }, + } + + end) + +end) + +RegisterNetEvent('esx:removePickup') +AddEventHandler('esx:removePickup', function(id) + ESX.Game.DeleteObject(Pickups[id].obj) + Pickups[id] = nil +end) + RegisterNetEvent('esx:pickupWeapon') AddEventHandler('esx:pickupWeapon', function(weaponPickup, weaponName) @@ -386,3 +445,35 @@ if Config.DisableWantedLevel then end +-- Pickups +Citizen.CreateThread(function() + while true do + + Citizen.Wait(0) + + local playerPed = GetPlayerPed(-1) + local coords = GetEntityCoords(playerPed) + + for k,v in pairs(Pickups) do + + local distance = GetDistanceBetweenCoords(coords.x, coords.y, coords.z, v.coords.x, v.coords.y, v.coords.z, true) + + if distance <= 5.0 then + + ESX.Game.Utils.DrawText3D({ + x = v.coords.x, + y = v.coords.y, + z = v.coords.z + 0.25 + }, v.label) + + end + + if distance <= 1.0 and not v.inRange then + TriggerServerEvent('esx:onPickup', v.id) + v.inRange = true + end + + end + + end +end) \ No newline at end of file diff --git a/resources/[essential]/es_extended/locales/br.lua b/resources/[essential]/es_extended/locales/br.lua index db4e39aa..cf47cb80 100644 --- a/resources/[essential]/es_extended/locales/br.lua +++ b/resources/[essential]/es_extended/locales/br.lua @@ -29,6 +29,7 @@ Locales['br'] = { ['play_emote'] = 'reproduzir emote', ['spawn_car'] = 'fazer aparecer um carro', ['spawn_car_param'] = 'nome do carro', + ['spawn_object'] = 'gerar um objeto', ['givemoney'] = 'dar dinheiro', ['money_amount'] = 'quantia do dinheiro', ['invalid_account'] = 'conta inválida', diff --git a/resources/[essential]/es_extended/locales/en.lua b/resources/[essential]/es_extended/locales/en.lua index 0a059de2..def2cc5e 100644 --- a/resources/[essential]/es_extended/locales/en.lua +++ b/resources/[essential]/es_extended/locales/en.lua @@ -29,6 +29,7 @@ Locales['en'] = { ['play_emote'] = 'play emote', ['spawn_car'] = 'spawn a car', ['spawn_car_param'] = 'name of car', + ['spawn_object'] = 'spawn object', ['givemoney'] = 'give money', ['money_amount'] = 'amount of money', ['invalid_account'] = 'invalid account', diff --git a/resources/[essential]/es_extended/locales/fr.lua b/resources/[essential]/es_extended/locales/fr.lua index e5af7b97..02bf1c10 100644 --- a/resources/[essential]/es_extended/locales/fr.lua +++ b/resources/[essential]/es_extended/locales/fr.lua @@ -29,6 +29,7 @@ Locales['fr'] = { ['play_emote'] = 'jouer emote', ['spawn_car'] = 'spawn un véhicule', ['spawn_car_param'] = 'nom de la voiture', + ['spawn_object'] = 'spawn un objet', ['givemoney'] = 'donner de l\'argent', ['money_amount'] = 'somme d\'argent', ['invalid_account'] = 'compete invalide', diff --git a/resources/[essential]/es_extended/server/commands.lua b/resources/[essential]/es_extended/server/commands.lua index 16def62e..e4102452 100644 --- a/resources/[essential]/es_extended/server/commands.lua +++ b/resources/[essential]/es_extended/server/commands.lua @@ -47,6 +47,12 @@ end, function(source, args, user) TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficient Permissions.") end, {help = _U('spawn_car'), params = {{name = "car", help = _U('spawn_car_param')}}}) +TriggerEvent('es:addGroupCommand', 'spawnobject', 'admin', function(source, args, user) + TriggerClientEvent('esx:spawnObject', source, args[2]) +end, function(source, args, user) + TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficient Permissions.") +end, {help = _U('spawn_object'), params = {{name = "name"}}}) + TriggerEvent('es:addGroupCommand', 'givemoney', 'admin', function(source, args, user) local _source = source diff --git a/resources/[essential]/es_extended/server/common.lua b/resources/[essential]/es_extended/server/common.lua index 5e6a1042..6676db37 100644 --- a/resources/[essential]/es_extended/server/common.lua +++ b/resources/[essential]/es_extended/server/common.lua @@ -4,6 +4,8 @@ ESX.UsableItemsCallbacks = {} ESX.Items = {} ESX.ServerCallbacks = {} ESX.LastPlayerData = {} +ESX.Pickups = {} +ESX.PickupId = 0 AddEventHandler('esx:getSharedObject', function(cb) cb(ESX) diff --git a/resources/[essential]/es_extended/server/functions.lua b/resources/[essential]/es_extended/server/functions.lua index 000402cf..45582314 100644 --- a/resources/[essential]/es_extended/server/functions.lua +++ b/resources/[essential]/es_extended/server/functions.lua @@ -223,3 +223,19 @@ ESX.GetWeaponLabel = function(name) end end + +ESX.CreatePickup = function(type, name, count, label) + + local pickupId = (ESX.PickupId == 65635 and 0 or ESX.PickupId + 1) + + ESX.Pickups[pickupId] = { + type = type, + name = name, + count = count + } + + TriggerClientEvent('esx:pickup', -1, pickupId, label) + + ESX.PickupId = pickupId + +end \ No newline at end of file diff --git a/resources/[essential]/es_extended/server/main.lua b/resources/[essential]/es_extended/server/main.lua index 23bab0e4..1a9134c3 100644 --- a/resources/[essential]/es_extended/server/main.lua +++ b/resources/[essential]/es_extended/server/main.lua @@ -404,6 +404,7 @@ AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount) if total > 0 then xPlayer.removeInventoryItem(itemName, total) + ESX.CreatePickup('item_standard', itemName, total, foundItem.label) TriggerClientEvent('esx:showNotification', _source, _U('threw') .. ' ' .. foundItem.label .. ' x' .. total) end @@ -438,6 +439,7 @@ AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount) if total > 0 then xPlayer.removeMoney(total) + ESX.CreatePickup('item_money', 'money', total, 'Cash') TriggerClientEvent('esx:showNotification', _source, _U('threw') .. ' [Cash] $' .. total) end @@ -472,6 +474,7 @@ AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount) if total > 0 then xPlayer.removeAccountMoney(itemName, total) + ESX.CreatePickup('item_account', itemName, total, 'Cash') TriggerClientEvent('esx:showNotification', _source, _U('threw') .. ' [Cash] $' .. total) end @@ -527,6 +530,24 @@ AddEventHandler('esx:useItem', function(itemName) end) +RegisterServerEvent('esx:onPickup') +AddEventHandler('esx:onPickup', function(id) + + local pickup = ESX.Pickups[id] + local xPlayer = ESX.GetPlayerFromId(source) + + if pickup.type == 'item_standard' then + xPlayer.addInventoryItem(pickup.name, pickup.count) + elseif pickup.type == 'item_money' then + xPlayer.addMoney(pickup.count) + elseif pickup.type == 'item_account' then + xPlayer.addAccountMoney(pickup.name, pickup.count) + end + + TriggerClientEvent('esx:removePickup', -1, id) + +end) + ESX.RegisterServerCallback('esx:getPlayerData', function(source, cb) local xPlayer = ESX.GetPlayerFromId(source)