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 immunity has changed.
This commit is contained in:
parent
8f78b0a852
commit
c6c17e9396
@ -429,6 +429,7 @@ protected:
|
||||
Function mOnMoney;
|
||||
Function mOnScore;
|
||||
Function mOnWantedLevel;
|
||||
Function mOnImmunity;
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1006,6 +1007,7 @@ public:
|
||||
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 EmitPlayerImmunity(Int32 player_id, Int32 old_immunity, Int32 new_immunity);
|
||||
void EmitVehicleColour(Int32 vehicle_id, Int32 changed);
|
||||
void EmitVehicleHealth(Int32 vehicle_id, Float32 old_health, Float32 new_health);
|
||||
void EmitVehiclePosition(Int32 vehicle_id);
|
||||
@ -1150,6 +1152,7 @@ private:
|
||||
Function mOnPlayerMoney;
|
||||
Function mOnPlayerScore;
|
||||
Function mOnPlayerWantedLevel;
|
||||
Function mOnPlayerImmunity;
|
||||
Function mOnVehicleColour;
|
||||
Function mOnVehicleHealth;
|
||||
Function mOnVehiclePosition;
|
||||
|
@ -781,6 +781,14 @@ void Core::EmitPlayerWantedLevel(Int32 player_id, Int32 old_level, Int32 new_lev
|
||||
Emit(mOnPlayerWantedLevel, _player.mObj, old_level, new_level);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::EmitPlayerImmunity(Int32 player_id, Int32 old_immunity, Int32 new_immunity)
|
||||
{
|
||||
PlayerInst & _player = m_Players.at(player_id);
|
||||
Emit(_player.mOnImmunity, old_immunity, new_immunity);
|
||||
Emit(mOnPlayerImmunity, _player.mObj, old_immunity, new_immunity);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::EmitVehicleColour(Int32 vehicle_id, Int32 changed)
|
||||
{
|
||||
|
@ -234,6 +234,7 @@ void Core::ResetFunc(PlayerInst & inst)
|
||||
inst.mOnMoney.ReleaseGently();
|
||||
inst.mOnScore.ReleaseGently();
|
||||
inst.mOnWantedLevel.ReleaseGently();
|
||||
inst.mOnImmunity.ReleaseGently();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -355,6 +356,7 @@ void Core::ResetFunc()
|
||||
Core::Get().mOnPlayerMoney.ReleaseGently();
|
||||
Core::Get().mOnPlayerScore.ReleaseGently();
|
||||
Core::Get().mOnPlayerWantedLevel.ReleaseGently();
|
||||
Core::Get().mOnPlayerImmunity.ReleaseGently();
|
||||
Core::Get().mOnVehicleColour.ReleaseGently();
|
||||
Core::Get().mOnVehicleHealth.ReleaseGently();
|
||||
Core::Get().mOnVehiclePosition.ReleaseGently();
|
||||
@ -468,6 +470,7 @@ Function & Core::GetEvent(Int32 evid)
|
||||
case EVT_PLAYERMONEY: return mOnPlayerMoney;
|
||||
case EVT_PLAYERSCORE: return mOnPlayerScore;
|
||||
case EVT_PLAYERWANTEDLEVEL: return mOnPlayerWantedLevel;
|
||||
case EVT_PLAYERIMMUNITY: return mOnPlayerImmunity;
|
||||
case EVT_VEHICLECOLOUR: return mOnVehicleColour;
|
||||
case EVT_VEHICLEHEALTH: return mOnVehicleHealth;
|
||||
case EVT_VEHICLEPOSITION: return mOnVehiclePosition;
|
||||
@ -631,6 +634,7 @@ Function & Core::GetPlayerEvent(Int32 id, Int32 evid)
|
||||
case EVT_PLAYERMONEY: return inst.mOnMoney;
|
||||
case EVT_PLAYERSCORE: return inst.mOnScore;
|
||||
case EVT_PLAYERWANTEDLEVEL: return inst.mOnWantedLevel;
|
||||
case EVT_PLAYERIMMUNITY: return inst.mOnImmunity;
|
||||
default: return NullFunction();
|
||||
}
|
||||
}
|
||||
|
@ -821,12 +821,22 @@ Int32 CPlayer::GetImmunity() const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CPlayer::SetImmunity(Int32 flags) const
|
||||
void CPlayer::SetImmunity(Int32 flags)
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
// Grab the current value for this property
|
||||
const Int32 current = _Func->GetPlayerImmunityFlags(m_ID);
|
||||
// Avoid property unwind from a recursive call
|
||||
_Func->SetPlayerImmunityFlags(m_ID, flags);
|
||||
// Avoid infinite recursive event loops
|
||||
if (!(m_CircularLocks & PCL_EMIT_PLAYER_IMMUNITY))
|
||||
{
|
||||
// Prevent this event from triggering while executed
|
||||
BitGuardU32 bg(m_CircularLocks, PCL_EMIT_PLAYER_IMMUNITY);
|
||||
// Now forward the event call
|
||||
Core::Get().EmitPlayerImmunity(m_ID, current, flags);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -21,6 +21,7 @@ enum PlayerCircularLocks
|
||||
PCL_EMIT_PLAYER_MONEY = (6 << 0),
|
||||
PCL_EMIT_PLAYER_SCORE = (7 << 0),
|
||||
PCL_EMIT_PLAYER_WANTED_LEVEL = (8 << 0),
|
||||
PCL_EMIT_PLAYER_IMMUNITY = (9 << 0),
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@ -490,7 +491,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the immunity flags of the managed player entity.
|
||||
*/
|
||||
void SetImmunity(Int32 flags) const;
|
||||
void SetImmunity(Int32 flags);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the position of the managed player entity.
|
||||
|
@ -383,6 +383,7 @@ enum EventType
|
||||
EVT_PLAYERMONEY,
|
||||
EVT_PLAYERSCORE,
|
||||
EVT_PLAYERWANTEDLEVEL,
|
||||
EVT_PLAYERIMMUNITY,
|
||||
EVT_VEHICLECOLOUR,
|
||||
EVT_VEHICLEHEALTH,
|
||||
EVT_VEHICLEPOSITION,
|
||||
|
Loading…
Reference in New Issue
Block a user