I’m not a developer nor do I claim to be one, but I have a few ideas and do this for a hobby and my own entertainment in ESX
This idea is to add a bit more reality by adding bag props onto players if items exceed a certain amount. And for those groups moving items from player to player while being searched by police to move the bag along with the items.
I can add props to players but,
My question is how do I not add the prop if it already exist, and remove it if the count is below config specified. Maybe one of you clever guys can give me a better way of doing it or help with the idea.
I won’t be surprised if I’m doing this completely wrong.
Below is my sample idea: Resolved, but I bet there is a better way to do it.
ESX = nil
Config = {}
Config.BigBucks = 10000
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local headingvector = GetEntityForwardVector(PlayerPedId())
local x, y, z = table.unpack(playerCoords + headingvector * - 2.0)
local coords2 = {
x = x,
y = y,
z = z - 1
}
Citizen.CreateThread(function()
while true do
--check cash
ESX.TriggerServerCallback('esx:getPlayerData', function(data)
local bag = GetClosestObjectOfType(playerCoords, 1.5, GetHashKey('bkr_prop_duffel_bag_01a'), false, false, false)
local money = data.money
if money >= Config.BigBucks and not DoesEntityExist(bag) then
PutCase()
ESX.ShowNotification('You will need a ~b~bag~s~ for that amount of ~b~cash~s~ you carry!')
elseif money < Config.BigBucks and DoesEntityExist(bag) then
DeleteObject(bag)
ESX.Game.SpawnObject('bkr_prop_duffel_bag_01a', coords2, function(usedbag)
FreezeEntityPosition(usedbag, false)
Citizen.Wait(5000)
DeleteObject(usedbag)
end)
end
end)
Citizen.Wait(5000)
end
end)
function PutCase()
attachModel = GetHashKey('bkr_prop_duffel_bag_01a')
boneNumber = 61163
local bone = GetPedBoneIndex(GetPlayerPed(-1), boneNumber)
RequestModel(attachModel)
while not HasModelLoaded(attachModel) do
Citizen.Wait(100)
end
attachedProp = CreateObject(attachModel, 0.0, 0.0, 0.0, 90.0, 90.0, 0.0)
AttachEntityToEntity(attachedProp, GetPlayerPed(-1), bone, 0.60, -0.03, 0.05, 90.0, -180.0, 80.0, 1, 1, 0, 0, 2, 1)
SetEntityAsMissionEntity(object, true, false)
SetEntityCollision(attachedProp, false, true)
end