Skip to content

05. Property support

Borea edited this page Jan 8, 2021 · 15 revisions

Add property support (Updated: 19-12-2020)

1a. Open esx_property/client/main.lua` and do the following: Find this code in OpenRoomMenu function:

			table.insert(elements, {label = _U('remove_object'),  value = 'room_inventory'})
			table.insert(elements, {label = _U('deposit_object'), value = 'player_inventory'})
  1. And replace it with:
			table.insert(elements, {label = "Property inventory", value = "property_inventory"})
  1. Then find this code:
			elseif data.current.value == 'room_inventory' then
				OpenRoomInventoryMenu(property, owner)
			elseif data.current.value == 'player_inventory' then
				OpenPlayerInventoryMenu(property, owner)
  1. And replace it with:
			elseif data.current.value == "property_inventory" then
				menu.close()
				OpenPropertyInventoryMenu(property, owner)
  1. And finally add this function:
function OpenPropertyInventoryMenu(property, owner)
	ESX.TriggerServerCallback("esx_property:getPropertyInventory", function(inventory)
		TriggerEvent("DP_Inventory:openPropertyInventory", inventory)
	end, owner)
end

2a. Add this to your database for cash money support: (You must upload the original esx_property .sql file first)

INSERT INTO `addon_account` (name, label, shared) VALUES
  ('property_money','Cash',0),
  ('property_black_money','Black Money',0)
;

3a. Open esx_property/server/main.lua and do the following:

  1. Replace function esx_property:getPropertyInventory with
ESX.RegisterServerCallback('esx_property:getPropertyInventory', function(source, cb, owner)
	local xPlayer    = ESX.GetPlayerFromIdentifier(owner)
	local blackMoney = 0
	local money = 0
	local items      = {}
	local weapons    = {}

	TriggerEvent('esx_addonaccount:getAccount', 'property_black_money', xPlayer.identifier, function(account)
		blackMoney = account.money
	end)

	TriggerEvent('esx_addonaccount:getAccount', 'property_money', xPlayer.identifier, function(account)
		money = account.money
	end)

	TriggerEvent('esx_addoninventory:getInventory', 'property', xPlayer.identifier, function(inventory)
		items = inventory.items
	end)

	TriggerEvent('esx_datastore:getDataStore', 'property', xPlayer.identifier, function(store)
		weapons = store.get('weapons') or {}
	end)

	cb({
		blackMoney = blackMoney,
		items      = items,
		money = money,
		weapons    = weapons
	})
end)
  1. Replace esx_property:getPlayerInventory with
ESX.RegisterServerCallback('esx_property:getPlayerInventory', function(source, cb)
	local xPlayer    = ESX.GetPlayerFromId(source)
	local blackMoney = xPlayer.getAccount('black_money').money
	local money = xPlayer.getAccount('money').money
	local items      = xPlayer.inventory

	cb({
		blackMoney = blackMoney,
		items      = items,
		money = money,
		weapons    = xPlayer.getLoadout()
	})
end)