From eb42f346b288e9b544b269873a5fcd5d7a1c92b8 Mon Sep 17 00:00:00 2001 From: KandaSoranyan <32266067+KandaSoranyan@users.noreply.github.com> Date: Mon, 19 Feb 2018 03:30:02 +0100 Subject: [PATCH] Add files via upload --- client/functions.lua | 127 +++++++++++++++++++++++++++++++++----- client/main.lua | 8 +-- config.lua | 10 +-- locales/de.lua | 5 ++ locales/en.lua | 7 ++- locales/fr.lua | 5 ++ server/classes/player.lua | 3 +- server/main.lua | 10 +-- 8 files changed, 143 insertions(+), 32 deletions(-) diff --git a/client/functions.lua b/client/functions.lua index d6b9e676..b6c2ae1a 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -430,7 +430,7 @@ ESX.Game.SpawnLocalVehicle = function(modelName, coords, heading, cb) RequestCollisionAtCoord(coords.x, coords.y, coords.z) while not HasCollisionLoadedAroundEntity(vehicle) do - RequestCollisionAtCoord(coords.x, coords.y, coords.z) + RequestCollisionAtCoord(coords.x, coords.x, coords.x) Citizen.Wait(0) end @@ -1057,6 +1057,7 @@ ESX.Game.Utils.DrawText3D = function(coords, text, size) end + ESX.ShowInventory = function() local playerPed = GetPlayerPed(-1) @@ -1145,6 +1146,10 @@ 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 + table.insert(elements, {label = --[[_U('giveammo')]]"Give ammo", action = 'giveammo', type = data.current.type, value = data.current.value}) + end + table.insert(elements, {label = _U('return'), action = 'return'}) ESX.UI.Menu.Open( @@ -1158,29 +1163,54 @@ ESX.ShowInventory = function() local item = data.current.value local type = data.current.type + local playerPed = GetPlayerPed(-1) if data.current.action == 'give' then if type == 'item_weapon' then - local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() local closestPed = GetPlayerPed(closestPlayer) + local pedammo = GetAmmoInPedWeapon(GetPlayerPed(-1),GetHashKey(item)) + if not IsPedSittingInAnyVehicle(closestPed) then + if closestPlayer ~= -1 and closestDistance < 3.0 then + if pedammo > 0 then + ESX.UI.Menu.Open( + 'dialog', GetCurrentResourceName(), 'inventory_item_count_give', + { + title = _U('amountammo') + }, + function(data2, menu2) + local quantity = tonumber(data2.value) + if quantity <= pedammo and quantity >= 0 and quantity ~= nil then + local ammobefore = GetAmmoInPedWeapon(playerPed, item) + TriggerServerEvent('esx:giveInventoryItem', GetPlayerServerId(closestPlayer), type, item, quantity) + local finalammo = math.floor(ammobefore - quantity) + SetPedAmmo(playerPed, item, finalammo) + menu2.close() + menu.close() + else + ESX.ShowNotification(_U("noammo")) + end - if closestPlayer ~= -1 or closestDistance > 3.0 then - -- PERSONNE - if not IsPedSittingInAnyVehicle(closestPed) then - TriggerServerEvent('esx:giveInventoryItem', GetPlayerServerId(closestPlayer), type, item, 1) - else - ESX.ShowNotification(_U("in_vehicle")) - end + end, + function(data2, menu2) + menu2.close() + end + ) + else + TriggerServerEvent('esx:giveInventoryItem', GetPlayerServerId(closestPlayer), type, item, 0) + menu.close() + end + else + ESX.ShowNotification(_U('players_nearby')) + end else - ESX.ShowNotification(_U('players_nearby')) + ESX.ShowNotification(_U("in_vehicle")) end - menu.close() else - ESX.UI.Menu.Open( + ESX.UI.Menu.Open( 'dialog', GetCurrentResourceName(), 'inventory_item_count_give', { title = _U('amount') @@ -1191,7 +1221,7 @@ ESX.ShowInventory = function() local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() local closestPed = GetPlayerPed(closestPlayer) if not IsPedSittingInAnyVehicle(closestPed) then - if closestPlayer ~= -1 or closestDistance < 3.0 then + if closestPlayer ~= -1 and closestDistance < 3.0 then TriggerServerEvent('esx:giveInventoryItem', GetPlayerServerId(closestPlayer), type, item, quantity) else ESX.ShowNotification(_U('players_nearby')) @@ -1214,9 +1244,33 @@ 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) - TriggerServerEvent('esx:removeInventoryItem', type, item, 1) - menu.close() + 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 + ) else @@ -1255,6 +1309,49 @@ ESX.ShowInventory = function() ESX.UI.Menu.CloseAll() ESX.ShowInventory() + elseif data.current.action == 'giveammo' then + local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() + local closestPed = GetPlayerPed(closestPlayer) + local pedammo = GetAmmoInPedWeapon(playerPed,GetHashKey(item)) + if not IsPedSittingInAnyVehicle(closestPed) then + if closestPlayer ~= -1 and closestDistance < 3.0 then + if pedammo > 0 then + ESX.UI.Menu.Open( + 'dialog', GetCurrentResourceName(), 'inventory_item_count_give', + { + title = _U('amountammo') + }, + 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') ) + menu2.close() + menu.close() + else + ESX.ShowNotification(_U("noammo")) + end + + end, + function(data2, menu2) + menu2.close() + end + ) + else + TriggerServerEvent('esx:giveInventoryItem', GetPlayerServerId(closestPlayer), type, item, 0) + menu.close() + end + else + ESX.ShowNotification(_U('players_nearby')) + end + else + ESX.ShowNotification(_U("in_vehicle")) + end end end, diff --git a/client/main.lua b/client/main.lua index 3594b85f..cec70363 100644 --- a/client/main.lua +++ b/client/main.lua @@ -333,13 +333,13 @@ AddEventHandler('esx:removePickup', function(id) end) RegisterNetEvent('esx:pickupWeapon') -AddEventHandler('esx:pickupWeapon', function(weaponPickup, weaponName) +AddEventHandler('esx:pickupWeapon', function(weaponPickup, weaponName,ammo) local ped = GetPlayerPed(-1) local playerPedPos = GetEntityCoords(ped, true) - - CreateAmbientPickup(GetHashKey(weaponPickup), playerPedPos.x + 2.0, playerPedPos.y, playerPedPos.z + 0.5, 0, 1000, 1, false, true) - + print(ammo) + CreateAmbientPickup(GetHashKey(weaponPickup), playerPedPos.x + 2.0, playerPedPos.y, playerPedPos.z + 0.5, 0, ammo, 1, false, true) + end) RegisterNetEvent('esx:spawnPed') diff --git a/config.lua b/config.lua index 215a67fb..c5775be6 100644 --- a/config.lua +++ b/config.lua @@ -1,13 +1,13 @@ Config = {} -Config.MaxPlayers = 32 +Config.MaxPlayers = 4 Config.Accounts = { 'bank', 'black_money' } Config.AccountLabels = { bank = 'Banque', black_money = 'Argent Sale' } -- French -- Config.AccountLabels = { bank = 'Bank', black_money = 'Dirty Money' } -- English -Config.PaycheckInterval = 7 * 60000 -Config.ShowDotAbovePlayer = false +Config.PaycheckInterval = 2 * 60000 +Config.ShowDotAbovePlayer = true Config.DisableWantedLevel = true -Config.RemoveInventoryItemDelay = 5 * 60000 +Config.RemoveInventoryItemDelay = 1000 Config.EnableWeaponPickup = true Config.Locale = 'fr' -Config.EnableDebug = false +Config.EnableDebug = true diff --git a/locales/de.lua b/locales/de.lua index 2c6d8d22..23c6ea75 100644 --- a/locales/de.lua +++ b/locales/de.lua @@ -1,4 +1,9 @@ Locales['de'] = { + ['amountammo'] = 'anzahl der Munition', + ['noammo'] = 'Du hast keine Munition !', + ['withammo'] = '~s~ mit x', + ['ammogiven'] = '~s~ Kugeln', + ['giveammo'] = 'Munition geben', ['inventory'] = 'Inventar', ['use'] = 'benutzen', ['give'] = 'geben', diff --git a/locales/en.lua b/locales/en.lua index 2c03137b..12bc40f7 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -5,6 +5,11 @@ Locales['en'] = { ['remove'] = 'remove', ['return'] = 'return', ['amount'] = 'amount', + ['amountammo'] = 'amount of ammo', + ['noammo'] = 'You dont have all these ammo !', + ['withammo'] = '~s~ with x', + ['ammogiven'] = '~s~ bullets', + ['giveammo'] = 'Give ammo', ['amount_invalid'] = 'invalid amount', ['players_nearby'] = 'no players nearby', ['ex_inv_lim'] = 'action not possible, exceeding invetory limit for ~b~', @@ -128,4 +133,4 @@ Locales['en'] = { ['weapon_flashlight'] = 'flashlight', ['gadget_nightvision'] = 'night vision', ['gadget_parachute'] = 'parachute', -} +} \ No newline at end of file diff --git a/locales/fr.lua b/locales/fr.lua index 60540df3..dcae71ec 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -5,6 +5,11 @@ Locales['fr'] = { ['remove'] = 'jeter', ['return'] = 'retour', ['amount'] = 'quantité', + ['amountammo'] = 'nombre de munitions', + ['noammo'] = 'Tu n\'as pas toutes ces munitions !', + ['withammo'] = '~s~ avec x ', + ['ammogiven'] = '~s~ balles', + ['giveammo'] = 'Donner munitions', ['amount_invalid'] = 'montant invalide', ['players_nearby'] = 'aucun joueur à proximité', ['ex_inv_lim'] = 'action impossible, depassement de la limite d\'inventaire pour ~b~', diff --git a/server/classes/player.lua b/server/classes/player.lua index b7d365b4..bf88ac93 100644 --- a/server/classes/player.lua +++ b/server/classes/player.lua @@ -388,11 +388,10 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, l if not foundWeapon then table.insert(self.loadout, { name = weaponName, - ammo = ammon, + ammo = ammo, label = weaponLabel }) end - TriggerClientEvent('esx:addWeapon', self.source, weaponName, ammo) TriggerClientEvent("esx:addInventoryItem", self.source, {label = weaponLabel}, 1) end diff --git a/server/main.lua b/server/main.lua index 8bafdddf..2e2e10cb 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) +AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCount,ammotogive) local _source = source @@ -366,10 +366,10 @@ AddEventHandler('esx:giveInventoryItem', function(target, type, itemName, itemCo end elseif type == 'item_weapon' then - + sourceXPlayer.removeWeapon(itemName) targetXPlayer.addWeapon(itemName, itemCount) - + local weaponLabel = itemName for i=1, #Config.Weapons, 1 do @@ -523,10 +523,10 @@ AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount) xPlayer.removeWeapon(itemName) if Config.EnableWeaponPickup then - TriggerClientEvent('esx:pickupWeapon', _source, weaponPickup, weaponName) + TriggerClientEvent('esx:pickupWeapon', _source, weaponPickup, weaponName,itemCount) end - TriggerClientEvent('esx:showNotification', _source, _U('threw') .. ' x1 ~g~' .. weaponLabel) + TriggerClientEvent('esx:showNotification', _source, _U('threw') .. ' x1 ~g~' .. weaponLabel .. _U('withammo').. '~r~' .. itemCount .. _U('ammogiven')) end)