1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-04-30 08:07:12 +02:00

Implement a new event to receive notifications when a player money has changed.

This commit is contained in:
Sandu Liviu Catalin 2016-08-17 15:55:59 +03:00
parent 16f35cbef6
commit e9b6d9765b
6 changed files with 48 additions and 6 deletions

View File

@ -426,6 +426,7 @@ protected:
Function mOnWorld; Function mOnWorld;
Function mOnTeam; Function mOnTeam;
Function mOnSkin; Function mOnSkin;
Function mOnMoney;
}; };
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
@ -1000,6 +1001,7 @@ public:
void EmitPlayerWorld(Int32 player_id, Int32 old_world, Int32 new_world, bool secondary); 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 EmitPlayerTeam(Int32 player_id, Int32 old_team, Int32 new_team);
void EmitPlayerSkin(Int32 player_id, Int32 old_skin, Int32 new_skin); void EmitPlayerSkin(Int32 player_id, Int32 old_skin, Int32 new_skin);
void EmitPlayerMoney(Int32 player_id, Int32 old_money, Int32 new_money);
void EmitVehicleColour(Int32 vehicle_id, Int32 changed); void EmitVehicleColour(Int32 vehicle_id, Int32 changed);
void EmitVehicleHealth(Int32 vehicle_id, Float32 old_health, Float32 new_health); void EmitVehicleHealth(Int32 vehicle_id, Float32 old_health, Float32 new_health);
void EmitVehiclePosition(Int32 vehicle_id); void EmitVehiclePosition(Int32 vehicle_id);
@ -1141,6 +1143,7 @@ private:
Function mOnPlayerWorld; Function mOnPlayerWorld;
Function mOnPlayerTeam; Function mOnPlayerTeam;
Function mOnPlayerSkin; Function mOnPlayerSkin;
Function mOnPlayerMoney;
Function mOnVehicleColour; Function mOnVehicleColour;
Function mOnVehicleHealth; Function mOnVehicleHealth;
Function mOnVehiclePosition; Function mOnVehiclePosition;

View File

@ -757,6 +757,14 @@ void Core::EmitPlayerSkin(Int32 player_id, Int32 old_skin, Int32 new_skin)
Emit(mOnPlayerSkin, _player.mObj, old_skin, new_skin); Emit(mOnPlayerSkin, _player.mObj, old_skin, new_skin);
} }
// ------------------------------------------------------------------------------------------------
void Core::EmitPlayerMoney(Int32 player_id, Int32 old_money, Int32 new_money)
{
PlayerInst & _player = m_Players.at(player_id);
Emit(_player.mOnMoney, old_money, new_money);
Emit(mOnPlayerMoney, _player.mObj, old_money, new_money);
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void Core::EmitVehicleColour(Int32 vehicle_id, Int32 changed) void Core::EmitVehicleColour(Int32 vehicle_id, Int32 changed)
{ {

View File

@ -231,6 +231,7 @@ void Core::ResetFunc(PlayerInst & inst)
inst.mOnWorld.ReleaseGently(); inst.mOnWorld.ReleaseGently();
inst.mOnTeam.ReleaseGently(); inst.mOnTeam.ReleaseGently();
inst.mOnSkin.ReleaseGently(); inst.mOnSkin.ReleaseGently();
inst.mOnMoney.ReleaseGently();
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -349,6 +350,7 @@ void Core::ResetFunc()
Core::Get().mOnPlayerWorld.ReleaseGently(); Core::Get().mOnPlayerWorld.ReleaseGently();
Core::Get().mOnPlayerTeam.ReleaseGently(); Core::Get().mOnPlayerTeam.ReleaseGently();
Core::Get().mOnPlayerSkin.ReleaseGently(); Core::Get().mOnPlayerSkin.ReleaseGently();
Core::Get().mOnPlayerMoney.ReleaseGently();
Core::Get().mOnVehicleColour.ReleaseGently(); Core::Get().mOnVehicleColour.ReleaseGently();
Core::Get().mOnVehicleHealth.ReleaseGently(); Core::Get().mOnVehicleHealth.ReleaseGently();
Core::Get().mOnVehiclePosition.ReleaseGently(); Core::Get().mOnVehiclePosition.ReleaseGently();
@ -459,6 +461,7 @@ Function & Core::GetEvent(Int32 evid)
case EVT_PLAYERWORLD: return mOnPlayerWorld; case EVT_PLAYERWORLD: return mOnPlayerWorld;
case EVT_PLAYERTEAM: return mOnPlayerTeam; case EVT_PLAYERTEAM: return mOnPlayerTeam;
case EVT_PLAYERSKIN: return mOnPlayerSkin; case EVT_PLAYERSKIN: return mOnPlayerSkin;
case EVT_PLAYERMONEY: return mOnPlayerMoney;
case EVT_VEHICLECOLOUR: return mOnVehicleColour; case EVT_VEHICLECOLOUR: return mOnVehicleColour;
case EVT_VEHICLEHEALTH: return mOnVehicleHealth; case EVT_VEHICLEHEALTH: return mOnVehicleHealth;
case EVT_VEHICLEPOSITION: return mOnVehiclePosition; case EVT_VEHICLEPOSITION: return mOnVehiclePosition;
@ -619,6 +622,7 @@ Function & Core::GetPlayerEvent(Int32 id, Int32 evid)
case EVT_PLAYERWORLD: return inst.mOnWorld; case EVT_PLAYERWORLD: return inst.mOnWorld;
case EVT_PLAYERTEAM: return inst.mOnTeam; case EVT_PLAYERTEAM: return inst.mOnTeam;
case EVT_PLAYERSKIN: return inst.mOnSkin; case EVT_PLAYERSKIN: return inst.mOnSkin;
case EVT_PLAYERMONEY: return inst.mOnMoney;
default: return NullFunction(); default: return NullFunction();
} }
} }

