From 2fd7d326be2d5070a1218bf29e87de28418bd034 Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Sun, 23 Dec 2018 14:32:38 +0100 Subject: [PATCH] 'Throwing' update, see desc, resolves #19 - proper i18n strings for dropping accounts, money, standard and weapons - check if the player has the weapon - workaround for duplicating weapon ammo when dropping weapon with 0 ammo - removed throw delay - code cleanup --- client/functions.lua | 2 +- client/main.lua | 16 +++--- config.lua | 2 - locales/br.lua | 8 ++- locales/cs.lua | 8 ++- locales/de.lua | 8 ++- locales/en.lua | 8 ++- locales/fi.lua | 8 ++- locales/fr.lua | 8 ++- locales/pl.lua | 8 ++- locales/sv.lua | 8 ++- server/main.lua | 134 +++++++++++++++++-------------------------- 12 files changed, 104 insertions(+), 114 deletions(-) diff --git a/client/functions.lua b/client/functions.lua index 2a3b6ac1..90ff3125 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -1216,7 +1216,7 @@ ESX.ShowInventory = function() if type == 'item_weapon' then - TriggerServerEvent('esx:removeInventoryItem', type, item, nil) + TriggerServerEvent('esx:removeInventoryItem', type, item) menu1.close() else -- type: item_standard diff --git a/client/main.lua b/client/main.lua index bc0f6ad3..5fab7cc2 100644 --- a/client/main.lua +++ b/client/main.lua @@ -328,10 +328,12 @@ AddEventHandler('esx:removePickup', function(id) end) RegisterNetEvent('esx:pickupWeapon') -AddEventHandler('esx:pickupWeapon', function(weaponPickup, weaponName,ammo) - local ped = PlayerPedId() - local playerPedPos = GetEntityCoords(ped, true) - CreateAmbientPickup(GetHashKey(weaponPickup), playerPedPos.x + 2.0, playerPedPos.y, playerPedPos.z + 0.5, 0, ammo, 1, false, true) +AddEventHandler('esx:pickupWeapon', function(weaponPickup, weaponName, ammo) + local playerPed = PlayerPedId() + local pickupCoords = GetOffsetFromEntityInWorldCoords(playerPed, 2.0, 0.0, 0.5) + local weaponHash = GetHashKey(weaponPickup) + + CreateAmbientPickup(weaponHash, pickupCoords, 0, ammo, 1, false, true) end) RegisterNetEvent('esx:spawnPed') @@ -358,7 +360,7 @@ AddEventHandler('esx:deleteVehicle', function() local playerPed = PlayerPedId() local vehicle = ESX.Game.GetVehicleInDirection() - if IsPedInAnyVehicle(playerPed, false) then + if IsPedInAnyVehicle(playerPed, true) then vehicle = GetVehiclePedIsIn(playerPed, false) end @@ -503,7 +505,7 @@ Citizen.CreateThread(function() 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) + local distance = GetDistanceBetweenCoords(coords, v.coords.x, v.coords.y, v.coords.z, true) local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() if distance <= 5.0 then @@ -516,7 +518,7 @@ Citizen.CreateThread(function() if (closestDistance == -1 or closestDistance > 3) and distance <= 1.0 and not v.inRange and not IsPedSittingInAnyVehicle(playerPed) then TriggerServerEvent('esx:onPickup', v.id) - PlaySoundFrontend(-1, "PICK_UP", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1) + PlaySoundFrontend(-1, 'PICK_UP', 'HUD_FRONTEND_DEFAULT_SOUNDSET', false) v.inRange = true end diff --git a/config.lua b/config.lua index 149784b4..2efac3de 100644 --- a/config.lua +++ b/config.lua @@ -7,10 +7,8 @@ Config.AccountLabels = { bank = _U('bank'), black_money = _U('black_m Config.EnableSocietyPayouts = false -- pay from the society account that the player is employed at? Requirement: esx_society Config.ShowDotAbovePlayer = false Config.DisableWantedLevel = true -Config.EnableWeaponPickup = true Config.EnableHud = true -- enable the default hud? Display current job and accounts (black, bank & cash) -Config.RemoveInventoryItemDelay = 5 * 60000 Config.PaycheckInterval = 7 * 60000 Config.MaxPlayers = 32 diff --git a/locales/br.lua b/locales/br.lua index b4958196..c5328418 100644 --- a/locales/br.lua +++ b/locales/br.lua @@ -30,9 +30,11 @@ Locales['br'] = { ['ex_inv_lim'] = 'acao nao e possivel, excedendo o limite de estoque para ~y~%s~s~', ['imp_invalid_quantity'] = 'acao impossivel, quantidade invalida', ['imp_invalid_amount'] = 'acao impossivel, valor invalido', - ['delete_five_min'] = '~r~excluir~s~ em 5 minutos', - ['threw'] = 'voce ~r~jogou~s~', - ['threw_weapon'] = 'voce ~r~atirou~s~ ~y~1x~s~ ~b~%s~s~ com ~o~%sx~s~ balas!', + ['threw_standard'] = 'you threw ~y~%sx~s~ ~b~%s~s~', + ['threw_money'] = 'you threw ~r~$%s~s~ ~b~cash~s~', + ['threw_account'] = 'you threw ~r~$%s~s~ ~b~%s~s~', + ['threw_weapon'] = 'you threw ~y~1x~s~ ~b~%s~s~', + ['threw_weapon_ammo'] = 'you threw ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets', -- Salary related ['received_salary'] = 'voce recebeu seu salario: ~g~$%s~s~ ', ['received_help'] = 'voce recebeu seu cheque de bem-estar: ~g~$%s~s~ ', diff --git a/locales/cs.lua b/locales/cs.lua index 98b34f8d..69a04afb 100644 --- a/locales/cs.lua +++ b/locales/cs.lua @@ -30,9 +30,11 @@ Locales['cs'] = { ['ex_inv_lim'] = 'akce není možná, překročen limit inventáře pro ~y~%s~s~', ['imp_invalid_quantity'] = 'akce není možná, neplatný počet', ['imp_invalid_amount'] = 'akce není možná, neplatné množství', - ['delete_five_min'] = 'věc bude ~r~zahozena~s~ za 5 minut', - ['threw'] = '~r~zahodili~s~ jste', - ['threw_weapon'] = '~r~zahodili~s~ jste ~y~1x~s~ ~b~%s~s~ s ~o~%sx~s~ náboji!', + ['threw_standard'] = 'you threw ~y~%sx~s~ ~b~%s~s~', + ['threw_money'] = 'you threw ~r~$%s~s~ ~b~cash~s~', + ['threw_account'] = 'you threw ~r~$%s~s~ ~b~%s~s~', + ['threw_weapon'] = 'you threw ~y~1x~s~ ~b~%s~s~', + ['threw_weapon_ammo'] = 'you threw ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets', -- Salary related ['received_salary'] = 'obdrželi jste výplatu: ~g~$%s~s~', ['received_help'] = 'obdrželi jste sociální dávku: ~g~$%s~s~', diff --git a/locales/de.lua b/locales/de.lua index d1c4f072..3af360a2 100644 --- a/locales/de.lua +++ b/locales/de.lua @@ -30,9 +30,11 @@ Locales['de'] = { ['ex_inv_lim'] = 'aktion nicht möglich, Inventarlimit überschritten für ~y~%s~s~', ['imp_invalid_quantity'] = 'aktion nicht möglich, ungültige Anzahl', ['imp_invalid_amount'] = 'aktion nicht möglich, ungültiger Betrag', - ['delete_five_min'] = 'item wird in ~y~fünf Minuten~s~ ~r~gelöscht~s~', - ['threw'] = 'du ~r~wirfst weg~s~', - ['threw_weapon'] = 'du hast ~y~1x~s~ ~b~%s~s~ mit ~o~%sx~s~ Schuss ~r~fallengelassen~s~!', + ['threw_standard'] = 'you threw ~y~%sx~s~ ~b~%s~s~', + ['threw_money'] = 'you threw ~r~$%s~s~ ~b~cash~s~', + ['threw_account'] = 'you threw ~r~$%s~s~ ~b~%s~s~', + ['threw_weapon'] = 'you threw ~y~1x~s~ ~b~%s~s~', + ['threw_weapon_ammo'] = 'you threw ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets', -- Salary related ['received_salary'] = 'du hast dein Gehalt erhalten: ~g~$%s~s~', ['received_help'] = 'du hast deine Sozialhilfe erhalten.: ~g~$%s~s~', diff --git a/locales/en.lua b/locales/en.lua index 7819c5cb..6fa0dd63 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -30,9 +30,11 @@ Locales['en'] = { ['ex_inv_lim'] = 'action not possible, exceeding inventory limit for ~y~%s~s~', ['imp_invalid_quantity'] = 'action impossible, invalid quantity', ['imp_invalid_amount'] = 'action impossible, invalid amount', - ['delete_five_min'] = 'the item will be ~r~thrown~s~ in 5 minutes', - ['threw'] = 'you ~r~threw~s~', - ['threw_weapon'] = 'you ~r~threw~s~ ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets!', + ['threw_standard'] = 'you threw ~y~%sx~s~ ~b~%s~s~', + ['threw_money'] = 'you threw ~r~$%s~s~ ~b~cash~s~', + ['threw_account'] = 'you threw ~r~$%s~s~ ~b~%s~s~', + ['threw_weapon'] = 'you threw ~y~1x~s~ ~b~%s~s~', + ['threw_weapon_ammo'] = 'you threw ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets', -- Salary related ['received_salary'] = 'you received your salary: ~g~$%s~s~', ['received_help'] = 'you recieved your welfare check: ~g~$%s~s~', diff --git a/locales/fi.lua b/locales/fi.lua index 39b7c8e9..f53df544 100644 --- a/locales/fi.lua +++ b/locales/fi.lua @@ -30,9 +30,11 @@ Locales['fi'] = { ['ex_inv_lim'] = 'toiminto mahdoton, reppu alkaa olla täysi ~y~%s~s~', ['imp_invalid_quantity'] = 'toiminto mahdoton, virheellinen määrä', ['imp_invalid_amount'] = 'toiminto mahdoton, virhellinen summa', - ['delete_five_min'] = 'esine ~r~poistetaan~s~ 5 minuutin päästä repusta', - ['threw'] = 'sinä ~r~tiputit~s~', - ['threw_weapon'] = 'sinä ~r~heitit~s~ ~y~1x~s~ ~b~%s~s~ jossa oli ~o~%sx~s~ ammuksia!', + ['threw_standard'] = 'you threw ~y~%sx~s~ ~b~%s~s~', + ['threw_money'] = 'you threw ~r~$%s~s~ ~b~cash~s~', + ['threw_account'] = 'you threw ~r~$%s~s~ ~b~%s~s~', + ['threw_weapon'] = 'you threw ~y~1x~s~ ~b~%s~s~', + ['threw_weapon_ammo'] = 'you threw ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets', -- Salary related ['received_salary'] = 'sinä vastaanotit palkkaa: ~g~$%s~s~', ['received_help'] = 'sinä vastaanotit valtion tukea: ~g~$%s~s~', diff --git a/locales/fr.lua b/locales/fr.lua index fc676c62..f46482a4 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -30,9 +30,11 @@ Locales['fr'] = { ['ex_inv_lim'] = 'action impossible, depassement de la limite d\'inventaire pour ~y~%s~s~', ['imp_invalid_quantity'] = 'action impossible, ~r~quantité invalide', ['imp_invalid_amount'] = 'action impossible, ~r~montant invalide', - ['delete_five_min'] = '~r~suppression~s~ dans 5 minutes', - ['threw'] = 'vous avez ~r~jeté~s~', - ['threw_weapon'] = 'vous ~r~jetez~s~ ~y~1x~s~ ~b~%s~s~ avec ~o~%sx~s~ munitions!', + ['threw_standard'] = 'you threw ~y~%sx~s~ ~b~%s~s~', + ['threw_money'] = 'you threw ~r~$%s~s~ ~b~cash~s~', + ['threw_account'] = 'you threw ~r~$%s~s~ ~b~%s~s~', + ['threw_weapon'] = 'you threw ~y~1x~s~ ~b~%s~s~', + ['threw_weapon_ammo'] = 'you threw ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets', -- Salary related ['received_salary'] = 'vous avez reçu votre salaire: ~g~$%s~s~', ['received_help'] = 'vous avez reçu une aide de l\'état: ~g~$%s~s~', diff --git a/locales/pl.lua b/locales/pl.lua index 3dc704cb..8c754742 100644 --- a/locales/pl.lua +++ b/locales/pl.lua @@ -30,9 +30,11 @@ Locales['pl'] = { ['ex_inv_lim'] = 'akcja nie jest możliwa, nie możesz mieć więcej ~y~%s~s~', ['imp_invalid_quantity'] = 'akcja jest niemożliwa, nieprawidłowa ilość', ['imp_invalid_amount'] = 'akcja jest niemożliwa, nieprawidłowa kwota', - ['delete_five_min'] = 'przedmiot zostanie ~r~usunięty~s~ za 5 minut', - ['threw'] = '~r~upuściłeś~s~', - ['threw_weapon'] = '~r~Upuściłeś~s~ ~y~1x~s~ ~b~%s~s~ z ~o~%sx~s~ pociskami!', + ['threw_standard'] = 'you threw ~y~%sx~s~ ~b~%s~s~', + ['threw_money'] = 'you threw ~r~$%s~s~ ~b~cash~s~', + ['threw_account'] = 'you threw ~r~$%s~s~ ~b~%s~s~', + ['threw_weapon'] = 'you threw ~y~1x~s~ ~b~%s~s~', + ['threw_weapon_ammo'] = 'you threw ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets', -- Salary related ['received_salary'] = 'otrzymałeś wynagrodzenie: ~g~%s$~s~', ['received_help'] = 'otrzymałem zapomogę: ~g~$%s~s~', diff --git a/locales/sv.lua b/locales/sv.lua index 2d3453be..ad2236ca 100644 --- a/locales/sv.lua +++ b/locales/sv.lua @@ -30,9 +30,11 @@ Locales['sv'] = { ['ex_inv_lim'] = 'åtgärd inte möjligt, översteg förråd gräns för ~y~%s~s~', ['imp_invalid_quantity'] = 'åtgärd omöjlig, ogiltig mängd', ['imp_invalid_amount'] = 'åtgärd omöjlig, ogiltig belopp', - ['delete_five_min'] = 'objektet kommer att ~r~kastas~s~ om 5 minuter!', - ['threw'] = 'du ~r~kastade~s~', - ['threw_weapon'] = 'du ~r~slängde~s~ ~y~1x~s~ ~b~%s~s~ med ~o~%sx~s~ skott!', + ['threw_standard'] = 'du kastade ~y~%sx~s~ ~b~%s~s~', + ['threw_money'] = 'du kastade ~r~$%s~s~ ~b~kontanter~s~', + ['threw_account'] = 'du kastade ~r~$%s~s~ ~b~%s~s~', + ['threw_weapon'] = 'du kastade ~y~1x~s~ ~b~%s~s~', + ['threw_weapon_ammo'] = 'du kastade ~y~1x~s~ ~b~%s~s~ med ~o~%sx~s~ skott', -- Salary related ['received_salary'] = 'du har mottagit din lön på ~g~%s SEK~s~', ['received_help'] = 'du har mottagit bidrag på ~g~%s SEK~s~', diff --git a/server/main.lua b/server/main.lua index bdc81691..cb7dfa8f 100644 --- a/server/main.lua +++ b/server/main.lua @@ -348,125 +348,97 @@ AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount) if type == 'item_standard' then - if itemCount == nil or itemCount <= 0 then + if itemCount == nil or itemCount < 1 then TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_quantity')) else - local xPlayer = ESX.GetPlayerFromId(source) - local foundItem = nil + local xPlayer = ESX.GetPlayerFromId(source) + local xItem = xPlayer.getInventoryItem(itemName) - for i=1, #xPlayer.inventory, 1 do - if xPlayer.inventory[i].name == itemName then - foundItem = xPlayer.inventory[i] - break - end - end - - if itemCount > foundItem.count then + if (itemCount > xItem.count or xItem.count < 1) then TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_quantity')) else + xPlayer.removeInventoryItem(itemName, itemCount) - TriggerClientEvent('esx:showNotification', _source, _U('delete_five_min')) - - SetTimeout(Config.RemoveInventoryItemDelay, function() - local remainingCount = xPlayer.getInventoryItem(itemName).count - local total = itemCount - - if remainingCount < itemCount then - total = remainingCount - end - - if total > 0 then - xPlayer.removeInventoryItem(itemName, total) - ESX.CreatePickup('item_standard', itemName, total, foundItem.label .. ' [' .. itemCount .. ']', _source) - TriggerClientEvent('esx:showNotification', _source, _U('threw') .. ' ' .. foundItem.label .. ' x' .. total) - end - end) + 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)) end end elseif type == 'item_money' then - if itemCount == nil or itemCount <= 0 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 > xPlayer.player.get('money') then + if (itemCount > playerCash or playerCash < 1) then TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount')) else + xPlayer.removeMoney(itemCount) - TriggerClientEvent('esx:showNotification', _source, _U('delete_five_min')) - - SetTimeout(Config.RemoveInventoryItemDelay, function() - local remainingCount = xPlayer.player.get('money') - local total = itemCount - - if remainingCount < itemCount then - total = remainingCount - end - - if total > 0 then - xPlayer.removeMoney(total) - ESX.CreatePickup('item_money', 'money', total, 'Cash' .. ' [' .. itemCount .. ']', _source) - TriggerClientEvent('esx:showNotification', _source, _U('threw') .. ' [Cash] $' .. total) - end - end) + 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))) end end elseif type == 'item_account' then - if itemCount == nil or itemCount <= 0 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 > xPlayer.getAccount(itemName).money then + if (itemCount > account.money or account.money < 1) then TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount')) else + xPlayer.removeAccountMoney(itemName, itemCount) - TriggerClientEvent('esx:showNotification', _source, _U('delete_five_min')) - - SetTimeout(Config.RemoveInventoryItemDelay, function() - local remainingCount = xPlayer.getAccount(itemName).money - local total = itemCount - - if remainingCount < itemCount then - total = remainingCount - end - - if total > 0 then - xPlayer.removeAccountMoney(itemName, total) - ESX.CreatePickup('item_account', itemName, total, Config.AccountLabels[itemName] .. ' [' .. itemCount .. ']', _source) - TriggerClientEvent('esx:showNotification', _source, _U('threw') .. ' [Cash] $' .. total) - end - end) + 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 weaponName = itemName - local weaponLabel = ESX.GetWeaponLabel(weaponName) - local weaponPickup = 'PICKUP_' .. weaponName - - TriggerClientEvent('esx:showNotification', _source, _U('delete_five_min')) - - SetTimeout(Config.RemoveInventoryItemDelay, function() - xPlayer.removeWeapon(itemName) - if Config.EnableWeaponPickup then - TriggerClientEvent('esx:pickupWeapon', _source, weaponPickup, weaponName, itemCount) - end + 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 + + -- workaround for CreateAmbientPickup() giving 30 rounds of ammo when you drop the weapon with 0 ammo + if itemCount == 0 then + itemCount = 1 + end + + if xPlayer.hasWeapon(itemName) then + local weaponLabel, weaponPickup = ESX.GetWeaponLabel(itemName), 'PICKUP_' .. string.upper(itemName) + + xPlayer.removeWeapon(itemName) + TriggerClientEvent('esx:pickupWeapon', _source, weaponPickup, itemName, itemCount) + + if itemCount > 0 then + TriggerClientEvent('esx:showNotification', _source, _U('threw_weapon_ammo', weaponLabel, itemCount)) + else + TriggerClientEvent('esx:showNotification', _source, _U('threw_weapon', weaponLabel)) + end + end - TriggerClientEvent('esx:showNotification', _source, _U('threw_weapon', weaponLabel, itemCount)) - end) end end) @@ -504,7 +476,9 @@ AddEventHandler('esx:onPickup', function(id) if remaining > 0 then TriggerClientEvent('esx:showNotification', _source, _U('cannot_pickup_room', item.label)) - ESX.CreatePickup('item_standard', pickup.name, remaining, item.label .. ' [' .. remaining .. ']', _source) + + 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 @@ -526,7 +500,7 @@ ESX.RegisterServerCallback('esx:getPlayerData', function(source, cb) job = xPlayer.getJob(), loadout = xPlayer.getLoadout(), lastPosition = xPlayer.getLastPosition(), - money = xPlayer.get('money') + money = xPlayer.getMoney() }) end) @@ -540,7 +514,7 @@ ESX.RegisterServerCallback('esx:getOtherPlayerData', function(source, cb, target job = xPlayer.getJob(), loadout = xPlayer.getLoadout(), lastPosition = xPlayer.getLastPosition(), - money = xPlayer.get('money') + money = xPlayer.getMoney() }) end)