mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
Implement a new event to receive notifications when a player score has changed.
This commit is contained in:
parent
e9b6d9765b
commit
203dd9802e
@ -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;
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -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.
|
||||
|
@ -381,6 +381,7 @@ enum EventType
|
||||
EVT_PLAYERTEAM,
|
||||
EVT_PLAYERSKIN,
|
||||
EVT_PLAYERMONEY,
|
||||
EVT_PLAYERSCORE,
|
||||
EVT_VEHICLECOLOUR,
|
||||
EVT_VEHICLEHEALTH,
|
||||
EVT_VEHICLEPOSITION,
|
||||
|
Loading…
Reference in New Issue
Block a user