diff --git a/source/Core.hpp b/source/Core.hpp index 8d4f767d..5256c804 100644 --- a/source/Core.hpp +++ b/source/Core.hpp @@ -427,6 +427,7 @@ protected: Function mOnTeam; Function mOnSkin; Function mOnMoney; + Function mOnScore; }; /* -------------------------------------------------------------------------------------------- @@ -1002,6 +1003,7 @@ public: void EmitPlayerTeam(Int32 player_id, Int32 old_team, Int32 new_team); void EmitPlayerSkin(Int32 player_id, Int32 old_skin, Int32 new_skin); void EmitPlayerMoney(Int32 player_id, Int32 old_money, Int32 new_money); + void EmitPlayerScore(Int32 player_id, Int32 old_score, Int32 new_score); void EmitVehicleColour(Int32 vehicle_id, Int32 changed); void EmitVehicleHealth(Int32 vehicle_id, Float32 old_health, Float32 new_health); void EmitVehiclePosition(Int32 vehicle_id); @@ -1144,6 +1146,7 @@ private: Function mOnPlayerTeam; Function mOnPlayerSkin; Function mOnPlayerMoney; + Function mOnPlayerScore; Function mOnVehicleColour; Function mOnVehicleHealth; Function mOnVehiclePosition; diff --git a/source/CoreEvents.cpp b/source/CoreEvents.cpp index 58735837..7f7195e5 100644 --- a/source/CoreEvents.cpp +++ b/source/CoreEvents.cpp @@ -765,6 +765,14 @@ void Core::EmitPlayerMoney(Int32 player_id, Int32 old_money, Int32 new_money) Emit(mOnPlayerMoney, _player.mObj, old_money, new_money); } +// ------------------------------------------------------------------------------------------------ +void Core::EmitPlayerScore(Int32 player_id, Int32 old_score, Int32 new_score) +{ + PlayerInst & _player = m_Players.at(player_id); + Emit(_player.mOnScore, old_score, new_score); + Emit(mOnPlayerScore, _player.mObj, old_score, new_score); +} + // ------------------------------------------------------------------------------------------------ void Core::EmitVehicleColour(Int32 vehicle_id, Int32 changed) { diff --git a/source/CoreUtils.cpp b/source/CoreUtils.cpp index 3da96a7a..d146d99e 100644 --- a/source/CoreUtils.cpp +++ b/source/CoreUtils.cpp @@ -232,6 +232,7 @@ void Core::ResetFunc(PlayerInst & inst) inst.mOnTeam.ReleaseGently(); inst.mOnSkin.ReleaseGently(); inst.mOnMoney.ReleaseGently(); + inst.mOnScore.ReleaseGently(); } // ------------------------------------------------------------------------------------------------ @@ -351,6 +352,7 @@ void Core::ResetFunc() Core::Get().mOnPlayerTeam.ReleaseGently(); Core::Get().mOnPlayerSkin.ReleaseGently(); Core::Get().mOnPlayerMoney.ReleaseGently(); + Core::Get().mOnPlayerScore.ReleaseGently(); Core::Get().mOnVehicleColour.ReleaseGently(); Core::Get().mOnVehicleHealth.ReleaseGently(); Core::Get().mOnVehiclePosition.ReleaseGently(); @@ -462,6 +464,7 @@ Function & Core::GetEvent(Int32 evid) case EVT_PLAYERTEAM: return mOnPlayerTeam; case EVT_PLAYERSKIN: return mOnPlayerSkin; case EVT_PLAYERMONEY: return mOnPlayerMoney; + case EVT_PLAYERSCORE: return mOnPlayerScore; case EVT_VEHICLECOLOUR: return mOnVehicleColour; case EVT_VEHICLEHEALTH: return mOnVehicleHealth; case EVT_VEHICLEPOSITION: return mOnVehiclePosition; @@ -623,6 +626,7 @@ Function & Core::GetPlayerEvent(Int32 id, Int32 evid) case EVT_PLAYERTEAM: return inst.mOnTeam; case EVT_PLAYERSKIN: return inst.mOnSkin; case EVT_PLAYERMONEY: return inst.mOnMoney; + case EVT_PLAYERSCORE: return inst.mOnScore; default: return NullFunction(); } } diff --git a/source/Entity/Player.cpp b/source/Entity/Player.cpp index 0e44c6d1..e84e9854 100644 --- a/source/Entity/Player.cpp +++ b/source/Entity/Player.cpp @@ -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); + } } // ------------------------------------------------------------------------------------------------ diff --git a/source/Entity/Player.hpp b/source/Entity/Player.hpp index b6115de9..7cd35c15 100644 --- a/source/Entity/Player.hpp +++ b/source/Entity/Player.hpp @@ -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. diff --git a/source/SqBase.hpp b/source/SqBase.hpp index ed9847d7..5f0d6c0f 100644 --- a/source/SqBase.hpp +++ b/source/SqBase.hpp @@ -381,6 +381,7 @@ enum EventType EVT_PLAYERTEAM, EVT_PLAYERSKIN, EVT_PLAYERMONEY, + EVT_PLAYERSCORE, EVT_VEHICLECOLOUR, EVT_VEHICLEHEALTH, EVT_VEHICLEPOSITION,