Skip to content

fix(esx_property): report whether the property was actually sold - #136

Open
seltonmt012 wants to merge 1 commit into
esx-framework:1.14.1from
seltonmt012:fix/property-sell-result
Open

fix(esx_property): report whether the property was actually sold#136
seltonmt012 wants to merge 1 commit into
esx-framework:1.14.1from
seltonmt012:fix/property-sell-result

Conversation

@seltonmt012

Copy link
Copy Markdown

Description

attemptSellToPlayer tells the client whether the agent can afford the property, measured after the agent was paid, instead of whether the sale happened.


Motivation

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

xPlayer is the estate agent running the command. xTarget is the buyer, and the buyer's money is what decides the sale. The agent's balance has nothing to do with it, and by the time this line runs the agent has already been credited the commission, so the number being compared is not even the one from the start of the call.

Both directions go wrong, and the client acts on the answer:

ESX.TriggerServerCallback("esx_property:attemptSellToPlayer", function(IsBought)
    if IsBought then
        -- refresh the property menu
    else
        ESX.ShowNotification(TranslateCap("cannot_sell"), "error")
    end
end, PropertyId, element.value)

An agent with a thin bank account sells a property and is told "cannot sell" while the keys have already moved. A wealthy agent gets a refreshed menu as if the sale went through when the buyer could not pay, had disconnected, or the agent was not even in the estate agent job.


Implementation Details

buyProperty, directly above in the same file, already has the shape this one is missing: put the condition in a local before any money moves, then hand that local to cb. This change makes attemptSellToPlayer match it.

Driven against the shipped callback with a price of 1000 and the default 25 percent commission:

case property sold answered before answered after
buyer can pay, agent broke yes false true
buyer cannot pay, agent rich no true false
buyer can pay, agent rich yes true true
agent has the wrong job no true false
buyer disconnected no true false

Four of the five answers contradicted what actually happened. The one that was right is the happy path, which is why this holds up in normal use and only shows itself when something goes wrong.


Usage Example

-- estate agent with an empty bank account sells a property to a buyer who can pay
-- before: "You cannot sell this property", but the buyer already owns it
-- after:  the menu refreshes and shows the new owner

PR Checklist

  • My commit messages and PR title follow the Conventional Commits standard.
  • My changes have been tested locally and function as expected.
  • My PR does not introduce any breaking changes.
  • I have provided a clear explanation of what my PR does, including the reasoning behind the changes and any relevant context.

Nothing about who gets the property or the money changes, only the answer sent back to the client.

Tested headless against the shipped file, not with two clients on a live server.

attemptSellToPlayer answered the client with the agent's own bank balance,
read after the commission had been credited. The buyer, whose money decides
the sale, was never part of the answer.

Both directions are wrong. A broke agent who sold successfully got "cannot
sell" while the property had already changed hands, and a rich agent got a
refreshed menu as if the sale went through when the buyer could not pay, had
disconnected, or the agent held the wrong job.

buyProperty right above already has the shape: put the condition in a local
before any money moves, then hand that local to cb. This does the same.

Driven against the shipped callback, price 1000 with the default 25 percent
commission. The answer disagreed with what happened in four of five cases
before and agrees in all five now:

  buyer can pay, agent broke        sold, answered false -> true
  buyer cannot pay, agent rich      not sold, answered true -> false
  buyer can pay, agent rich         sold, answered true, unchanged
  agent has the wrong job           not sold, answered true -> false
  buyer disconnected                not sold, answered true -> false
@seltonmt012
seltonmt012 force-pushed the fix/property-sell-result branch from e63fd74 to 2e7bff4 Compare August 8, 2026 18:25
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

Successfully merging this pull request may close these issues.

1 participant