esx-framework / esx_property

GNU General Public License v3.0
8 stars 23 forks source link

ESX.RegisterServerCallback "esx_property:buyProperty" is not well implemented. #33

Open fferrandini opened 2 months ago

fferrandini commented 2 months ago

`ESX.RegisterServerCallback("esx_property:buyProperty", function(source, cb, PropertyId) local xPlayer = ESX.GetPlayerFromId(source) local Price = Properties[PropertyId].Price if xPlayer.getAccount("bank").money >= Price then xPlayer.removeAccountMoney("bank", Price, "Bought Property") Properties[PropertyId].Owner = xPlayer.identifier Properties[PropertyId].OwnerName = xPlayer.getName() Properties[PropertyId].Owned = true Log("Property Bought", 65280, {{name = "Property Name", value = Properties[PropertyId].Name, inline = true}, {name = "Price", value = ESX.Math.GroupDigits(Price), inline = true}, {name = "Player", value = xPlayer.getName(), inline = true}}, 1) TriggerClientEvent("esx_property:syncProperties", -1, Properties) if Config.OxInventory then exports.ox_inventory:RegisterStash("property-" .. PropertyId, Properties[PropertyId].Name, 15, 100000, xPlayer.identifier) end

end cb(xPlayer.getAccount("bank").money >= Price) end)`

if player has enough money to buy property. example price : 100k

and what he got left after buying is under the property value, the cb() function returns to client false which will prompt user with a "cant afford" msg but he bought the house. gotta leave menu and interact again to see the owner's menu.

i have changed to this and worked :

ESX.RegisterServerCallback("esx_property:buyProperty", function(source, cb, PropertyId) local xPlayer = ESX.GetPlayerFromId(source) local Price = Properties[PropertyId].Price local isBought = false if xPlayer.getAccount("bank").money >= Price then xPlayer.removeAccountMoney("bank", Price, "Bought Property") Properties[PropertyId].Owner = xPlayer.identifier Properties[PropertyId].OwnerName = xPlayer.getName() Properties[PropertyId].Owned = true Log("Property Bought", 65280, {{name = "**Property Name**", value = Properties[PropertyId].Name, inline = true}, {name = "**Price**", value = ESX.Math.GroupDigits(Price), inline = true}, {name = "**Player**", value = xPlayer.getName(), inline = true}}, 1) TriggerClientEvent("esx_property:syncProperties", -1, Properties) if Config.OxInventory then exports.ox_inventory:RegisterStash("property-" .. PropertyId, Properties[PropertyId].Name, 15, 100000, xPlayer.identifier) end isBought = true end cb(isBought) end)