From 5f93c0a1290b60083d7624afe120fc555c12f9a4 Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Sun, 15 Apr 2018 22:52:03 +0200 Subject: [PATCH] Improved i18 formatting, see desc - /giveweapon now takes ammo as an argument - improved Swedish translation - hide actions in the inventory menu if they cannot be done. - general code improvements, cleanup --- client/functions.lua | 90 ++++++++++++++++++++++---------------------- locales/en.lua | 9 +++-- locales/sv.lua | 10 +++-- server/commands.lua | 4 +- server/main.lua | 15 ++++---- 5 files changed, 67 insertions(+), 61 deletions(-) diff --git a/client/functions.lua b/client/functions.lua index d6babc04..49ecb156 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -1118,6 +1118,7 @@ ESX.ShowInventory = function() count = 1, type = 'item_weapon', value = Config.Weapons[i].name, + ammo = ammo, usable = false, rare = false, canRemove = true @@ -1152,7 +1153,7 @@ ESX.ShowInventory = function() table.insert(elements, {label = _U('remove'), action = 'remove', type = data.current.type, value = data.current.value}) end - if data.current.type == "item_weapon" then + if data.current.type == "item_weapon" and data.current.ammo > 0 and player ~= -1 and distance <= 3.0 then table.insert(elements, {label = _U('giveammo'), action = 'giveammo', type = data.current.type, value = data.current.value}) end @@ -1176,10 +1177,10 @@ ESX.ShowInventory = function() if type == 'item_weapon' then local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() local closestPed = GetPlayerPed(closestPlayer) - local pedammo = GetAmmoInPedWeapon(GetPlayerPed(-1),GetHashKey(item)) + local pedAmmo = GetAmmoInPedWeapon(GetPlayerPed(-1),GetHashKey(item)) if not IsPedSittingInAnyVehicle(closestPed) then if closestPlayer ~= -1 and closestDistance < 3.0 then - if pedammo > 0 then + if pedAmmo > 0 then ESX.UI.Menu.Open( 'dialog', GetCurrentResourceName(), 'inventory_item_count_give', { @@ -1187,19 +1188,17 @@ ESX.ShowInventory = function() }, function(data2, menu2) local quantity = tonumber(data2.value) - if quantity <= pedammo and quantity >= 0 and quantity ~= nil then - local ammobefore = GetAmmoInPedWeapon(playerPed, item) + if quantity <= pedAmmo and quantity >= 0 and quantity ~= nil then TriggerServerEvent('esx:giveInventoryItem', GetPlayerServerId(closestPlayer), type, item, quantity) - local finalammo = math.floor(ammobefore - quantity) + local finalammo = math.floor(pedAmmo - quantity) SetPedAmmo(playerPed, item, finalammo) menu2.close() menu.close() else - ESX.ShowNotification(_U("noammo")) + ESX.ShowNotification(_U('noammo')) end - end, - function(data2, menu2) + end, function(data2, menu2) menu2.close() end ) @@ -1250,33 +1249,34 @@ ESX.ShowInventory = function() elseif data.current.action == 'remove' then if type == 'item_weapon' then - local pedammo = GetAmmoInPedWeapon(GetPlayerPed(-1),GetHashKey(item)) - ESX.UI.Menu.Open( - 'dialog', GetCurrentResourceName(), 'inventory_item_count_remove', - { - title = _U('amount') - }, - function(data2, menu2) + local pedAmmo = GetAmmoInPedWeapon(GetPlayerPed(-1),GetHashKey(item)) + + -- does the player have any ammo for the weapon? + if pedAmmo > 0 then + ESX.UI.Menu.Open( + 'dialog', GetCurrentResourceName(), 'inventory_item_count_remove', + { + title = _U('amount') + }, function(data2, menu2) + local quantity = tonumber(data2.value) - local quantity = tonumber(data2.value) - - if quantity <= pedammo and quantity >= 0 and quantity ~= nil then - local ammobefore = GetAmmoInPedWeapon(playerPed, item) - TriggerServerEvent('esx:removeInventoryItem', type, item, quantity) - local finalammo = math.floor(ammobefore - quantity) - SetPedAmmo(playerPed, item, finalammo) - else - ESX.ShowNotification(_U("noammo")) - end - - menu2.close() - menu.close() - - end, - function(data2, menu2) - menu2.close() - end - ) + if quantity <= pedAmmo and quantity >= 0 and quantity ~= nil then + local finalammo = math.floor(pedAmmo - quantity) + + SetPedAmmo(playerPed, item, finalammo) + TriggerServerEvent('esx:removeInventoryItem', type, item, quantity) + else + ESX.ShowNotification(_U('noammo')) + end + menu2.close() + menu.close() + end, function(data2, menu2) + menu2.close() + end) + else + TriggerServerEvent('esx:removeInventoryItem', type, item, 0) + menu.close() + end else @@ -1316,10 +1316,10 @@ ESX.ShowInventory = function() elseif data.current.action == 'giveammo' then local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() local closestPed = GetPlayerPed(closestPlayer) - local pedammo = GetAmmoInPedWeapon(playerPed,GetHashKey(item)) + local pedAmmo = GetAmmoInPedWeapon(playerPed,GetHashKey(item)) if not IsPedSittingInAnyVehicle(closestPed) then if closestPlayer ~= -1 and closestDistance < 3.0 then - if pedammo > 0 then + if pedAmmo > 0 then ESX.UI.Menu.Open( 'dialog', GetCurrentResourceName(), 'inventory_item_count_give', { @@ -1327,18 +1327,16 @@ ESX.ShowInventory = function() }, function(data2, menu2) local quantity = tonumber(data2.value) - if quantity <= pedammo and quantity >= 0 and quantity ~= nil then - local ammobefore2 = GetAmmoInPedWeapon(closestPed, item) - local finalammo = math.floor(pedammo - quantity) - local finalammo2 = math.floor(ammobefore2 + quantity) - SetPedAmmo(playerPed, item, finalammo) - Citizen.invokeNative(0x78F0424C34306220,closestPed, item, finalammo2) - --SetPedAmmo(closestPed, item, finalammo2) - ESX.ShowNotification(_U('yougave') .. "x~r~ " .. quantity .. _U('ammogiven') ) + if quantity <= pedAmmo and quantity >= 0 and quantity ~= nil then + local finalAmmoSource = math.floor(pedAmmo - quantity) + SetPedAmmo(playerPed, item, finalAmmoSource) + AddAmmoToPed(closestPed, item, quantity) + ESX.ShowNotification(_U('gave_ammo', quantity)) + -- todo notify target that he recived ammo menu2.close() menu.close() else - ESX.ShowNotification(_U("noammo")) + ESX.ShowNotification(_U('noammo')) end end, diff --git a/locales/en.lua b/locales/en.lua index b84aed7a..c02bba66 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -7,8 +7,11 @@ Locales['en'] = { ['amount'] = 'amount', ['amountammo'] = 'amount of ammo', ['noammo'] = 'you do not have enough ammo!', - ['withammo'] = '~s~ with x', - ['ammogiven'] = '~s~ bullets', + ['threw_weapon'] = 'you ~r~threw~s~ ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets!', + ['gave_weapon'] = 'you gave ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets to ~y~%s~s~.', + ['recived_weapon'] = 'you recived ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets from ~b~%s~s~.', + ['gave_ammo'] = 'you gave ~o~%sx~s~ bullets to ~y~%s~s~.', + ['recived_ammo'] = 'you recived ~o~%sx~s~ bullets from ~b~%s~s~.', ['giveammo'] = 'Give ammo', ['amount_invalid'] = 'invalid amount', ['players_nearby'] = 'no players nearby', @@ -19,7 +22,7 @@ Locales['en'] = { ['by'] = '~s~ by ~b~', ['imp_invalid_quantity'] = 'action impossible, invalid quantity', ['imp_invalid_amount'] = 'action impossible, invalid amount', - ['delete_five_min'] = 'the item will be ~r~deleted~s~ in 5 minutes', + ['delete_five_min'] = 'the item will be ~r~thrown~s~ in 5 minutes', ['threw'] = 'you ~r~threw~s~', ['rec_salary'] = 'you received your salary: ', ['rec_help'] = 'you recieved your welfare check: ', diff --git a/locales/sv.lua b/locales/sv.lua index 5e00ac11..00044a41 100644 --- a/locales/sv.lua +++ b/locales/sv.lua @@ -7,8 +7,11 @@ Locales['sv'] = { ['amount'] = 'antal', ['amountammo'] = 'mängd ammunition', ['noammo'] = 'du har inte tillräckligt med ammunition!', - ['withammo'] = '~s~ med x', - ['ammogiven'] = '~s~ skott', + ['threw_weapon'] = 'du ~r~slängde~s~ ~y~1x~s~ ~b~%s~s~ med ~o~%sx~s~ skott!', + ['gave_weapon'] = 'du gav ~y~1x~s~ ~b~%s~s~ med ~o~%sx~s~ skott till ~y~%s~s~.', + ['recived_weapon'] = 'du tog emot ~y~1x~s~ ~b~%s~s~ med ~o~%sx~s~ skott från ~b~%s~s~.', + ['gave_ammo'] = 'du gav ~o~%sx~s~ skott till ~y~%s~s~.', + ['recived_ammo'] = 'du tog emot ~o~%sx~s~ skott från ~b~%s~s~.', ['giveammo'] = 'Ge ammunition', ['amount_invalid'] = 'ogiltig mängd', ['players_nearby'] = 'inga spelare nära', @@ -19,7 +22,7 @@ Locales['sv'] = { ['by'] = '~s~ av ~b~', ['imp_invalid_quantity'] = 'åtgärd omöjlig, ogiltig mängd', ['imp_invalid_amount'] = 'åtgärd omöjlig, ogiltig belopp', - ['delete_five_min'] = '~r~ta bort~s~ inom 5 minuter', + ['delete_five_min'] = 'objektet kommer att ~r~tas bort~s~ om 5 minuter!', ['threw'] = 'du ~r~kastade~s~', ['rec_salary'] = 'du fick din lön: ', ['rec_help'] = 'du fick din välfärdskontroll: ', @@ -27,6 +30,7 @@ Locales['sv'] = { ['company_nomoney'] = 'Ditt företag är för fattigt!!', ['state_paid'] = 'Du fick en statlig check', ['act_imp'] = 'åtgärd omöjlig', + ['in_vehicle'] = 'du kan inte ge saker till en som sitter i ett fordon!', ['cannot_pickup_room'] = 'du har inte plats för att plocka upp ~y~%s~s~!', -- Commands ['setjob'] = 'tilldela ett jobb till en användare', diff --git a/server/commands.lua b/server/commands.lua index e0e371f9..d53a7948 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -150,11 +150,11 @@ TriggerEvent('es:addGroupCommand', 'giveweapon', 'admin', function(source, args, local xPlayer = ESX.GetPlayerFromId(args[1]) local weaponName = string.upper(args[2]) - xPlayer.addWeapon(weaponName, 1000) + xPlayer.addWeapon(weaponName, tonumber(args[3])) end, function(source, args, user) TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Insufficient Permissions.") -end, {help = _U('giveweapon'), params = {{name = "id", help = _U('id_param')}, {name = "weapon", help = _U('weapon')}}}) +end, {help = _U('giveweapon'), params = {{name = "id", help = _U('id_param')}, {name = "weapon", help = _U('weapon')}, {name = "ammo", help = _U('amountammo')}}}) TriggerEvent('es:addGroupCommand', 'disc', 'admin', function(source, args, user) DropPlayer(source, 'You have been disconnected') diff --git a/server/main.lua b/server/main.lua index 94bfc585..147690f5 100644 --- a/server/main.lua +++ b/server/main.lua @@ -309,7 +309,7 @@ end) RegisterServerEvent('esx:giveInventoryItem') -AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCount,ammotogive) +AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCount) local _source = source @@ -379,8 +379,8 @@ AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCo end end - TriggerClientEvent('esx:showNotification', _source, _U('yougave') .. ' x1 ~g~' .. weaponLabel .. _U('to') .. targetXPlayer.name) - TriggerClientEvent('esx:showNotification', target, _U('youreceived') .. ' x1 ~g~' .. weaponLabel .. _U('by') .. sourceXPlayer.name) + TriggerClientEvent('esx:showNotification', _source, _U('gave_weapon', weaponLabel, itemCount, targetXPlayer.name)) + TriggerClientEvent('esx:showNotification', target, _U('recived_weapon', weaponLabel, itemCount, sourceXPlayer.name)) end end) @@ -517,16 +517,17 @@ AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount) break end end - + + 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) + TriggerClientEvent('esx:pickupWeapon', _source, weaponPickup, weaponName, itemCount) end - TriggerClientEvent('esx:showNotification', _source, _U('threw') .. ' x1 ~g~' .. weaponLabel .. _U('withammo').. '~r~' .. itemCount .. _U('ammogiven')) + TriggerClientEvent('esx:showNotification', _source, _U('threw_weapon', weaponLabel, itemCount)) end)