mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-10-15 07:27:19 +02:00
Implement a new event to receive notifications when a player money has changed.
This commit is contained in:
@@ -649,21 +649,46 @@ Int32 CPlayer::GetMoney() const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CPlayer::SetMoney(Int32 amount) const
|
||||
void CPlayer::SetMoney(Int32 amount)
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
// Grab the current value for this property
|
||||
const Int32 current = _Func->GetPlayerMoney(m_ID);
|
||||
// Don't even bother if it's the same value
|
||||
if (current == amount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Avoid property unwind from a recursive call
|
||||
_Func->SetPlayerMoney(m_ID, amount);
|
||||
// Avoid infinite recursive event loops
|
||||
if (!(m_CircularLocks & PCL_EMIT_PLAYER_MONEY))
|
||||
{
|
||||
// Prevent this event from triggering while executed
|
||||
BitGuardU32 bg(m_CircularLocks, PCL_EMIT_PLAYER_MONEY);
|
||||
// Now forward the event call
|
||||
Core::Get().EmitPlayerMoney(m_ID, current, amount);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CPlayer::GiveMoney(Int32 amount) const
|
||||
void CPlayer::GiveMoney(Int32 amount)
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
// Grab the current value for this property
|
||||
const Int32 current = _Func->GetPlayerMoney(m_ID);
|
||||
// Avoid property unwind from a recursive call
|
||||
_Func->GivePlayerMoney(m_ID, amount);
|
||||
// Avoid infinite recursive event loops
|
||||
if (!(m_CircularLocks & PCL_EMIT_PLAYER_MONEY))
|
||||
{
|
||||
// Prevent this event from triggering while executed
|
||||
BitGuardU32 bg(m_CircularLocks, PCL_EMIT_PLAYER_MONEY);
|
||||
// Now forward the event call
|
||||
Core::Get().EmitPlayerMoney(m_ID, current, current + amount);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@@ -18,6 +18,7 @@ enum PlayerCircularLocks
|
||||
PCL_EMIT_PLAYER_WORLD = (3 << 0),
|
||||
PCL_EMIT_PLAYER_TEAM = (4 << 0),
|
||||
PCL_EMIT_PLAYER_SKIN = (5 << 0),
|
||||
PCL_EMIT_PLAYER_MONEY = (6 << 0),
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@@ -422,12 +423,12 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the money amount of the managed player entity.
|
||||
*/
|
||||
void SetMoney(Int32 amount) const;
|
||||
void SetMoney(Int32 amount);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Give a certain amount of money to the managed player entity.
|
||||
*/
|
||||
void GiveMoney(Int32 amount) const;
|
||||
void GiveMoney(Int32 amount);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the score of the managed player entity.
|
||||
|
Reference in New Issue
Block a user