From c975fea6d30f0bd3b7ac2bb1f9e7ce181406c27d Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Sun, 25 Nov 2018 17:32:36 +0100 Subject: [PATCH] Don't give weapon if target already has one, seperate string for weapon without ammo --- client/functions.lua | 15 +++++++------- client/main.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 | 9 +++++++-- locales/sv.lua | 8 ++++++-- server/main.lua | 48 ++++++++++++++++++++++++++++---------------- 11 files changed, 90 insertions(+), 40 deletions(-) diff --git a/client/functions.lua b/client/functions.lua index 51337139..ab0b0e5d 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -1109,7 +1109,11 @@ ESX.ShowInventory = function() for i=1, #players, 1 do if players[i] ~= PlayerId() then foundPlayers = true - table.insert(elements, {label = GetPlayerName(players[i]), value = players[i]}) + + table.insert(elements, { + label = GetPlayerName(players[i]), + value = players[i] + }) end end @@ -1166,8 +1170,7 @@ ESX.ShowInventory = function() else -- type: item_standard - ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'inventory_item_count_give', - { + ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'inventory_item_count_give', { title = _U('amount') }, function(data3, menu3) local quantity = tonumber(data3.value) @@ -1219,8 +1222,7 @@ ESX.ShowInventory = function() else -- type: item_standard - ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'inventory_item_count_remove', - { + ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'inventory_item_count_remove', { title = _U('amount') }, function(data2, menu2) local quantity = tonumber(data2.value) @@ -1257,8 +1259,7 @@ ESX.ShowInventory = function() if closestPlayer ~= -1 and closestDistance < 3.0 then if pedAmmo > 0 then - ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'inventory_item_count_give', - { + ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'inventory_item_count_give', { title = _U('amountammo') }, function(data2, menu2) diff --git a/client/main.lua b/client/main.lua index 9bb7ebea..b4c305d9 100644 --- a/client/main.lua +++ b/client/main.lua @@ -131,6 +131,7 @@ AddEventHandler('esx:addInventoryItem', function(item, count) for i=1, #ESX.PlayerData.inventory, 1 do if ESX.PlayerData.inventory[i].name == item.name then ESX.PlayerData.inventory[i] = item + break end end @@ -146,6 +147,7 @@ AddEventHandler('esx:removeInventoryItem', function(item, count) for i=1, #ESX.PlayerData.inventory, 1 do if ESX.PlayerData.inventory[i].name == item.name then ESX.PlayerData.inventory[i] = item + break end end diff --git a/locales/br.lua b/locales/br.lua index 1b54127c..b4958196 100644 --- a/locales/br.lua +++ b/locales/br.lua @@ -13,8 +13,12 @@ Locales['br'] = { ['noammo'] = 'voce nao tem todas essas muniçoes!', ['gave_item'] = 'voce deu ~y~%sx~s~ ~b~%s~s~ para ~y~%s~s~', ['received_item'] = 'voce recebeu ~y~%sx~s~ ~b~%s~s~ de ~b~%s~s~', - ['gave_weapon'] = 'voce deu ~y~1x~s~ ~b~%s~s~ com ~o~%sx~s~ balas para ~y~%s~s~.', - ['received_weapon'] = 'voce recebeu ~y~1x~s~ ~b~%s~s~ com ~o~%sx~s~ balas de ~b~%s~s~.', + ['gave_weapon'] = 'you gave ~y~1x~s~ ~b~%s~s~ to ~y~%s~s~.', + ['gave_weapon_ammo'] = 'you gave ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets to ~y~%s~s~.', + ['gave_weapon_hasalready'] = '~y~%s~s~ already have an ~y~%s~s~', + ['received_weapon'] = 'you received ~y~1x~s~ ~b~%s~s~ from ~b~%s~s~.', + ['received_weapon_ammo'] = 'you received ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets from ~b~%s~s~.', + ['received_weapon_hasalready'] = '~b~%s~s~ attempted to give you an ~y~%s~s~, but you already have one.', ['gave_ammo'] = 'voce deu ~o~%sx~s~ balas para ~y~%s~s~.', ['received_ammo'] = 'voce recebeu ~o~%sx~s~ balas de ~b~%s~s~.', ['gave_money'] = 'voce deu ~g~$%s~s~ para ~y~%s~s~', diff --git a/locales/cs.lua b/locales/cs.lua index 2a3c6bf5..98b34f8d 100644 --- a/locales/cs.lua +++ b/locales/cs.lua @@ -13,8 +13,12 @@ Locales['cs'] = { ['noammo'] = 'nemáte dostatek munice!', ['gave_item'] = 'dali jste ~y~%sx~s~ ~b~%s~s~ ~y~%s~s~', ['received_item'] = 'obdrželi jste ~y~%sx~s~ ~b~%s~s~ od ~b~%s~s~', - ['gave_weapon'] = 'dali jste ~y~1x~s~ ~b~%s~s~ s ~o~%sx~s~ náboji ~y~%s~s~.', - ['received_weapon'] = 'obdrželi jste ~y~1x~s~ ~b~%s~s~ s ~o~%sx~s~ náboji od ~b~%s~s~.', + ['gave_weapon'] = 'you gave ~y~1x~s~ ~b~%s~s~ to ~y~%s~s~.', + ['gave_weapon_ammo'] = 'you gave ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets to ~y~%s~s~.', + ['gave_weapon_hasalready'] = '~y~%s~s~ already have an ~y~%s~s~', + ['received_weapon'] = 'you received ~y~1x~s~ ~b~%s~s~ from ~b~%s~s~.', + ['received_weapon_ammo'] = 'you received ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets from ~b~%s~s~.', + ['received_weapon_hasalready'] = '~b~%s~s~ attempted to give you an ~y~%s~s~, but you already have one.', ['gave_ammo'] = 'dali jste ~o~%sx~s~ nábojů ~y~%s~s~.', ['received_ammo'] = 'obdrželi jste ~o~%sx~s~ nábojů od ~b~%s~s~.', ['gave_money'] = 'dali jste ~g~$%s~s~ ~y~%s~s~', diff --git a/locales/de.lua b/locales/de.lua index 200032df..1ec804c1 100644 --- a/locales/de.lua +++ b/locales/de.lua @@ -13,8 +13,12 @@ Locales['de'] = { ['noammo'] = 'du hast keine munition!', ['gave_item'] = 'du gibst ~y~%sx~s~ ~b~%s~s~ zu ~y~%s~s~', ['received_item'] = 'to empfängst ~y~%sx~s~ ~b~%s~s~ von ~b~%s~s~', - ['gave_weapon'] = 'you gave ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets to ~y~%s~s~.', - ['received_weapon'] = 'you received ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets from ~b~%s~s~.', + ['gave_weapon'] = 'you gave ~y~1x~s~ ~b~%s~s~ to ~y~%s~s~.', + ['gave_weapon_ammo'] = 'you gave ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets to ~y~%s~s~.', + ['gave_weapon_hasalready'] = '~y~%s~s~ already have an ~y~%s~s~', + ['received_weapon'] = 'you received ~y~1x~s~ ~b~%s~s~ from ~b~%s~s~.', + ['received_weapon_ammo'] = 'you received ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets from ~b~%s~s~.', + ['received_weapon_hasalready'] = '~b~%s~s~ attempted to give you an ~y~%s~s~, but you already have one.', ['gave_ammo'] = 'you gave ~o~%sx~s~ bullets to ~y~%s~s~.', ['received_ammo'] = 'you received ~o~%sx~s~ bullets from ~b~%s~s~.', ['gave_money'] = 'du gibst ~g~$%s~s~ zu ~y~%s~s~', diff --git a/locales/en.lua b/locales/en.lua index 3b4859b6..7819c5cb 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -13,8 +13,12 @@ Locales['en'] = { ['noammo'] = 'you do not have enough ammo!', ['gave_item'] = 'you gave ~y~%sx~s~ ~b~%s~s~ to ~y~%s~s~', ['received_item'] = 'you received ~y~%sx~s~ ~b~%s~s~ from ~b~%s~s~', - ['gave_weapon'] = 'you gave ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets to ~y~%s~s~.', - ['received_weapon'] = 'you received ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets from ~b~%s~s~.', + ['gave_weapon'] = 'you gave ~y~1x~s~ ~b~%s~s~ to ~y~%s~s~.', + ['gave_weapon_ammo'] = 'you gave ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets to ~y~%s~s~.', + ['gave_weapon_hasalready'] = '~y~%s~s~ already have an ~y~%s~s~', + ['received_weapon'] = 'you received ~y~1x~s~ ~b~%s~s~ from ~b~%s~s~.', + ['received_weapon_ammo'] = 'you received ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets from ~b~%s~s~.', + ['received_weapon_hasalready'] = '~b~%s~s~ attempted to give you an ~y~%s~s~, but you already have one.', ['gave_ammo'] = 'you gave ~o~%sx~s~ bullets to ~y~%s~s~.', ['received_ammo'] = 'you received ~o~%sx~s~ bullets from ~b~%s~s~.', ['gave_money'] = 'you gave ~g~$%s~s~ to ~y~%s~s~', diff --git a/locales/fi.lua b/locales/fi.lua index a22e7130..39b7c8e9 100644 --- a/locales/fi.lua +++ b/locales/fi.lua @@ -13,8 +13,12 @@ Locales['fi'] = { ['noammo'] = 'sinulla ei ole ammuksia!', ['gave_item'] = 'sinä annoit ~y~%sx~s~ ~b~%s~s~ henkilölle ~y~%s~s~', ['received_item'] = 'sinä sait ~y~%sx~s~ ~b~%s~s~ henkilöltä ~b~%s~s~', - ['gave_weapon'] = 'sinä annoit ~y~1x~s~ ~b~%s~s~ jossa oli ~o~%sx~s~ ammuksia henkilölle ~y~%s~s~.', - ['received_weapon'] = 'sinä sait ~y~1x~s~ ~b~%s~s~ jossa oli ~o~%sx~s~ ammuksia henkilöltä ~b~%s~s~.', + ['gave_weapon'] = 'you gave ~y~1x~s~ ~b~%s~s~ to ~y~%s~s~.', + ['gave_weapon_ammo'] = 'you gave ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets to ~y~%s~s~.', + ['gave_weapon_hasalready'] = '~y~%s~s~ already have an ~y~%s~s~', + ['received_weapon'] = 'you received ~y~1x~s~ ~b~%s~s~ from ~b~%s~s~.', + ['received_weapon_ammo'] = 'you received ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets from ~b~%s~s~.', + ['received_weapon_hasalready'] = '~b~%s~s~ attempted to give you an ~y~%s~s~, but you already have one.', ['gave_ammo'] = 'sinä annoit ~o~%sx~s~ ammuksia henkilölle ~y~%s~s~.', ['received_ammo'] = 'sinä sait ~o~%sx~s~ ammuksia henkilöltä ~b~%s~s~.', ['gave_money'] = 'sinä annoit ~g~$%s~s~ henkilölle ~y~%s~s~', diff --git a/locales/fr.lua b/locales/fr.lua index 044a0530..fc676c62 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -13,8 +13,12 @@ Locales['fr'] = { ['noammo'] = 'tu n\'as pas toutes ces munitions!', ['gave_item'] = 'vous avez donné ~y~%sx~s~ ~b~%s~s~ à ~y~%s~s~', ['received_item'] = 'vous avez reçu ~y~%sx~s~ ~b~%s~s~ par ~b~%s~s~', - ['gave_weapon'] = 'vous donnez ~y~1x~s~ ~b~%s~s~ avec ~o~%sx~s~ minitions à ~y~%s~s~.', - ['received_weapon'] = 'vous recevez ~y~1x~s~ ~b~%s~s~ avec ~o~%sx~s~ munitions de ~b~%s~s~.', + ['gave_weapon'] = 'you gave ~y~1x~s~ ~b~%s~s~ to ~y~%s~s~.', + ['gave_weapon_ammo'] = 'you gave ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets to ~y~%s~s~.', + ['gave_weapon_hasalready'] = '~y~%s~s~ already have an ~y~%s~s~', + ['received_weapon'] = 'you received ~y~1x~s~ ~b~%s~s~ from ~b~%s~s~.', + ['received_weapon_ammo'] = 'you received ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets from ~b~%s~s~.', + ['received_weapon_hasalready'] = '~b~%s~s~ attempted to give you an ~y~%s~s~, but you already have one.', ['gave_ammo'] = 'vous donnez ~o~%sx~s~ munitions à ~y~%s~s~.', ['received_ammo'] = 'vous recevez ~o~%sx~s~ munitions de ~b~%s~s~.', ['gave_money'] = 'vous avez donné ~g~$%s~s~ à ~y~%s~s~', diff --git a/locales/pl.lua b/locales/pl.lua index 2b249813..3dc704cb 100644 --- a/locales/pl.lua +++ b/locales/pl.lua @@ -6,14 +6,19 @@ Locales['pl'] = { ['give'] = 'daj', ['remove'] = 'usuń', ['return'] = 'return', + ['give_to'] = 'give to', ['amount'] = 'amount', ['giveammo'] = 'give ammo', ['amountammo'] = 'ilość amunicji', ['noammo'] = 'nie masz wystarczającej ilości amunicji!', ['gave_item'] = 'dajesz ~y~%sx~s~ ~b~%s~s~ dla ~y~%s~s~', ['received_item'] = 'otrzymujesz ~y~%sx~s~ ~b~%s~s~ od ~b~%s~s~', - ['gave_weapon'] = 'dajesz ~y~1x~s~ ~b~%s~s~ z ~o~%sx~s~ nabojami dla ~y~%s~s~.', - ['received_weapon'] = 'otrzymujesz ~y~1x~s~ ~b~%s~s~ z ~o~%sx~s~ nabojami od ~b~%s~s~.', + ['gave_weapon'] = 'you gave ~y~1x~s~ ~b~%s~s~ to ~y~%s~s~.', + ['gave_weapon_ammo'] = 'you gave ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets to ~y~%s~s~.', + ['gave_weapon_hasalready'] = '~y~%s~s~ already have an ~y~%s~s~', + ['received_weapon'] = 'you received ~y~1x~s~ ~b~%s~s~ from ~b~%s~s~.', + ['received_weapon_ammo'] = 'you received ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets from ~b~%s~s~.', + ['received_weapon_hasalready'] = '~b~%s~s~ attempted to give you an ~y~%s~s~, but you already have one.', ['gave_ammo'] = 'dajesz ~o~%sx~s~ naboje dla ~y~%s~s~.', ['received_ammo'] = 'otrzymujesz ~o~%sx~s~ naboje od ~b~%s~s~.', ['gave_money'] = 'dajesz ~g~%s$~s~ dla ~y~%s~s~', diff --git a/locales/sv.lua b/locales/sv.lua index 0c759e7b..2d3453be 100644 --- a/locales/sv.lua +++ b/locales/sv.lua @@ -13,8 +13,12 @@ Locales['sv'] = { ['noammo'] = 'du har inte tillräckligt med ammunition!', ['gave_item'] = 'du gav ~y~%sx~s~ ~b~%s~s~ till ~y~%s~s~', ['received_item'] = 'du tog emot ~y~%sx~s~ ~b~%s~s~ från ~b~%s~s~', - ['gave_weapon'] = 'du gav ~y~1x~s~ ~b~%s~s~ med ~o~%sx~s~ skott till ~y~%s~s~.', - ['received_weapon'] = 'du tog emot ~y~1x~s~ ~b~%s~s~ med ~o~%sx~s~ skott från ~b~%s~s~.', + ['gave_weapon'] = 'du gav ~y~1x~s~ ~b~%s~s~ till ~y~%s~s~.', + ['gave_weapon_ammo'] = 'du gav ~y~1x~s~ ~b~%s~s~ med ~o~%sx~s~ skott till ~y~%s~s~.', + ['gave_weapon_hasalready'] = '~y~%s~s~ har redan en ~y~%s~s~', + ['received_weapon'] = 'du tog emot ~y~1x~s~ ~b~%s~s~ från ~b~%s~s~.', + ['received_weapon_ammo'] = 'du tog emot ~y~1x~s~ ~b~%s~s~ med ~o~%sx~s~ skott från ~b~%s~s~.', + ['received_weapon_hasalready'] = '~b~%s~s~ försökte ge dig en ~y~%s~s~, men det har du redan.', ['gave_ammo'] = 'du gav ~o~%sx~s~ skott till ~y~%s~s~.', ['received_ammo'] = 'du tog emot ~o~%sx~s~ skott från ~b~%s~s~.', ['gave_money'] = 'du gav ~g~%s SEK~s~ till ~y~%s~s~', diff --git a/server/main.lua b/server/main.lua index d3717a86..f008d0d7 100644 --- a/server/main.lua +++ b/server/main.lua @@ -15,11 +15,10 @@ AddEventHandler('es:playerLoaded', function(source, _player) -- Update user name in DB table.insert(tasks, function(cb) - MySQL.Async.execute('UPDATE `users` SET `name` = @name WHERE `identifier` = @identifier', - { - ['@identifier'] = player.getIdentifier(), - ['@name'] = userData.playerName - }, function(rowsChanged) + MySQL.Async.execute('UPDATE `users` SET `name` = @name WHERE `identifier` = @identifier', { + ['@identifier'] = player.getIdentifier(), + ['@name'] = userData.playerName + }, function(rowsChanged) cb() end) end) @@ -291,13 +290,13 @@ AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCo elseif type == 'item_money' then - if itemCount > 0 and sourceXPlayer.player.get('money') >= itemCount then + if itemCount > 0 and sourceXPlayer.getMoney() >= itemCount then sourceXPlayer.removeMoney(itemCount) targetXPlayer.addMoney (itemCount) - TriggerClientEvent('esx:showNotification', _source, _U('gave_money', itemCount, targetXPlayer.name)) - TriggerClientEvent('esx:showNotification', target, _U('received_money', itemCount, sourceXPlayer.name)) + 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)) else TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount')) @@ -310,21 +309,35 @@ AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCo sourceXPlayer.removeAccountMoney(itemName, itemCount) targetXPlayer.addAccountMoney (itemName, itemCount) - TriggerClientEvent('esx:showNotification', _source, _U('gave_account_money', itemCount, Config.AccountLabels[itemName], targetXPlayer.name)) - TriggerClientEvent('esx:showNotification', target, _U('received_account_money', itemCount, Config.AccountLabels[itemName], sourceXPlayer.name)) + 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)) else TriggerClientEvent('esx:showNotification', _source, _U('imp_invalid_amount')) end elseif type == 'item_weapon' then - - sourceXPlayer.removeWeapon(itemName) - targetXPlayer.addWeapon(itemName, itemCount) - - local weaponLabel = ESX.GetWeaponLabel(itemName) - TriggerClientEvent('esx:showNotification', _source, _U('gave_weapon', weaponLabel, itemCount, targetXPlayer.name)) - TriggerClientEvent('esx:showNotification', target, _U('received_weapon', weaponLabel, itemCount, sourceXPlayer.name)) + + 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)) + else + TriggerClientEvent('esx:showNotification', _source, _U('gave_weapon', weaponLabel, targetXPlayer.name)) + TriggerClientEvent('esx:showNotification', target, _U('received_weapon', weaponLabel, sourceXPlayer.name)) + 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) @@ -345,6 +358,7 @@ AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount) for i=1, #xPlayer.inventory, 1 do if xPlayer.inventory[i].name == itemName then foundItem = xPlayer.inventory[i] + break end end