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 wanted level has changed.
This commit is contained in:
parent
203dd9802e
commit
8f78b0a852
@ -428,6 +428,7 @@ protected:
|
||||
Function mOnSkin;
|
||||
Function mOnMoney;
|
||||
Function mOnScore;
|
||||
Function mOnWantedLevel;
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1004,6 +1005,7 @@ public:
|
||||
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 EmitPlayerWantedLevel(Int32 player_id, Int32 old_level, Int32 new_level);
|
||||
void EmitVehicleColour(Int32 vehicle_id, Int32 changed);
|
||||
void EmitVehicleHealth(Int32 vehicle_id, Float32 old_health, Float32 new_health);
|
||||
void EmitVehiclePosition(Int32 vehicle_id);
|
||||
@ -1147,6 +1149,7 @@ private:
|
||||
Function mOnPlayerSkin;
|
||||
Function mOnPlayerMoney;
|
||||
Function mOnPlayerScore;
|
||||
Function mOnPlayerWantedLevel;
|
||||
Function mOnVehicleColour;
|
||||
Function mOnVehicleHealth;
|
||||
Function mOnVehiclePosition;
|
||||
|
@ -773,6 +773,14 @@ void Core::EmitPlayerScore(Int32 player_id, Int32 old_score, Int32 new_score)
|
||||
Emit(mOnPlayerScore, _player.mObj, old_score, new_score);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::EmitPlayerWantedLevel(Int32 player_id, Int32 old_level, Int32 new_level)
|
||||
{
|
||||
PlayerInst & _player = m_Players.at(player_id);
|
||||
Emit(_player.mOnWantedLevel, old_level, new_level);
|
||||
Emit(mOnPlayerWantedLevel, _player.mObj, old_level, new_level);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::EmitVehicleColour(Int32 vehicle_id, Int32 changed)
|
||||
{
|
||||
|
@ -233,6 +233,7 @@ void Core::ResetFunc(PlayerInst & inst)
|
||||
inst.mOnSkin.ReleaseGently();
|
||||
inst.mOnMoney.ReleaseGently();
|
||||
inst.mOnScore.ReleaseGently();
|
||||
inst.mOnWantedLevel.ReleaseGently();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -353,6 +354,7 @@ void Core::ResetFunc()
|
||||
Core::Get().mOnPlayerSkin.ReleaseGently();
|
||||
Core::Get().mOnPlayerMoney.ReleaseGently();
|
||||
Core::Get().mOnPlayerScore.ReleaseGently();
|
||||
Core::Get().mOnPlayerWantedLevel.ReleaseGently();
|
||||
Core::Get().mOnVehicleColour.ReleaseGently();
|
||||
Core::Get().mOnVehicleHealth.ReleaseGently();
|
||||
Core::Get().mOnVehiclePosition.ReleaseGently();
|
||||
@ -465,6 +467,7 @@ Function & Core::GetEvent(Int32 evid)
|
||||
case EVT_PLAYERSKIN: return mOnPlayerSkin;
|
||||
case EVT_PLAYERMONEY: return mOnPlayerMoney;
|
||||
case EVT_PLAYERSCORE: return mOnPlayerScore;
|
||||
case EVT_PLAYERWANTEDLEVEL: return mOnPlayerWantedLevel;
|
||||
case EVT_VEHICLECOLOUR: return mOnVehicleColour;
|
||||
case EVT_VEHICLEHEALTH: return mOnVehicleHealth;
|
||||
case EVT_VEHICLEPOSITION: return mOnVehiclePosition;
|
||||
@ -627,6 +630,7 @@ Function & Core::GetPlayerEvent(Int32 id, Int32 evid)
|
||||
case EVT_PLAYERSKIN: return inst.mOnSkin;
|
||||
case EVT_PLAYERMONEY: return inst.mOnMoney;
|
||||
case EVT_PLAYERSCORE: return inst.mOnScore;
|
||||
case EVT_PLAYERWANTEDLEVEL: return inst.mOnWantedLevel;
|
||||
default: return NullFunction();
|
||||
}
|
||||
}
|
||||
|
@ -734,12 +734,27 @@ Int32 CPlayer::GetWantedLevel() const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CPlayer::SetWantedLevel(Int32 level) const
|
||||
void CPlayer::SetWantedLevel(Int32 level)
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
// Grab the current value for this property
|
||||
const Int32 current = _Func->GetPlayerWantedLevel(m_ID);
|
||||
// Don't even bother if it's the same value
|
||||
if (current == level)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Avoid property unwind from a recursive call
|
||||
_Func->SetPlayerWantedLevel(m_ID, level);
|
||||
// Avoid infinite recursive event loops
|
||||
if (!(m_CircularLocks & PCL_EMIT_PLAYER_WANTED_LEVEL))
|
||||
{
|
||||
// Prevent this event from triggering while executed
|
||||
BitGuardU32 bg(m_CircularLocks, PCL_EMIT_PLAYER_WANTED_LEVEL);
|
||||
// Now forward the event call
|
||||
Core::Get().EmitPlayerWantedLevel(m_ID, current, level);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -20,6 +20,7 @@ enum PlayerCircularLocks
|
||||
PCL_EMIT_PLAYER_SKIN = (5 << 0),
|
||||
PCL_EMIT_PLAYER_MONEY = (6 << 0),
|
||||
PCL_EMIT_PLAYER_SCORE = (7 << 0),
|
||||
PCL_EMIT_PLAYER_WANTED_LEVEL = (8 << 0),
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@ -449,7 +450,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the wanted level of the managed player entity.
|
||||
*/
|
||||
void SetWantedLevel(Int32 level) const;
|
||||
void SetWantedLevel(Int32 level);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the connection latency of the managed player entity.
|
||||
|
@ -382,6 +382,7 @@ enum EventType
|
||||
EVT_PLAYERSKIN,
|
||||
EVT_PLAYERMONEY,
|
||||
EVT_PLAYERSCORE,
|
||||
EVT_PLAYERWANTEDLEVEL,
|
||||
EVT_VEHICLECOLOUR,
|
||||
EVT_VEHICLEHEALTH,
|
||||
EVT_VEHICLEPOSITION,
|
||||
|
Loading…
Reference in New Issue
Block a user