Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fferrandini opened this issue Jun 28, 2024 · 0 comments

Comments

@fferrandini
Copy link

`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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant