mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-01-19 03:57:14 +01:00
Implement a new event to receive notifications when a player score has changed.
This commit is contained in:
parent
e9b6d9765b
commit
203dd9802e
@ -427,6 +427,7 @@ protected:
|
|||||||
Function mOnTeam;
|
Function mOnTeam;
|
||||||
Function mOnSkin;
|
Function mOnSkin;
|
||||||
Function mOnMoney;
|
Function mOnMoney;
|
||||||
|
Function mOnScore;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
@ -1002,6 +1003,7 @@ public:
|
|||||||
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 EmitPlayerMoney(Int32 player_id, Int32 old_money, Int32 new_money);
|
||||||
|
void EmitPlayerScore(Int32 player_id, Int32 old_score, Int32 new_score);
|
||||||
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);
|
||||||
@ -1144,6 +1146,7 @@ private:
|
|||||||
Function mOnPlayerTeam;
|
Function mOnPlayerTeam;
|
||||||
Function mOnPlayerSkin;
|
Function mOnPlayerSkin;
|
||||||
Function mOnPlayerMoney;
|
Function mOnPlayerMoney;
|
||||||
|
Function mOnPlayerScore;
|
||||||
Function mOnVehicleColour;
|
Function mOnVehicleColour;
|
||||||
Function mOnVehicleHealth;
|
Function mOnVehicleHealth;
|
||||||
Function mOnVehiclePosition;
|
Function mOnVehiclePosition;
|
||||||
|
@ -765,6 +765,14 @@ void Core::EmitPlayerMoney(Int32 player_id, Int32 old_money, Int32 new_money)
|
|||||||
Emit(mOnPlayerMoney, _player.mObj, old_money, new_money);
|
Emit(mOnPlayerMoney, _player.mObj, old_money, new_money);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
void Core::EmitPlayerScore(Int32 player_id, Int32 old_score, Int32 new_score)
|
||||||
|
{
|
||||||
|
PlayerInst & _player = m_Players.at(player_id);
|
||||||
|
Emit(_player.mOnScore, old_score, new_score);
|
||||||
|
Emit(mOnPlayerScore, _player.mObj, old_score, new_score);
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void Core::EmitVehicleColour(Int32 vehicle_id, Int32 changed)
|
void Core::EmitVehicleColour(Int32 vehicle_id, Int32 changed)
|
||||||
{
|
{
|
||||||
|
@ -232,6 +232,7 @@ void Core::ResetFunc(PlayerInst & inst)
|
|||||||
inst.mOnTeam.ReleaseGently();
|
inst.mOnTeam.ReleaseGently();
|
||||||
inst.mOnSkin.ReleaseGently();
|
inst.mOnSkin.ReleaseGently();
|
||||||
inst.mOnMoney.ReleaseGently();
|
inst.mOnMoney.ReleaseGently();
|
||||||
|
inst.mOnScore.ReleaseGently();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
@ -351,6 +352,7 @@ void Core::ResetFunc()
|
|||||||
Core::Get().mOnPlayerTeam.ReleaseGently();
|
Core::Get().mOnPlayerTeam.ReleaseGently();
|
||||||
Core::Get().mOnPlayerSkin.ReleaseGently();
|
Core::Get().mOnPlayerSkin.ReleaseGently();
|
||||||
Core::Get().mOnPlayerMoney.ReleaseGently();
|
Core::Get().mOnPlayerMoney.ReleaseGently();
|
||||||
|
Core::Get().mOnPlayerScore.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();
|
||||||
@ -462,6 +464,7 @@ Function & Core::GetEvent(Int32 evid)
|
|||||||
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_PLAYERMONEY: return mOnPlayerMoney;
|
||||||
|
case EVT_PLAYERSCORE: return mOnPlayerScore;
|
||||||
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;
|
||||||
@ -623,6 +626,7 @@ Function & Core::GetPlayerEvent(Int32 id, Int32 evid)
|
|||||||
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;
|
case EVT_PLAYERMONEY: return inst.mOnMoney;
|
||||||
|
case EVT_PLAYERSCORE: return inst.mOnScore;
|
||||||
default: return NullFunction();
|
default: return NullFunction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -701,12 +701,27 @@ Int32 CPlayer::GetScore() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void CPlayer::SetScore(Int32 score) const
|
void CPlayer::SetScore(Int32 score)
|
||||||
{
|
{
|
||||||
// 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->GetPlayerScore(m_ID);
|
||||||
|
// Don't even bother if it's the same value
|
||||||
|
if (current == score)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Avoid property unwind from a recursive call
|
||||||
_Func->SetPlayerScore(m_ID, score);
|
_Func->SetPlayerScore(m_ID, score);
|
||||||
|
// Avoid infinite recursive event loops
|
||||||
|
if (!(m_CircularLocks & PCL_EMIT_PLAYER_SCORE))
|
||||||
|
{
|
||||||
|
// Prevent this event from triggering while executed
|
||||||
|
BitGuardU32 bg(m_CircularLocks, PCL_EMIT_PLAYER_SCORE);
|
||||||
|
// Now forward the event call
|
||||||
|
Core::Get().EmitPlayerScore(m_ID, current, score);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -19,6 +19,7 @@ enum PlayerCircularLocks
|
|||||||
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),
|
PCL_EMIT_PLAYER_MONEY = (6 << 0),
|
||||||
|
PCL_EMIT_PLAYER_SCORE = (7 << 0),
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
@ -438,7 +439,7 @@ public:
|
|||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Modify the score of the managed player entity.
|
* Modify the score of the managed player entity.
|
||||||
*/
|
*/
|
||||||
void SetScore(Int32 score) const;
|
void SetScore(Int32 score);
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Retrieve the wanted level of the managed player entity.
|
* Retrieve the wanted level of the managed player entity.
|
||||||
|
@ -381,6 +381,7 @@ enum EventType
|
|||||||
EVT_PLAYERTEAM,
|
EVT_PLAYERTEAM,
|
||||||
EVT_PLAYERSKIN,
|
EVT_PLAYERSKIN,
|
||||||
EVT_PLAYERMONEY,
|
EVT_PLAYERMONEY,
|
||||||
|
EVT_PLAYERSCORE,
|
||||||
EVT_VEHICLECOLOUR,
|
EVT_VEHICLECOLOUR,
|
||||||
EVT_VEHICLEHEALTH,
|
EVT_VEHICLEHEALTH,
|
||||||
EVT_VEHICLEPOSITION,
|
EVT_VEHICLEPOSITION,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user