diff --git a/client/main.lua b/client/main.lua
index 18d0ad43..489d4ae8 100644
--- a/client/main.lua
+++ b/client/main.lua
@@ -124,15 +124,18 @@ AddEventHandler('es:activateMoney', function(money)
end)
RegisterNetEvent('esx:addInventoryItem')
-AddEventHandler('esx:addInventoryItem', function(item, count)
+AddEventHandler('esx:addInventoryItem', function(item, count, showNotification)
for k,v in ipairs(ESX.PlayerData.inventory) do
- if v.name == item.name then
- ESX.PlayerData.inventory[k] = item
+ if v.name == item then
+ ESX.UI.ShowInventoryItemNotification(true, v.label, count - v.count)
+ ESX.PlayerData.inventory[k].count = count
break
end
end
- ESX.UI.ShowInventoryItemNotification(true, item, count)
+ if showNotification then
+ ESX.UI.ShowInventoryItemNotification(true, item, count)
+ end
if ESX.UI.Menu.IsOpen('default', 'es_extended', 'inventory') then
ESX.ShowInventory()
@@ -140,15 +143,18 @@ AddEventHandler('esx:addInventoryItem', function(item, count)
end)
RegisterNetEvent('esx:removeInventoryItem')
-AddEventHandler('esx:removeInventoryItem', function(item, count)
+AddEventHandler('esx:removeInventoryItem', function(item, count, showNotification)
for k,v in ipairs(ESX.PlayerData.inventory) do
- if v.name == item.name then
- ESX.PlayerData.inventory[k] = item
+ if v.name == item then
+ ESX.UI.ShowInventoryItemNotification(false, v.label, v.count - count)
+ ESX.PlayerData.inventory[k].count = count
break
end
end
- ESX.UI.ShowInventoryItemNotification(false, item, count)
+ if showNotification then
+ ESX.UI.ShowInventoryItemNotification(false, item, count)
+ end
if ESX.UI.Menu.IsOpen('default', 'es_extended', 'inventory') then
ESX.ShowInventory()
diff --git a/html/js/app.js b/html/js/app.js
index 95308dc6..7705334c 100644
--- a/html/js/app.js
+++ b/html/js/app.js
@@ -22,7 +22,6 @@
};
ESX.updateHUDElement = function (name, data) {
-
for (let i = 0; i < ESX.HUDElements.length; i++) {
if (ESX.HUDElements[i].name == name) {
ESX.HUDElements[i].data = data;
@@ -51,7 +50,7 @@
}
};
- ESX.inventoryNotification = function (add, item, count) {
+ ESX.inventoryNotification = function (add, label, count) {
let notif = '';
if (add) {
@@ -60,10 +59,13 @@
notif += '-';
}
- notif += count + ' ' + item.label;
+ if (count) {
+ notif += count + ' ' + label;
+ } else {
+ notif += ' ' + label;
+ }
let elem = $('
' + notif + '
');
-
$('#inventory_notifications').append(elem);
$(elem).delay(3000).fadeOut(1000, function () {
@@ -105,4 +107,4 @@
});
};
-})();
\ No newline at end of file
+})();
diff --git a/server/classes/player.lua b/server/classes/player.lua
index 391b0e96..3b931af8 100644
--- a/server/classes/player.lua
+++ b/server/classes/player.lua
@@ -70,10 +70,6 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
self.player.displayMoney(money)
end
- self.displayBank = function(money)
- self.player.displayBank(money)
- end
-
self.getIdentifier = function()
return self.player.getIdentifier()
end
@@ -97,8 +93,8 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
self.getAccounts = function()
local accounts = {}
- for k,v in ipairs(Config.Accounts) do
- if v == 'bank' then
+ for k,account in ipairs(Config.Accounts) do
+ if account == 'bank' then
table.insert(accounts, {
name = 'bank',
money = self.get('bank'),
@@ -106,8 +102,9 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
})
else
for k2,v2 in ipairs(self.accounts) do
- if v2.name == v then
+ if v2.name == account then
table.insert(accounts, v2)
+ break
end
end
end
@@ -116,8 +113,8 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
return accounts
end
- self.getAccount = function(a)
- if a == 'bank' then
+ self.getAccount = function(account)
+ if account == 'bank' then
return {
name = 'bank',
money = self.get('bank'),
@@ -126,7 +123,7 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
end
for k,v in ipairs(self.accounts) do
- if v.name == a then
+ if v.name == account then
return v
end
end
@@ -192,9 +189,9 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
end
end
- self.setAccountMoney = function(acc, money)
+ self.setAccountMoney = function(accountName, money)
if money >= 0 then
- local account = self.getAccount(acc)
+ local account = self.getAccount(accountName)
if account then
local prevMoney = account.money
@@ -202,7 +199,7 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
account.money = newMoney
- if acc == 'bank' then
+ if accountName == 'bank' then
self.set('bank', newMoney)
end
@@ -211,15 +208,15 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
end
end
- self.addAccountMoney = function(acc, money)
+ self.addAccountMoney = function(accountName, money)
if money > 0 then
- local account = self.getAccount(acc)
+ local account = self.getAccount(accountName)
if account then
local newMoney = account.money + ESX.Math.Round(money)
account.money = newMoney
- if acc == 'bank' then
+ if accountName == 'bank' then
self.set('bank', newMoney)
end
@@ -228,15 +225,15 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
end
end
- self.removeAccountMoney = function(acc, money)
+ self.removeAccountMoney = function(accountName, money)
if money > 0 then
- local account = self.getAccount(acc)
+ local account = self.getAccount(accountName)
if account then
local newMoney = account.money - ESX.Math.Round(money)
account.money = newMoney
- if acc == 'bank' then
+ if accountName == 'bank' then
self.set('bank', newMoney)
end
@@ -259,11 +256,13 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
local item = self.getInventoryItem(name)
if item then
- local newCount = item.count + count
- item.count = newCount
+ count = ESX.Math.Round(count)
- TriggerEvent('esx:onAddInventoryItem', self.source, item, count)
- self.triggerEvent('esx:addInventoryItem', item, count)
+ local newCount = item.count + count
+ item.count = newCount
+
+ TriggerEvent('esx:onAddInventoryItem', self.source, item.name, item.count)
+ self.triggerEvent('esx:addInventoryItem', item.name, item.count)
end
end
@@ -271,13 +270,14 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
local item = self.getInventoryItem(name)
if item then
+ count = ESX.Math.Round(count)
local newCount = item.count - count
if newCount >= 0 then
item.count = newCount
- TriggerEvent('esx:onRemoveInventoryItem', self.source, item, count)
- self.triggerEvent('esx:removeInventoryItem', item, count)
+ TriggerEvent('esx:onRemoveInventoryItem', self.source, item.name, item.count)
+ self.triggerEvent('esx:removeInventoryItem', item.name, item.count)
end
end
end
@@ -286,15 +286,12 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
local item = self.getInventoryItem(name)
if item and count >= 0 then
- local oldCount = item.count
- item.count = count
+ count = ESX.Math.Round(count)
- if oldCount > item.count then
- TriggerEvent('esx:onRemoveInventoryItem', self.source, item, oldCount - item.count)
- self.triggerEvent('esx:removeInventoryItem', item, oldCount - item.count)
+ if count > item.count then
+ self.addInventoryItem(item.name, count - item.count)
else
- TriggerEvent('esx:onAddInventoryItem', self.source, item, item.count - oldCount)
- self.triggerEvent('esx:addInventoryItem', item, item.count - oldCount)
+ self.removeInventoryItem(item.name, item.count - count)
end
end
end
@@ -351,15 +348,16 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
self.job.grade_label = gradeObject.label
self.job.grade_salary = gradeObject.salary
- self.job.skin_male = {}
- self.job.skin_female = {}
-
if gradeObject.skin_male then
self.job.skin_male = json.decode(gradeObject.skin_male)
+ else
+ self.job.skin_male = {}
end
if gradeObject.skin_female then
self.job.skin_female = json.decode(gradeObject.skin_female)
+ else
+ self.job.skin_female = {}
end
TriggerEvent('esx:setJob', self.source, self.job, lastJob)
@@ -370,9 +368,9 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
end
self.addWeapon = function(weaponName, ammo)
- local weaponLabel = ESX.GetWeaponLabel(weaponName)
-
if not self.hasWeapon(weaponName) then
+ local weaponLabel = ESX.GetWeaponLabel(weaponName)
+
table.insert(self.loadout, {
name = weaponName,
ammo = ammo,
@@ -381,7 +379,7 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
})
self.triggerEvent('esx:addWeapon', weaponName, ammo)
- self.triggerEvent('esx:addInventoryItem', {label = weaponLabel}, 1)
+ self.triggerEvent('esx:addInventoryItem', weaponLabel, false, true)
end
end
@@ -389,9 +387,14 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
local loadoutNum, weapon = self.getWeapon(weaponName)
if weapon then
- if not self.hasWeaponComponent(weaponName, weaponComponent) then
- table.insert(self.loadout[loadoutNum].components, weaponComponent)
- self.triggerEvent('esx:addWeaponComponent', weaponName, weaponComponent)
+ local component = ESX.GetWeaponComponent(weaponName, weaponComponent)
+
+ if component then
+ if not self.hasWeaponComponent(weaponName, weaponComponent) then
+ table.insert(self.loadout[loadoutNum].components, weaponComponent)
+ self.triggerEvent('esx:addWeaponComponent', weaponName, weaponComponent)
+ self.triggerEvent('esx:addInventoryItem', component.label, false, true)
+ end
end
end
end
@@ -413,7 +416,7 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
weaponLabel = v.label
for k2,v2 in ipairs(v.components) do
- self.triggerEvent('esx:removeWeaponComponent', weaponName, v2)
+ self.removeWeaponComponent(weaponName, v2)
end
table.remove(self.loadout, k)
@@ -423,7 +426,7 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
if weaponLabel then
self.triggerEvent('esx:removeWeapon', weaponName, ammo)
- self.triggerEvent('esx:removeInventoryItem', {label = weaponLabel}, 1)
+ self.triggerEvent('esx:removeInventoryItem', weaponLabel, false, true)
end
end
@@ -431,14 +434,21 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
local loadoutNum, weapon = self.getWeapon(weaponName)
if weapon then
- for k,v in ipairs(self.loadout[loadoutNum].components) do
- if v.name == weaponComponent then
- table.remove(self.loadout[loadoutNum].components, k)
- break
+ local component = ESX.GetWeaponComponent(weaponName, weaponComponent)
+
+ if component then
+ if self.hasWeaponComponent(weaponName, weaponComponent) then
+ for k,v in ipairs(self.loadout[loadoutNum].components) do
+ if v.name == weaponComponent then
+ table.remove(self.loadout[loadoutNum].components, k)
+ break
+ end
+ end
+
+ self.triggerEvent('esx:removeWeaponComponent', weaponName, weaponComponent)
+ self.triggerEvent('esx:removeInventoryItem', component.label, false, true)
end
end
-
- self.triggerEvent('esx:removeWeaponComponent', weaponName, weaponComponent)
end
end
diff --git a/server/commands.lua b/server/commands.lua
index b57a23bf..90c50375 100644
--- a/server/commands.lua
+++ b/server/commands.lua
@@ -129,6 +129,8 @@ TriggerEvent('es:addGroupCommand', 'giveweapon', 'admin', function(source, args,
local weaponName = args[2] or 'unknown'
if ESX.GetWeapon(weaponName) then
+ weaponName = string.upper(weaponName)
+
if xPlayer.hasWeapon(weaponName) then
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Player already has that weapon.' } })
else
@@ -152,19 +154,19 @@ TriggerEvent('es:addGroupCommand', 'giveweaponcomponent', 'admin', function(sour
local xPlayer = ESX.GetPlayerFromId(args[1])
if xPlayer then
- local weapon = args[2] or 'unknown'
+ local weaponName = args[2] or 'unknown'
- if ESX.GetWeapon(weapon) then
- weapon = string.upper(weapon)
+ if ESX.GetWeapon(weaponName) then
+ weaponName = string.upper(weaponName)
- if xPlayer.hasWeapon(weapon) then
- local component = ESX.GetWeaponComponent(weapon, args[3] or 'unknown')
+ if xPlayer.hasWeapon(weaponName) then
+ local component = ESX.GetWeaponComponent(weaponName, args[3] or 'unknown')
if component then
- if xPlayer.hasWeaponComponent(weapon, args[3]) then
+ if xPlayer.hasWeaponComponent(weaponName, args[3]) then
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Player already has that weapon component.' } })
else
- xPlayer.addWeaponComponent(weapon, args[3])
+ xPlayer.addWeaponComponent(weaponName, args[3])
end
else
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Invalid weapon component.' } })
@@ -182,20 +184,14 @@ end, function(source, args, user)
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
end, {help = 'Give weapon component', params = {
{name = 'playerId', help = _U('id_param')},
- {name = 'weapon', help = _U('weapon')},
- {name = 'component', help = 'weapon component'}
+ {name = 'weaponName', help = _U('weapon')},
+ {name = 'componentName', help = 'weapon component'}
}})
TriggerEvent('es:addGroupCommand', 'disc', 'admin', function(source, args, user)
DropPlayer(source, 'You have been disconnected')
end, function(source, args, user)
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
-end)
-
-TriggerEvent('es:addGroupCommand', 'disconnect', 'admin', function(source, args, user)
- DropPlayer(source, 'You have been disconnected')
-end, function(source, args, user)
- TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficient Permissions.' } })
end, {help = _U('disconnect')})
TriggerEvent('es:addGroupCommand', 'clear', 'user', function(source, args, user)
diff --git a/server/main.lua b/server/main.lua
index 78086ea5..16047c86 100644
--- a/server/main.lua
+++ b/server/main.lua
@@ -373,6 +373,8 @@ AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount)
end
end
elseif type == 'item_weapon' then
+ itemName = string.upper(itemName)
+
if xPlayer.hasWeapon(itemName) then
local weaponNum, weapon = xPlayer.getWeapon(itemName)
xPlayer.removeWeapon(itemName)