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 world has changed.
This commit is contained in:
parent
c5ef8018ae
commit
84bae9432a
@ -423,6 +423,7 @@ protected:
|
||||
Function mOnPosition;
|
||||
Function mOnOption;
|
||||
Function mOnAdmin;
|
||||
Function mOnWorld;
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -994,6 +995,7 @@ public:
|
||||
void EmitPlayerPosition(Int32 player_id);
|
||||
void EmitPlayerOption(Int32 player_id, Int32 option_id, bool value, Int32 header, Object & payload);
|
||||
void EmitPlayerAdmin(Int32 player_id, bool old_admin, bool new_admin);
|
||||
void EmitPlayerWorld(Int32 player_id, Int32 old_world, Int32 new_world, bool secondary);
|
||||
void EmitVehicleColour(Int32 vehicle_id, Int32 changed);
|
||||
void EmitVehicleHealth(Int32 vehicle_id, Float32 old_health, Float32 new_health);
|
||||
void EmitVehiclePosition(Int32 vehicle_id);
|
||||
@ -1132,6 +1134,7 @@ private:
|
||||
Function mOnPlayerPosition;
|
||||
Function mOnPlayerOption;
|
||||
Function mOnPlayerAdmin;
|
||||
Function mOnPlayerWorld;
|
||||
Function mOnVehicleColour;
|
||||
Function mOnVehicleHealth;
|
||||
Function mOnVehiclePosition;
|
||||
|
@ -733,6 +733,14 @@ void Core::EmitPlayerAdmin(Int32 player_id, bool old_admin, bool new_admin)
|
||||
Emit(mOnPlayerAdmin, _player.mObj, old_admin, new_admin);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::EmitPlayerWorld(Int32 player_id, Int32 old_world, Int32 new_world, bool secondary)
|
||||
{
|
||||
PlayerInst & _player = m_Players.at(player_id);
|
||||
Emit(_player.mOnWorld, old_world, new_world, secondary);
|
||||
Emit(mOnPlayerWorld, _player.mObj, old_world, new_world, secondary);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::EmitVehicleColour(Int32 vehicle_id, Int32 changed)
|
||||
{
|
||||
|
@ -228,6 +228,7 @@ void Core::ResetFunc(PlayerInst & inst)
|
||||
inst.mOnPosition.ReleaseGently();
|
||||
inst.mOnOption.ReleaseGently();
|
||||
inst.mOnAdmin.ReleaseGently();
|
||||
inst.mOnWorld.ReleaseGently();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -343,6 +344,7 @@ void Core::ResetFunc()
|
||||
Core::Get().mOnPlayerPosition.ReleaseGently();
|
||||
Core::Get().mOnPlayerOption.ReleaseGently();
|
||||
Core::Get().mOnPlayerAdmin.ReleaseGently();
|
||||
Core::Get().mOnPlayerWorld.ReleaseGently();
|
||||
Core::Get().mOnVehicleColour.ReleaseGently();
|
||||
Core::Get().mOnVehicleHealth.ReleaseGently();
|
||||
Core::Get().mOnVehiclePosition.ReleaseGently();
|
||||
@ -450,6 +452,7 @@ Function & Core::GetEvent(Int32 evid)
|
||||
case EVT_PLAYERPOSITION: return mOnPlayerPosition;
|
||||
case EVT_PLAYEROPTION: return mOnPlayerOption;
|
||||
case EVT_PLAYERADMIN: return mOnPlayerAdmin;
|
||||
case EVT_PLAYERWORLD: return mOnPlayerWorld;
|
||||
case EVT_VEHICLECOLOUR: return mOnVehicleColour;
|
||||
case EVT_VEHICLEHEALTH: return mOnVehicleHealth;
|
||||
case EVT_VEHICLEPOSITION: return mOnVehiclePosition;
|
||||
@ -607,6 +610,7 @@ Function & Core::GetPlayerEvent(Int32 id, Int32 evid)
|
||||
case EVT_PLAYERPOSITION: return inst.mOnPosition;
|
||||
case EVT_PLAYEROPTION: return inst.mOnOption;
|
||||
case EVT_PLAYERADMIN: return inst.mOnAdmin;
|
||||
case EVT_PLAYERWORLD: return inst.mOnWorld;
|
||||
default: return NullFunction();
|
||||
}
|
||||
}
|
||||
|
@ -417,12 +417,27 @@ Int32 CPlayer::GetWorld() const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CPlayer::SetWorld(Int32 world) const
|
||||
void CPlayer::SetWorld(Int32 world)
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
// Grab the current value for this property
|
||||
const Int32 current = _Func->GetPlayerWorld(m_ID);
|
||||
// Don't even bother if it's the same value
|
||||
if (current == world)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Avoid property unwind from a recursive call
|
||||
_Func->SetPlayerWorld(m_ID, world);
|
||||
// Avoid infinite recursive event loops
|
||||
if (!(m_CircularLocks & PCL_EMIT_PLAYER_WORLD))
|
||||
{
|
||||
// Prevent this event from triggering while executed
|
||||
BitGuardU32 bg(m_CircularLocks, PCL_EMIT_PLAYER_WORLD);
|
||||
// Now forward the event call
|
||||
Core::Get().EmitPlayerWorld(m_ID, current, world, false);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -435,12 +450,27 @@ Int32 CPlayer::GetSecondaryWorld() const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void CPlayer::SetSecondaryWorld(Int32 world) const
|
||||
void CPlayer::SetSecondaryWorld(Int32 world)
|
||||
{
|
||||
// Validate the managed identifier
|
||||
Validate();
|
||||
// Perform the requested operation
|
||||
// Grab the current value for this property
|
||||
const Int32 current = _Func->GetPlayerSecondaryWorld(m_ID);
|
||||
// Don't even bother if it's the same value
|
||||
if (current == world)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Avoid property unwind from a recursive call
|
||||
_Func->SetPlayerSecondaryWorld(m_ID, world);
|
||||
// Avoid infinite recursive event loops
|
||||
if (!(m_CircularLocks & PCL_EMIT_PLAYER_WORLD))
|
||||
{
|
||||
// Prevent this event from triggering while executed
|
||||
BitGuardU32 bg(m_CircularLocks, PCL_EMIT_PLAYER_WORLD);
|
||||
// Now forward the event call
|
||||
Core::Get().EmitPlayerWorld(m_ID, current, world, true);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -15,6 +15,7 @@ enum PlayerCircularLocks
|
||||
{
|
||||
PCL_EMIT_PLAYER_OPTION = (1 << 0)
|
||||
PCL_EMIT_PLAYER_ADMIN = (2 << 0),
|
||||
PCL_EMIT_PLAYER_WORLD = (3 << 0),
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@ -329,7 +330,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the world in which the managed player entity exists.
|
||||
*/
|
||||
void SetWorld(Int32 world) const;
|
||||
void SetWorld(Int32 world);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the secondary world of the managed player entity.
|
||||
|
@ -377,6 +377,7 @@ enum EventType
|
||||
EVT_PLAYERPOSITION,
|
||||
EVT_PLAYEROPTION,
|
||||
EVT_PLAYERADMIN,
|
||||
EVT_PLAYERWORLD,
|
||||
EVT_VEHICLECOLOUR,
|
||||
EVT_VEHICLEHEALTH,
|
||||
EVT_VEHICLEPOSITION,
|
||||
|
Loading…
Reference in New Issue
Block a user