Skip to content

05. Property support

kyledeluxe edited this page Jul 26, 2020 · 15 revisions

Add property support

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'})

1b. And replace it with:

			table.insert(elements, {label = "Property inventory", value = "property_inventory"})

2a. Then find this code:

			elseif data.current.value == 'room_inventory' then
				OpenRoomInventoryMenu(property, owner)
			elseif data.current.value == 'player_inventory' then
				OpenPlayerInventoryMenu(property, owner)

2b. 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("esx_inventoryhud:openPropertyInventory", inventory)
	end, owner)
end
  1. 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)
;
  1. Open esx_property/server/main.lua` and do the following:

5a. Replace function esx_property:getPropertyInventory with

	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)

5b. 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)

Clone this wiki locally