1
0
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 team has changed.

This commit is contained in:
Sandu Liviu Catalin
2016-08-17 15:49:08 +03:00
parent 84bae9432a
commit ad774fcb3f
6 changed files with 36 additions and 4 deletions

View File

@@ -510,15 +510,30 @@ Int32 CPlayer::GetTeam() const
}
// ------------------------------------------------------------------------------------------------
void CPlayer::SetTeam(Int32 team) const
void CPlayer::SetTeam(Int32 team)
{
// Validate the managed identifier
Validate();
// Perform the requested operation
if (_Func->SetPlayerTeam(m_ID, team) == vcmpErrorArgumentOutOfBounds)
// Grab the current value for this property
const Int32 current = _Func->GetPlayerTeam(m_ID);
// Don't even bother if it's the same value
if (current == team)
{
return;
}
// Avoid property unwind from a recursive call
else if (_Func->SetPlayerTeam(m_ID, team) == vcmpErrorArgumentOutOfBounds)
{
STHROWF("Invalid team identifier: %d", team);
}
// Avoid infinite recursive event loops
else if (!(m_CircularLocks & PCL_EMIT_PLAYER_TEAM))
{
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, PCL_EMIT_PLAYER_TEAM);
// Now forward the event call
Core::Get().EmitPlayerTeam(m_ID, current, team);
}
}
// ------------------------------------------------------------------------------------------------

View File

@@ -16,6 +16,7 @@ enum PlayerCircularLocks
PCL_EMIT_PLAYER_OPTION = (1 << 0)
PCL_EMIT_PLAYER_ADMIN = (2 << 0),
PCL_EMIT_PLAYER_WORLD = (3 << 0),
PCL_EMIT_PLAYER_TEAM = (4 << 0),
};
/* ------------------------------------------------------------------------------------------------
@@ -365,7 +366,7 @@ public:
/* --------------------------------------------------------------------------------------------
* Modify the team of the managed player entity.
*/
void SetTeam(Int32 team) const;
void SetTeam(Int32 team);
/* --------------------------------------------------------------------------------------------
* Retrieve the skin identifier of the managed player entity.