View File

@ -649,21 +649,46 @@ Int32 CPlayer::GetMoney() const
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void CPlayer::SetMoney(Int32 amount) const void CPlayer::SetMoney(Int32 amount)
{ {
// Validate the managed identifier // Validate the managed identifier
Validate(); Validate();
// Perform the requested operation // Grab the current value for this property
const Int32 current = _Func->GetPlayerMoney(m_ID);
// Don't even bother if it's the same value
if (current == amount)
{
return;
}
// Avoid property unwind from a recursive call
_Func->SetPlayerMoney(m_ID, amount); _Func->SetPlayerMoney(m_ID, amount);
// Avoid infinite recursive event loops
if (!(m_CircularLocks & PCL_EMIT_PLAYER_MONEY))
{
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, PCL_EMIT_PLAYER_MONEY);
// Now forward the event call
Core::Get().EmitPlayerMoney(m_ID, current, amount);
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void CPlayer::GiveMoney(Int32 amount) const void CPlayer::GiveMoney(Int32 amount)
{ {
// Validate the managed identifier // Validate the managed identifier
Validate(); Validate();
// Perform the requested operation // Grab the current value for this property
const Int32 current = _Func->GetPlayerMoney(m_ID);
// Avoid property unwind from a recursive call
_Func->GivePlayerMoney(m_ID, amount); _Func->GivePlayerMoney(m_ID, amount);
// Avoid infinite recursive event loops
if (!(m_CircularLocks & PCL_EMIT_PLAYER_MONEY))
{
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, PCL_EMIT_PLAYER_MONEY);
// Now forward the event call
Core::Get().EmitPlayerMoney(m_ID, current, current + amount);
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -18,6 +18,7 @@ enum PlayerCircularLocks
PCL_EMIT_PLAYER_WORLD = (3 << 0), PCL_EMIT_PLAYER_WORLD = (3 << 0),
PCL_EMIT_PLAYER_TEAM = (4 << 0), PCL_EMIT_PLAYER_TEAM = (4 << 0),
PCL_EMIT_PLAYER_SKIN = (5 << 0), PCL_EMIT_PLAYER_SKIN = (5 << 0),
PCL_EMIT_PLAYER_MONEY = (6 << 0),
}; };
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
@ -422,12 +423,12 @@ public:
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify the money amount of the managed player entity. * Modify the money amount of the managed player entity.
*/ */
void SetMoney(Int32 amount) const; void SetMoney(Int32 amount);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Give a certain amount of money to the managed player entity. * Give a certain amount of money to the managed player entity.
*/ */
void GiveMoney(Int32 amount) const; void GiveMoney(Int32 amount);
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the score of the managed player entity. * Retrieve the score of the managed player entity.

View File

@ -380,6 +380,7 @@ enum EventType
EVT_PLAYERWORLD, EVT_PLAYERWORLD,
EVT_PLAYERTEAM, EVT_PLAYERTEAM,
EVT_PLAYERSKIN, EVT_PLAYERSKIN,
EVT_PLAYERMONEY,
EVT_VEHICLECOLOUR, EVT_VEHICLECOLOUR,
EVT_VEHICLEHEALTH, EVT_VEHICLEHEALTH,
EVT_VEHICLEPOSITION, EVT_VEHICLEPOSITION,