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 team has changed.
This commit is contained in:
parent
84bae9432a
commit
ad774fcb3f
@ -424,6 +424,7 @@ protected:
|
||||
Function mOnOption;
|
||||
Function mOnAdmin;
|
||||
Function mOnWorld;
|
||||
Function mOnTeam;
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -996,6 +997,7 @@ public:
|
||||
void EmitPlayerOption(Int32 player_id, Int32 option_id, bool value, Int32 header, Object & payload);
|
||||
void EmitPlayerAdmin(Int32 player_id, bool old_admin, bool new_admin);
|
||||
void EmitPlayerWorld(Int32 player_id, Int32 old_world, Int32 new_world, bool secondary);
|
||||
void EmitPlayerTeam(Int32 player_id, Int32 old_team, Int32 new_team);
|
||||
void EmitVehicleColour(Int32 vehicle_id, Int32 changed);
|
||||
void EmitVehicleHealth(Int32 vehicle_id, Float32 old_health, Float32 new_health);
|
||||
void EmitVehiclePosition(Int32 vehicle_id);
|
||||
@ -1135,6 +1137,7 @@ private:
|
||||
Function mOnPlayerOption;
|
||||
Function mOnPlayerAdmin;
|
||||
Function mOnPlayerWorld;
|
||||
Function mOnPlayerTeam;
|
||||
Function mOnVehicleColour;
|
||||
Function mOnVehicleHealth;
|
||||
Function mOnVehiclePosition;
|
||||
|
@ -741,6 +741,14 @@ void Core::EmitPlayerWorld(Int32 player_id, Int32 old_world, Int32 new_world, bo
|
||||
Emit(mOnPlayerWorld, _player.mObj, old_world, new_world, secondary);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::EmitPlayerTeam(Int32 player_id, Int32 old_team, Int32 new_team)
|
||||
{
|
||||
PlayerInst & _player = m_Players.at(player_id);
|
||||
Emit(_player.mOnTeam, old_team, new_team);
|
||||
Emit(mOnPlayerTeam, _player.mObj, old_team, new_team);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::EmitVehicleColour(Int32 vehicle_id, Int32 changed)
|
||||
{
|
||||
|
@ -229,6 +229,7 @@ void Core::ResetFunc(PlayerInst & inst)
|
||||
inst.mOnOption.ReleaseGently();
|
||||
inst.mOnAdmin.ReleaseGently();
|
||||
inst.mOnWorld.ReleaseGently();
|
||||
inst.mOnTeam.ReleaseGently();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -345,6 +346,7 @@ void Core::ResetFunc()
|
||||
Core::Get().mOnPlayerOption.ReleaseGently();
|
||||
Core::Get().mOnPlayerAdmin.ReleaseGently();
|
||||
Core::Get().mOnPlayerWorld.ReleaseGently();
|
||||
Core::Get().mOnPlayerTeam.ReleaseGently();
|
||||
Core::Get().mOnVehicleColour.ReleaseGently();
|
||||
Core::Get().mOnVehicleHealth.ReleaseGently();
|
||||
Core::Get().mOnVehiclePosition.ReleaseGently();
|
||||
@ -453,6 +455,7 @@ Function & Core::GetEvent(Int32 evid)
|
||||
case EVT_PLAYEROPTION: return mOnPlayerOption;
|
||||
case EVT_PLAYERADMIN: return mOnPlayerAdmin;
|
||||
case EVT_PLAYERWORLD: return mOnPlayerWorld;
|
||||
case EVT_PLAYERTEAM: return mOnPlayerTeam;
|
||||
case EVT_VEHICLECOLOUR: return mOnVehicleColour;
|
||||
case EVT_VEHICLEHEALTH: return mOnVehicleHealth;
|
||||
case EVT_VEHICLEPOSITION: return mOnVehiclePosition;
|
||||
@ -611,6 +614,7 @@ Function & Core::GetPlayerEvent(Int32 id, Int32 evid)
|
||||
case EVT_PLAYEROPTION: return inst.mOnOption;
|
||||
case EVT_PLAYERADMIN: return inst.mOnAdmin;
|
||||
case EVT_PLAYERWORLD: return inst.mOnWorld;
|
||||
case EVT_PLAYERTEAM: return inst.mOnTeam;
|
||||
default: return NullFunction();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -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.
|
||||
|
@ -378,6 +378,7 @@ enum EventType
|
||||
EVT_PLAYEROPTION,
|
||||
EVT_PLAYERADMIN,
|
||||
EVT_PLAYERWORLD,
|
||||
EVT_PLAYERTEAM,
|
||||
EVT_VEHICLECOLOUR,
|
||||
EVT_VEHICLEHEALTH,
|
||||
EVT_VEHICLEPOSITION,
|
||||
|
Loading…
Reference in New Issue
Block a user