mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-31 10:18:54 +00:00
Don't parse item object to client, added weapon component notifications (more see desc)
- Removed xPlayer .displayBank() - Fixed issues with giving weapon using commands - Modified ESX.UI.ShowInventoryItemNotification() to take string instead of table - Minor adjustments and variable renames - Fixed lower case weapons not droppable - Removed /disconnect command becasue fivem implemented their own
This commit is contained in:
+59
-49
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user