Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RegisterServerEvent('esx:giveInventoryItem')
- AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCount)
- local _source = source
- local sourceXPlayer = ESX.GetPlayerFromId(_source)
- local targetXPlayer = ESX.GetPlayerFromId(target)
- if type == 'item_standard' then
- local sourceItem = sourceXPlayer.getInventoryItem(itemName)
- local targetItem = targetXPlayer.getInventoryItem(itemName)
- if itemCount > 0 and sourceItem.count >= itemCount then
- if targetItem.limit ~= -1 and (targetItem.count + itemCount) > targetItem.limit then
- TriggerClientEvent('esx:showNotification', _source, _U('ex_inv_lim', targetXPlayer.name))
- else
- sourceXPlayer.removeInventoryItem(itemName, itemCount)
- targetXPlayer.addInventoryItem (itemName, itemCount)
- TriggerClientEvent('esx:showNotification', _source, _U('gave_item', itemCount, ESX.Items[itemName].label, targetXPlayer.name))
- TriggerClientEvent('esx:showNotification', target, _U('received_item', itemCount, ESX.Items[itemName].label, sourceXPlayer.name))
- TriggerEvent("esx:giveitemalert",sourceXPlayer.name,targetXPlayer.name,ESX.Items[itemName].label,itemCount)
- end
- else
- TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_quantity'))
- end
- elseif type == 'item_money' then
- if itemCount > 0 and sourceXPlayer.getMoney() >= itemCount then
- sourceXPlayer.removeMoney(itemCount)
- targetXPlayer.addMoney (itemCount)
- TriggerClientEvent('esx:showNotification', _source, _U('gave_money', ESX.Math.GroupDigits(itemCount), targetXPlayer.name))
- TriggerClientEvent('esx:showNotification', target, _U('received_money', ESX.Math.GroupDigits(itemCount), sourceXPlayer.name))
- TriggerEvent("esx:givemoneyalert",sourceXPlayer.name,targetXPlayer.name,itemCount)
- else
- TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
- end
- elseif type == 'item_account' then
- if itemCount > 0 and sourceXPlayer.getAccount(itemName).money >= itemCount then
- sourceXPlayer.removeAccountMoney(itemName, itemCount)
- targetXPlayer.addAccountMoney (itemName, itemCount)
- TriggerClientEvent('esx:showNotification', _source, _U('gave_account_money', ESX.Math.GroupDigits(itemCount), Config.AccountLabels[itemName], targetXPlayer.name))
- TriggerClientEvent('esx:showNotification', target, _U('received_account_money', ESX.Math.GroupDigits(itemCount), Config.AccountLabels[itemName], sourceXPlayer.name))
- TriggerEvent("esx:givemoneybankalert",sourceXPlayer.name,targetXPlayer.name,itemCount)
- else
- TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
- end
- elseif type == 'item_weapon' then
- if not targetXPlayer.hasWeapon(itemName) then
- sourceXPlayer.removeWeapon(itemName)
- targetXPlayer.addWeapon(itemName, itemCount)
- local weaponLabel = ESX.GetWeaponLabel(itemName)
- if itemCount > 0 then
- TriggerClientEvent('esx:showNotification', _source, _U('gave_weapon_ammo', weaponLabel, itemCount, targetXPlayer.name))
- TriggerClientEvent('esx:showNotification', target, _U('received_weapon_ammo', weaponLabel, itemCount, sourceXPlayer.name))
- TriggerEvent("esx:giveweaponalert",sourceXPlayer.name,targetXPlayer.name,weaponLabel)
- else
- TriggerClientEvent('esx:showNotification', _source, _U('gave_weapon', weaponLabel, targetXPlayer.name))
- TriggerClientEvent('esx:showNotification', target, _U('received_weapon', weaponLabel, sourceXPlayer.name))
- TriggerEvent("esx:giveweaponalert",sourceXPlayer.name,targetXPlayer.name,weaponLabel)
- end
- else
- TriggerClientEvent('esx:showNotification', _source, _U('gave_weapon_hasalready', targetXPlayer.name, weaponLabel))
- TriggerClientEvent('esx:showNotification', _source, _U('received_weapon_hasalready', sourceXPlayer.name, weaponLabel))
- end
- end
- end)
- RegisterServerEvent('esx:removeInventoryItem')
- AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount)
- local _source = source
- local sourceXPlayer = ESX.GetPlayerFromId(_source)
- if type == 'item_standard' then
- if itemCount == nil or itemCount < 1 then
- TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_quantity'))
- else
- local xPlayer = ESX.GetPlayerFromId(source)
- local xItem = xPlayer.getInventoryItem(itemName)
- if (itemCount > xItem.count or xItem.count < 1) then
- TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_quantity'))
- else
- xPlayer.removeInventoryItem(itemName, itemCount)
- local pickupLabel = ('~y~%s~s~ [~b~%s~s~]'):format(xItem.label, itemCount)
- ESX.CreatePickup('item_standard', itemName, itemCount, pickupLabel, _source)
- TriggerClientEvent('esx:showNotification', _source, _U('threw_standard', itemCount, xItem.label))
- TriggerEvent("esx:removeitemalert",sourceXPlayer.name,ESX.Items[itemName].label,itemCount)
- end
- end
- elseif type == 'item_money' then
- if itemCount == nil or itemCount < 1 then
- TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
- else
- local xPlayer = ESX.GetPlayerFromId(source)
- local playerCash = xPlayer.getMoney()
- if (itemCount > playerCash or playerCash < 1) then
- TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
- else
- xPlayer.removeMoney(itemCount)
- local pickupLabel = ('~y~%s~s~ [~g~%s~s~]'):format(_U('cash'), _U('locale_currency', ESX.Math.GroupDigits(itemCount)))
- ESX.CreatePickup('item_money', 'money', itemCount, pickupLabel, _source)
- TriggerClientEvent('esx:showNotification', _source, _U('threw_money', ESX.Math.GroupDigits(itemCount)))
- TriggerEvent("esx:removemoneyalert",sourceXPlayer.name,itemCount)
- end
- end
- elseif type == 'item_account' then
- if itemCount == nil or itemCount < 1 then
- TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
- else
- local xPlayer = ESX.GetPlayerFromId(source)
- local account = xPlayer.getAccount(itemName)
- if (itemCount > account.money or account.money < 1) then
- TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount'))
- else
- xPlayer.removeAccountMoney(itemName, itemCount)
- local pickupLabel = ('~y~%s~s~ [~g~%s~s~]'):format(account.label, _U('locale_currency', ESX.Math.GroupDigits(itemCount)))
- ESX.CreatePickup('item_account', itemName, itemCount, pickupLabel, _source)
- TriggerClientEvent('esx:showNotification', _source, _U('threw_account', ESX.Math.GroupDigits(itemCount), string.lower(account.label)))
- end
- end
- elseif type == 'item_weapon' then
- local xPlayer = ESX.GetPlayerFromId(source)
- local loadout = xPlayer.getLoadout()
- for i=1, #loadout, 1 do
- if loadout[i].name == itemName then
- itemCount = loadout[i].ammo
- break
- end
- end
- if xPlayer.hasWeapon(itemName) then
- local weaponLabel, weaponPickup = ESX.GetWeaponLabel(itemName), 'PICKUP_' .. string.upper(itemName)
- xPlayer.removeWeapon(itemName)
- if itemCount > 0 then
- TriggerClientEvent('esx:pickupWeapon', _source, weaponPickup, itemName, itemCount)
- TriggerClientEvent('esx:showNotification', _source, _U('threw_weapon_ammo', weaponLabel, itemCount))
- TriggerEvent("esx:removeweaponalert",sourceXPlayer.name,weaponLabel)
- else
- -- workaround for CreateAmbientPickup() giving 30 rounds of ammo when you drop the weapon with 0 ammo
- TriggerClientEvent('esx:pickupWeapon', _source, weaponPickup, itemName, 1)
- TriggerClientEvent('esx:showNotification', _source, _U('threw_weapon', weaponLabel))
- TriggerEvent("esx:removeweaponalert",sourceXPlayer.name,weaponLabel)
- end
- end
- end
- end)
- RegisterServerEvent('esx:useItem')
- AddEventHandler('esx:useItem', function(itemName)
- local xPlayer = ESX.GetPlayerFromId(source)
- local count = xPlayer.getInventoryItem(itemName).count
- if count > 0 then
- ESX.UseItem(source, itemName)
- else
- TriggerClientEvent('esx:showNotification', xPlayer.source, _U('act_imp'))
- end
- end)
- RegisterServerEvent('esx:onPickup')
- AddEventHandler('esx:onPickup', function(id)
- local _source = source
- local pickup = ESX.Pickups[id]
- local xPlayer = ESX.GetPlayerFromId(_source)
- local sourceXPlayer = ESX.GetPlayerFromId(_source)
- if pickup.type == 'item_standard' then
- local item = xPlayer.getInventoryItem(pickup.name)
- local canTake = ((item.limit == -1) and (pickup.count)) or ((item.limit - item.count > 0) and (item.limit - item.count)) or 0
- local total = pickup.count < canTake and pickup.count or canTake
- local remaining = pickup.count - total
- TriggerClientEvent('esx:removePickup', -1, id)
- if total > 0 then
- xPlayer.addInventoryItem(pickup.name, total)
- TriggerEvent("esx:pickupitemalert",sourceXPlayer.name,pickup.name,total)
- end
- if remaining > 0 then
- TriggerClientEvent('esx:showNotification', _source, _U('cannot_pickup_room', item.label))
- local pickupLabel = ('~y~%s~s~ [~b~%s~s~]'):format(item.label, remaining)
- ESX.CreatePickup('item_standard', pickup.name, remaining, pickupLabel, _source)
- end
- elseif pickup.type == 'item_money' then
- TriggerClientEvent('esx:removePickup', -1, id)
- xPlayer.addMoney(pickup.count)
- TriggerEvent("esx:pickupmoneyalert",sourceXPlayer.name,pickup.count)
- elseif pickup.type == 'item_account' then
- TriggerClientEvent('esx:removePickup', -1, id)
- xPlayer.addAccountMoney(pickup.name, pickup.count)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement