From 8586fdcce24eb98ba06cab046424382483236fe0 Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Wed, 18 Sep 2019 13:47:41 +0200 Subject: [PATCH] Fix thrown items not synced with mid-joined players --- client/main.lua | 18 ++++++++++++++++++ server/functions.lua | 9 ++++++--- server/main.lua | 1 + 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/client/main.lua b/client/main.lua index 722d4041..b71d5cf1 100644 --- a/client/main.lua +++ b/client/main.lua @@ -40,6 +40,24 @@ AddEventHandler('esx:playerLoaded', function(xPlayer) end end) +RegisterNetEvent('esx:createMissingPickups') +AddEventHandler('esx:createMissingPickups', function(pickups) + for pickupId,v in pairs(pickups) do + ESX.Game.SpawnLocalObject('prop_money_bag_01', v.coords, function(obj) + SetEntityAsMissionEntity(obj, true, false) + PlaceObjectOnGroundProperly(obj) + + Pickups[pickupId] = { + id = pickupId, + obj = obj, + label = v.label, + inRange = false, + coords = v.coords + } + end) + end +end) + AddEventHandler('playerSpawned', function() while not ESX.PlayerLoaded do Citizen.Wait(1) diff --git a/server/functions.lua b/server/functions.lua index 351c0511..3ab80291 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -162,16 +162,19 @@ ESX.GetItemLabel = function(item) end end -ESX.CreatePickup = function(type, name, count, label, player) +ESX.CreatePickup = function(type, name, count, label, playerId) local pickupId = (ESX.PickupId == 65635 and 0 or ESX.PickupId + 1) + local xPlayer = ESX.GetPlayerFromId(playerId) ESX.Pickups[pickupId] = { type = type, name = name, - count = count + count = count, + label = label, + coords = xPlayer.getCoords() } - TriggerClientEvent('esx:pickup', -1, pickupId, label, player) + TriggerClientEvent('esx:pickup', -1, pickupId, label, playerId) ESX.PickupId = pickupId end diff --git a/server/main.lua b/server/main.lua index 57e4b615..86d7f2f4 100644 --- a/server/main.lua +++ b/server/main.lua @@ -234,6 +234,7 @@ AddEventHandler('es:playerLoaded', function(source, _player) }) xPlayer.displayMoney(xPlayer.getMoney()) + TriggerClientEvent('esx:createMissingPickups', _source, ESX.Pickups) end) end)