1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-08-20 06:47:09 +02:00

Implement a new event to receive notifications when a player score has changed.

This commit is contained in:
Sandu Liviu Catalin
2016-08-17 16:00:28 +03:00
parent e9b6d9765b
commit 203dd9802e
6 changed files with 35 additions and 3 deletions

View File

@@ -701,12 +701,27 @@ Int32 CPlayer::GetScore() const
}
// ------------------------------------------------------------------------------------------------
void CPlayer::SetScore(Int32 score) const
void CPlayer::SetScore(Int32 score)
{
// Validate the managed identifier
Validate();
// Perform the requested operation
// Grab the current value for this property
const Int32 current = _Func->GetPlayerScore(m_ID);
// Don't even bother if it's the same value
if (current == score)
{
return;
}
// Avoid property unwind from a recursive call
_Func->SetPlayerScore(m_ID, score);
// Avoid infinite recursive event loops
if (!(m_CircularLocks & PCL_EMIT_PLAYER_SCORE))
{
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, PCL_EMIT_PLAYER_SCORE);
// Now forward the event call
Core::Get().EmitPlayerScore(m_ID, current, score);
}
}
// ------------------------------------------------------------------------------------------------

View File

@@ -19,6 +19,7 @@ enum PlayerCircularLocks
PCL_EMIT_PLAYER_TEAM = (4 << 0),
PCL_EMIT_PLAYER_SKIN = (5 << 0),
PCL_EMIT_PLAYER_MONEY = (6 << 0),
PCL_EMIT_PLAYER_SCORE = (7 << 0),
};
/* ------------------------------------------------------------------------------------------------
@@ -438,7 +439,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the score of the managed player entity.
*/
void SetScore(Int32 score) const;
void SetScore(Int32 score);
/* --------------------------------------------------------------------------------------------
* Retrieve the wanted level of the managed player entity.