Use new ESX function, secutiy fixes and cleanup

This commit is contained in:
ElPumpo
2018-05-05 23:56:51 +02:00
parent d5520be5d7
commit 1ea1c5b203
6 changed files with 57 additions and 101 deletions
+37 -61
View File
@@ -15,8 +15,6 @@ end
TriggerEvent('esx_phone:registerNumber', 'mecano', _U('mechanic_customer'), true, true)
TriggerEvent('esx_society:registerSociety', 'mecano', 'Mecano', 'society_mecano', 'society_mecano', 'society_mecano', {type = 'private'})
-------------- Récupération bouteille de gaz -------------
---- Sqlut je teste ------
local function Harvest(source)
SetTimeout(4000, function()
@@ -29,8 +27,7 @@ local function Harvest(source)
if GazBottleQuantity >= 5 then
TriggerClientEvent('esx:showNotification', source, _U('you_do_not_room'))
else
xPlayer.addInventoryItem('gazbottle', 1)
xPlayer.addInventoryItem('gazbottle', 1)
Harvest(source)
end
end
@@ -62,8 +59,7 @@ local function Harvest2(source)
if FixToolQuantity >= 5 then
TriggerClientEvent('esx:showNotification', source, _U('you_do_not_room'))
else
xPlayer.addInventoryItem('fixtool', 1)
xPlayer.addInventoryItem('fixtool', 1)
Harvest2(source)
end
end
@@ -83,7 +79,7 @@ AddEventHandler('esx_mecanojob:stopHarvest2', function()
local _source = source
PlayersHarvesting2[_source] = false
end)
----------------- Récupération Outils Carosserie ----------------
local function Harvest3(source)
SetTimeout(4000, function()
@@ -92,11 +88,10 @@ local function Harvest3(source)
local xPlayer = ESX.GetPlayerFromId(source)
local CaroToolQuantity = xPlayer.getInventoryItem('carotool').count
if CaroToolQuantity >= 5 then
if CaroToolQuantity >= 5 then
TriggerClientEvent('esx:showNotification', source, _U('you_do_not_room'))
else
xPlayer.addInventoryItem('carotool', 1)
xPlayer.addInventoryItem('carotool', 1)
Harvest3(source)
end
end
@@ -116,7 +111,7 @@ AddEventHandler('esx_mecanojob:stopHarvest3', function()
local _source = source
PlayersHarvesting3[_source] = false
end)
------------ Craft Chalumeau -------------------
local function Craft(source)
SetTimeout(4000, function()
@@ -129,9 +124,8 @@ local function Craft(source)
if GazBottleQuantity <= 0 then
TriggerClientEvent('esx:showNotification', source, _U('not_enough_gas_can'))
else
xPlayer.removeInventoryItem('gazbottle', 1)
xPlayer.addInventoryItem('blowpipe', 1)
xPlayer.removeInventoryItem('gazbottle', 1)
xPlayer.addInventoryItem('blowpipe', 1)
Craft(source)
end
end
@@ -151,7 +145,7 @@ AddEventHandler('esx_mecanojob:stopCraft', function()
local _source = source
PlayersCrafting[_source] = false
end)
------------ Craft kit Réparation --------------
local function Craft2(source)
SetTimeout(4000, function()
@@ -163,9 +157,8 @@ local function Craft2(source)
if FixToolQuantity <= 0 then
TriggerClientEvent('esx:showNotification', source, _U('not_enough_repair_tools'))
else
xPlayer.removeInventoryItem('fixtool', 1)
xPlayer.addInventoryItem('fixkit', 1)
xPlayer.removeInventoryItem('fixtool', 1)
xPlayer.addInventoryItem('fixkit', 1)
Craft2(source)
end
end
@@ -185,7 +178,7 @@ AddEventHandler('esx_mecanojob:stopCraft2', function()
local _source = source
PlayersCrafting2[_source] = false
end)
----------------- Craft kit Carosserie ----------------
local function Craft3(source)
SetTimeout(4000, function()
@@ -197,9 +190,8 @@ local function Craft3(source)
if CaroToolQuantity <= 0 then
TriggerClientEvent('esx:showNotification', source, _U('not_enough_body_tools'))
else
xPlayer.removeInventoryItem('carotool', 1)
xPlayer.addInventoryItem('carokit', 1)
xPlayer.removeInventoryItem('carotool', 1)
xPlayer.addInventoryItem('carokit', 1)
Craft3(source)
end
end
@@ -220,8 +212,6 @@ AddEventHandler('esx_mecanojob:stopCraft3', function()
PlayersCrafting3[_source] = false
end)
---------------------------- NPC Job Earnings ------------------------------------------------------
RegisterServerEvent('esx_mecanojob:onNPCJobMissionCompleted')
AddEventHandler('esx_mecanojob:onNPCJobMissionCompleted', function()
@@ -241,7 +231,6 @@ AddEventHandler('esx_mecanojob:onNPCJobMissionCompleted', function()
end)
---------------------------- register usable item --------------------------------------------------
ESX.RegisterUsableItem('blowpipe', function(source)
local _source = source
@@ -250,7 +239,7 @@ ESX.RegisterUsableItem('blowpipe', function(source)
xPlayer.removeInventoryItem('blowpipe', 1)
TriggerClientEvent('esx_mecanojob:onHijack', _source)
TriggerClientEvent('esx:showNotification', _source, _U('you_used_blowtorch'))
TriggerClientEvent('esx:showNotification', _source, _U('you_used_blowtorch'))
end)
@@ -262,7 +251,7 @@ ESX.RegisterUsableItem('fixkit', function(source)
xPlayer.removeInventoryItem('fixkit', 1)
TriggerClientEvent('esx_mecanojob:onFixkit', _source)
TriggerClientEvent('esx:showNotification', _source, _U('you_used_repair_kit'))
TriggerClientEvent('esx:showNotification', _source, _U('you_used_repair_kit'))
end)
@@ -274,34 +263,33 @@ ESX.RegisterUsableItem('carokit', function(source)
xPlayer.removeInventoryItem('carokit', 1)
TriggerClientEvent('esx_mecanojob:onCarokit', _source)
TriggerClientEvent('esx:showNotification', _source, _U('you_used_body_kit'))
TriggerClientEvent('esx:showNotification', _source, _U('you_used_body_kit'))
end)
----------------------------------
---- Ajout Gestion Stock Boss ----
----------------------------------
RegisterServerEvent('esx_mecanojob:getStockItem')
AddEventHandler('esx_mecanojob:getStockItem', function(itemName, count)
local xPlayer = ESX.GetPlayerFromId(source)
local xPlayer = ESX.GetPlayerFromId(source)
TriggerEvent('esx_addoninventory:getSharedInventory', 'society_mecano', function(inventory)
local item = inventory.getItem(itemName)
if item.count >= count then
inventory.removeItem(itemName, count)
xPlayer.addInventoryItem(itemName, count)
else
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('invalid_quantity'))
end
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('you_removed') .. count .. ' ' .. item.label)
end)
TriggerEvent('esx_addoninventory:getSharedInventory', 'society_mecano', function(inventory)
local item = inventory.getItem(itemName)
local sourceItem = xPlayer.getInventoryItem(itemName)
-- is there enough in the society?
if count > 0 and item.count >= count then
-- can the player carry the said amount of x item?
if sourceItem.limit ~= -1 and (sourceItem.count + count) > sourceItem.limit then
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('player_cannot_hold'))
else
inventory.removeItem(itemName, count)
xPlayer.addInventoryItem(itemName, count)
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('have_withdrawn', count, item.label))
end
else
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('invalid_quantity'))
end
end)
end)
ESX.RegisterServerCallback('esx_mecanojob:getStockItems', function(source, cb)
@@ -312,10 +300,6 @@ ESX.RegisterServerCallback('esx_mecanojob:getStockItems', function(source, cb)
end)
-------------
-- AJOUT 2 --
-------------
RegisterServerEvent('esx_mecanojob:putStockItems')
AddEventHandler('esx_mecanojob:putStockItems', function(itemName, count)
@@ -339,14 +323,6 @@ AddEventHandler('esx_mecanojob:putStockItems', function(itemName, count)
end)
--ESX.RegisterServerCallback('esx_mecanojob:putStockItems', function(source, cb)
-- TriggerEvent('esx_addoninventory:getSharedInventory', 'society_policestock', function(inventory)
-- cb(inventory.items)
-- end)
--end)
ESX.RegisterServerCallback('esx_mecanojob:getPlayerInventory', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)