mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 17:28:53 +00:00
Add object pickups when dropping + add /spawnobject admin command
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
@@ -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',
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -4,6 +4,8 @@ ESX.UsableItemsCallbacks = {}
|
||||
ESX.Items = {}
|
||||
ESX.ServerCallbacks = {}
|
||||
ESX.LastPlayerData = {}
|
||||
ESX.Pickups = {}
|
||||
ESX.PickupId = 0
|
||||
|
||||
AddEventHandler('esx:getSharedObject', function(cb)
|
||||
cb(ESX)
|
||||
|
||||
@@ -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
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user