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 money has changed.
This commit is contained in:
parent
16f35cbef6
commit
e9b6d9765b
@ -426,6 +426,7 @@ protected:
|
||||
Function mOnWorld;
|
||||
Function mOnTeam;
|
||||
Function mOnSkin;
|
||||
Function mOnMoney;
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1000,6 +1001,7 @@ public:
|
||||
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 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 EmitVehicleHealth(Int32 vehicle_id, Float32 old_health, Float32 new_health);
|
||||
void EmitVehiclePosition(Int32 vehicle_id);
|
||||
@ -1141,6 +1143,7 @@ private:
|
||||
Function mOnPlayerWorld;
|
||||
Function mOnPlayerTeam;
|
||||
Function mOnPlayerSkin;
|
||||
Function mOnPlayerMoney;
|
||||
Function mOnVehicleColour;
|
||||
Function mOnVehicleHealth;
|
||||
Function mOnVehiclePosition;
|
||||
|
@ -757,6 +757,14 @@ void Core::EmitPlayerSkin(Int32 player_id, Int32 old_skin, Int32 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)
|
||||
{
|
||||
|
@ -231,6 +231,7 @@ void Core::ResetFunc(PlayerInst & inst)
|
||||
inst.mOnWorld.ReleaseGently();
|
||||
inst.mOnTeam.ReleaseGently();
|
||||
inst.mOnSkin.ReleaseGently();
|
||||
inst.mOnMoney.ReleaseGently();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -349,6 +350,7 @@ void Core::ResetFunc()
|
||||
Core::Get().mOnPlayerWorld.ReleaseGently();
|
||||
Core::Get().mOnPlayerTeam.ReleaseGently();
|
||||
Core::Get().mOnPlayerSkin.ReleaseGently();
|
||||
Core::Get().mOnPlayerMoney.ReleaseGently();
|
||||
Core::Get().mOnVehicleColour.ReleaseGently();
|
||||
Core::Get().mOnVehicleHealth.ReleaseGently();
|
||||
Core::Get().mOnVehiclePosition.ReleaseGently();
|
||||
@ -459,6 +461,7 @@ Function & Core::GetEvent(Int32 evid)
|
||||
case EVT_PLAYERWORLD: return mOnPlayerWorld;
|
||||
case EVT_PLAYERTEAM: return mOnPlayerTeam;
|
||||
case EVT_PLAYERSKIN: return mOnPlayerSkin;
|
||||
case EVT_PLAYERMONEY: return mOnPlayerMoney;
|
||||
case EVT_VEHICLECOLOUR: return mOnVehicleColour;
|
||||
case EVT_VEHICLEHEALTH: return mOnVehicleHealth;
|
||||
case EVT_VEHICLEPOSITION: return mOnVehiclePosition;
|
||||
@ -619,6 +622,7 @@ Function & Core::GetPlayerEvent(Int32 id, Int32 evid)
|
||||
case EVT_PLAYERWORLD: return inst.mOnWorld;
|
||||
case EVT_PLAYERTEAM: return inst.mOnTeam;
|
||||
case EVT_PLAYERSKIN: return inst.mOnSkin;
|
||||
case EVT_PLAYERMONEY: return inst.mOnMoney;
|
||||
default: return NullFunction();
|
||||
}
|
||||
}
|
||||
|
@ -649,21 +649,46 @@ Int32 CPlayer::GetMoney() const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CPlayer::SetMoney(Int32 amount) const
|
||||
void CPlayer::SetMoney(Int32 amount)
|
||||
{
|
||||
// Validate the managed identifier
|
||||
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);
|
||||
// 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();
|
||||
// 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);
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -18,6 +18,7 @@ enum PlayerCircularLocks
|
||||
PCL_EMIT_PLAYER_WORLD = (3 << 0),
|
||||
PCL_EMIT_PLAYER_TEAM = (4 << 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.
|
||||
*/
|
||||
void SetMoney(Int32 amount) const;
|
||||
void SetMoney(Int32 amount);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* 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.
|
||||
|
@ -380,6 +380,7 @@ enum EventType
|
||||
EVT_PLAYERWORLD,
|
||||
EVT_PLAYERTEAM,
|
||||
EVT_PLAYERSKIN,
|
||||
EVT_PLAYERMONEY,
|
||||
EVT_VEHICLECOLOUR,
|
||||
EVT_VEHICLEHEALTH,
|
||||
EVT_VEHICLEPOSITION,
|
||||
|
Loading…
Reference in New Issue
Block a user