1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 08:47:17 +01:00

Implement pickup option change event and expose the functions to use it.

Fix bitflags declaration for circular locks (huge mistake here).
This commit is contained in:
Sandu Liviu Catalin 2018-06-28 22:06:23 +03:00
parent 1e24f55e94
commit 877e1a38cc
11 changed files with 121 additions and 22 deletions

View File

@ -160,6 +160,7 @@ static const EnumElement g_EventEnum[] = {
{_SC("PickupAlpha"), EVT_PICKUPALPHA},
{_SC("PickupAutomatic"), EVT_PICKUPAUTOMATIC},
{_SC("PickupAutoTimer"), EVT_PICKUPAUTOTIMER},
{_SC("PickupOption"), EVT_PICKUPOPTION},
{_SC("CheckpointEntered"), EVT_CHECKPOINTENTERED},
{_SC("CheckpointExited"), EVT_CHECKPOINTEXITED},
{_SC("CheckpointWorld"), EVT_CHECKPOINTWORLD},
@ -360,6 +361,13 @@ static const EnumElement g_VehicleOptionEnum[] = {
{_SC("Max"), vcmpVehicleOptionSiren}
};
// ------------------------------------------------------------------------------------------------
static const EnumElement g_PickupOptionEnum[] = {
{_SC("Unknown"), SQMOD_UNKNOWN},
{_SC("SingleUse "), vcmpPickupOptionSingleUse},
{_SC("Max"), vcmpPickupOptionSingleUse}
};
// ------------------------------------------------------------------------------------------------
static const EnumElement g_BodyPartEnum[] = {
{_SC("Unknown"), SQMOD_UNKNOWN},
@ -1134,6 +1142,7 @@ static const EnumElements g_EnumList[] = {
{_SC("SqServerOption"), g_ServerOptionEnum},
{_SC("SqPlayerOption"), g_PlayerOptionEnum},
{_SC("SqVehicleOption"), g_VehicleOptionEnum},
{_SC("SqPickupOption"), g_PickupOptionEnum},
{_SC("SqBodyPart"), g_BodyPartEnum},
{_SC("SqPlayerState"), g_PlayerStateEnum},
{_SC("SqPlayerAction"), g_PlayerActionEnum},

View File

@ -21,7 +21,7 @@ namespace SqMod {
enum CoreCircularLocks
{
CCL_RELOAD_SCRIPTS = (1 << 0),
CCL_EMIT_SERVER_OPTION = (2 << 0)
CCL_EMIT_SERVER_OPTION = (1 << 1)
};
/* ------------------------------------------------------------------------------------------------
@ -400,6 +400,7 @@ protected:
SignalPair mOnAlpha;
SignalPair mOnAutomatic;
SignalPair mOnAutoTimer;
SignalPair mOnOption;
};
/* --------------------------------------------------------------------------------------------
@ -1185,6 +1186,7 @@ public:
void EmitPickupAlpha(Int32 pickup_id, Int32 old_alpha, Int32 new_alpha);
void EmitPickupAutomatic(Int32 pickup_id, bool old_status, bool new_status);
void EmitPickupAutoTimer(Int32 pickup_id, Int32 old_timer, Int32 new_timer);
void EmitPickupOption(Int32 pickup_id, Int32 option_id, bool value, Int32 header, LightObj & payload);
void EmitObjectReport(Int32 object_id, bool old_status, bool new_status, bool touched);
void EmitPlayerHealth(Int32 player_id, Float32 old_health, Float32 new_health);
void EmitPlayerArmour(Int32 player_id, Float32 old_armour, Float32 new_armour);
@ -1337,6 +1339,7 @@ public:
SignalPair mOnPickupAlpha;
SignalPair mOnPickupAutomatic;
SignalPair mOnPickupAutoTimer;
SignalPair mOnPickupOption;
SignalPair mOnCheckpointEntered;
SignalPair mOnCheckpointExited;
SignalPair mOnCheckpointWorld;

View File

@ -768,6 +768,15 @@ void Core::EmitPickupAutoTimer(Int32 pickup_id, Int32 old_timer, Int32 new_timer
(*mOnPickupAutoTimer.first)(_pickup.mObj, old_timer, new_timer);
}
// ------------------------------------------------------------------------------------------------
void Core::EmitPickupOption(Int32 pickup_id, Int32 option_id, bool value,
Int32 header, LightObj & payload)
{
PickupInst & _pickup = m_Pickups.at(pickup_id);
(*_pickup.mOnOption.first)(option_id, value, header, payload);
(*mOnPickupOption.first)(_pickup.mObj, option_id, value, header, payload);
}
// ------------------------------------------------------------------------------------------------
void Core::EmitObjectReport(Int32 object_id, bool old_status, bool new_status, bool touched)
{

View File

@ -541,6 +541,7 @@ void Core::PickupInst::InitEvents()
InitSignalPair(mOnAlpha, mEvents, "Alpha");
InitSignalPair(mOnAutomatic, mEvents, "Automatic");
InitSignalPair(mOnAutoTimer, mEvents, "AutoTimer");
InitSignalPair(mOnOption, mEvents, "Option");
}
// ------------------------------------------------------------------------------------------------
@ -555,6 +556,7 @@ void Core::PickupInst::DropEvents()
ResetSignalPair(mOnAlpha);
ResetSignalPair(mOnAutomatic);
ResetSignalPair(mOnAutoTimer);
ResetSignalPair(mOnOption);
mEvents.Release();
}

View File

@ -144,6 +144,7 @@ void Core::InitEvents()
InitSignalPair(mOnPickupAlpha, m_Events, "PickupAlpha");
InitSignalPair(mOnPickupAutomatic, m_Events, "PickupAutomatic");
InitSignalPair(mOnPickupAutoTimer, m_Events, "PickupAutoTimer");
InitSignalPair(mOnPickupOption, m_Events, "PickupOption");
InitSignalPair(mOnCheckpointEntered, m_Events, "CheckpointEntered");
InitSignalPair(mOnCheckpointExited, m_Events, "CheckpointExited");
InitSignalPair(mOnCheckpointWorld, m_Events, "CheckpointWorld");
@ -278,6 +279,7 @@ void Core::DropEvents()
ResetSignalPair(mOnPickupAlpha);
ResetSignalPair(mOnPickupAutomatic);
ResetSignalPair(mOnPickupAutoTimer);
ResetSignalPair(mOnPickupOption);
ResetSignalPair(mOnCheckpointEntered);
ResetSignalPair(mOnCheckpointExited);
ResetSignalPair(mOnCheckpointWorld);

View File

@ -13,7 +13,7 @@ namespace SqMod {
enum CheckpointCircularLocks
{
CHECKPOINTCL_EMIT_CHECKPOINT_WORLD = (1 << 0),
CHECKPOINTCL_EMIT_CHECKPOINT_RADIUS = (2 << 0)
CHECKPOINTCL_EMIT_CHECKPOINT_RADIUS = (1 << 1)
};
/* ------------------------------------------------------------------------------------------------

View File

@ -132,6 +132,60 @@ bool CPickup::IsStreamedFor(CPlayer & player) const
return _Func->IsPickupStreamedForPlayer(m_ID, player.GetID());
}
// ------------------------------------------------------------------------------------------------
bool CPickup::GetOption(Int32 option_id) const
{
// Attempt to obtain the current value of the specified option
const bool value = _Func->GetPickupOption(m_ID, static_cast< vcmpPickupOption >(option_id));
// Check for errors
if (_Func->GetLastError() == vcmpErrorArgumentOutOfBounds)
{
STHROWF("Invalid option identifier: %d", option_id);
}
// Return the requested value
return value;
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetOption(Int32 option_id, bool toggle)
{
// Attempt to obtain the current value of the specified option
const bool value = _Func->GetPickupOption(m_ID, static_cast< vcmpPickupOption >(option_id));
// Attempt to modify the current value of the specified option
if (_Func->SetPickupOption(m_ID, static_cast< vcmpPickupOption >(option_id),
toggle) == vcmpErrorArgumentOutOfBounds)
{
STHROWF("Invalid option identifier: %d", option_id);
}
else if (!(m_CircularLocks & PICKUPCL_EMIT_PICKUP_OPTION))
{
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, PICKUPCL_EMIT_PICKUP_OPTION);
// Now forward the event call
Core::Get().EmitPickupOption(m_ID, option_id, value, 0, NullLightObj());
}
}
// ------------------------------------------------------------------------------------------------
void CPickup::SetOptionEx(Int32 option_id, bool toggle, Int32 header, LightObj & payload)
{
// Attempt to obtain the current value of the specified option
const bool value = _Func->GetPickupOption(m_ID, static_cast< vcmpPickupOption >(option_id));
// Attempt to modify the current value of the specified option
if (_Func->SetPickupOption(m_ID, static_cast< vcmpPickupOption >(option_id),
toggle) == vcmpErrorArgumentOutOfBounds)
{
STHROWF("Invalid option identifier: %d", option_id);
}
else if (!(m_CircularLocks & PICKUPCL_EMIT_PICKUP_OPTION))
{
// Prevent this event from triggering while executed
BitGuardU32 bg(m_CircularLocks, PICKUPCL_EMIT_PICKUP_OPTION);
// Now forward the event call
Core::Get().EmitPickupOption(m_ID, option_id, value, header, payload);
}
}
// ------------------------------------------------------------------------------------------------
Int32 CPickup::GetWorld() const
{
@ -469,6 +523,9 @@ void Register_CPickup(HSQUIRRELVM vm)
.Prop(_SC("PosZ"), &CPickup::GetPositionZ, &CPickup::SetPositionZ)
// Member Methods
.Func(_SC("StreamedFor"), &CPickup::IsStreamedFor)
.Func(_SC("GetOption"), &CPickup::GetOption)
.Func(_SC("SetOption"), &CPickup::SetOption)
.Func(_SC("SetOptionEx"), &CPickup::SetOptionEx)
.Func(_SC("Refresh"), &CPickup::Refresh)
.Func(_SC("SetPos"), &CPickup::SetPositionEx)
.Func(_SC("SetPosition"), &CPickup::SetPositionEx)

View File

@ -12,10 +12,11 @@ namespace SqMod {
*/
enum PickupCircularLocks
{
PICKUPCL_EMIT_PICKUP_WORLD = (1 << 0),
PICKUPCL_EMIT_PICKUP_ALPHA = (2 << 0),
PICKUPCL_EMIT_PICKUP_AUTOMATIC = (3 << 0),
PICKUPCL_EMIT_PICKUP_AUTOTIMER = (4 << 0)
PICKUPCL_EMIT_PICKUP_OPTION = (1 << 0),
PICKUPCL_EMIT_PICKUP_WORLD = (1 << 1),
PICKUPCL_EMIT_PICKUP_ALPHA = (1 << 2),
PICKUPCL_EMIT_PICKUP_AUTOMATIC = (1 << 3),
PICKUPCL_EMIT_PICKUP_AUTOTIMER = (1 << 4)
};
/* ------------------------------------------------------------------------------------------------
@ -188,6 +189,21 @@ public:
*/
bool IsStreamedFor(CPlayer & player) const;
/* --------------------------------------------------------------------------------------------
* Retrieve the current option value of the managed pickup entity.
*/
bool GetOption(Int32 option_id) const;
/* --------------------------------------------------------------------------------------------
* Modify the current option value of the managed pickup entity.
*/
void SetOption(Int32 option_id, bool toggle);
/* --------------------------------------------------------------------------------------------
* Modify the current option value of the managed pickup entity.
*/
void SetOptionEx(Int32 option_id, bool toggle, Int32 header, LightObj & payload);
/* --------------------------------------------------------------------------------------------
* Retrieve the world in which the managed pickup entity exists.
*/

View File

@ -14,15 +14,15 @@ namespace SqMod {
enum PlayerCircularLocks
{
PLAYERCL_EMIT_PLAYER_OPTION = (1 << 0),
PLAYERCL_EMIT_PLAYER_ADMIN = (2 << 0),
PLAYERCL_EMIT_PLAYER_WORLD = (3 << 0),
PLAYERCL_EMIT_PLAYER_TEAM = (4 << 0),
PLAYERCL_EMIT_PLAYER_SKIN = (5 << 0),
PLAYERCL_EMIT_PLAYER_MONEY = (6 << 0),
PLAYERCL_EMIT_PLAYER_SCORE = (7 << 0),
PLAYERCL_EMIT_PLAYER_WANTED_LEVEL = (8 << 0),
PLAYERCL_EMIT_PLAYER_IMMUNITY = (9 << 0),
PLAYERCL_EMIT_PLAYER_ALPHA = (10 << 0)
PLAYERCL_EMIT_PLAYER_ADMIN = (1 << 1),
PLAYERCL_EMIT_PLAYER_WORLD = (1 << 2),
PLAYERCL_EMIT_PLAYER_TEAM = (1 << 3),
PLAYERCL_EMIT_PLAYER_SKIN = (1 << 4),
PLAYERCL_EMIT_PLAYER_MONEY = (1 << 5),
PLAYERCL_EMIT_PLAYER_SCORE = (1 << 6),
PLAYERCL_EMIT_PLAYER_WANTED_LEVEL = (1 << 7),
PLAYERCL_EMIT_PLAYER_IMMUNITY = (1 << 8),
PLAYERCL_EMIT_PLAYER_ALPHA = (1 << 9)
};
/* ------------------------------------------------------------------------------------------------

View File

@ -13,13 +13,13 @@ namespace SqMod {
enum VehicleCircularLocks
{
VEHICLECL_EMIT_VEHICLE_OPTION = (1 << 0),
VEHICLECL_EMIT_VEHICLE_WORLD = (2 << 0),
VEHICLECL_EMIT_VEHICLE_IMMUNITY = (3 << 0),
VEHICLECL_EMIT_VEHICLE_PARTSTATUS = (4 << 0),
VEHICLECL_EMIT_VEHICLE_TYRESTATUS = (5 << 0),
VEHICLECL_EMIT_VEHICLE_DAMAGEDATA = (6 << 0),
VEHICLECL_EMIT_VEHICLE_RADIO = (7 << 0),
VEHICLECL_EMIT_VEHICLE_HANDLINGRULE = (8 << 0)
VEHICLECL_EMIT_VEHICLE_WORLD = (1 << 1),
VEHICLECL_EMIT_VEHICLE_IMMUNITY = (1 << 2),
VEHICLECL_EMIT_VEHICLE_PARTSTATUS = (1 << 3),
VEHICLECL_EMIT_VEHICLE_TYRESTATUS = (1 << 4),
VEHICLECL_EMIT_VEHICLE_DAMAGEDATA = (1 << 5),
VEHICLECL_EMIT_VEHICLE_RADIO = (1 << 6),
VEHICLECL_EMIT_VEHICLE_HANDLINGRULE = (1 << 7)
};
/* ------------------------------------------------------------------------------------------------

View File

@ -381,6 +381,7 @@ enum EventType
EVT_PICKUPALPHA,
EVT_PICKUPAUTOMATIC,
EVT_PICKUPAUTOTIMER,
EVT_PICKUPOPTION,
EVT_CHECKPOINTENTERED,
EVT_CHECKPOINTEXITED,
EVT_CHECKPOINTWORLD,