mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-01 10:48:52 +00:00
player.lua: implement canSwapItem() and triggerEvent()
This commit is contained in:
@@ -13,6 +13,10 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, l
|
||||
self.source = self.player.get('source')
|
||||
self.identifier = self.player.get('identifier')
|
||||
|
||||
self.triggerEvent = function(eventName, ...)
|
||||
TriggerClientEvent(eventName, self.source, ...)
|
||||
end
|
||||
|
||||
self.setMoney = function(money)
|
||||
money = ESX.Math.Round(money)
|
||||
|
||||
@@ -389,6 +393,20 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, l
|
||||
return newWeight <= self.maxWeight
|
||||
end
|
||||
|
||||
self.canSwapItem = function(firstItem, firstItemCount, testItem, testItemCount)
|
||||
local firstItemObject = self.getInventoryItem(firstItem)
|
||||
local testItemObject = self.getInventoryItem(testItem)
|
||||
|
||||
if firstItemObject.count >= firstItemCount then
|
||||
local weightWithoutFirstItem = ESX.Math.Round(self.getWeight() - (firstItemObject.weight * firstItemCount))
|
||||
local weightWithTestItem = ESX.Math.Round(weightWithoutFirstItem + (testItemObject.weight * testItemCount))
|
||||
|
||||
return weightWithTestItem <= self.maxWeight
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
self.setMaxWeight = function(newWeight)
|
||||
self.maxWeight = newWeight
|
||||
TriggerClientEvent('esx:setMaxWeight', self.source, self.maxWeight)
|
||||
|
||||
Reference in New Issue
Block a user