diff --git a/source/Core.hpp b/source/Core.hpp index aca0383b..be9a300f 100644 --- a/source/Core.hpp +++ b/source/Core.hpp @@ -496,6 +496,7 @@ protected: Function mOnRotation; Function mOnOption; Function mOnWorld; + Function mOnImmunity; }; public: @@ -1017,6 +1018,7 @@ public: void EmitVehicleRotation(Int32 vehicle_id); void EmitVehicleOption(Int32 vehicle_id, Int32 option_id, bool value, Int32 header, Object & payload); void EmitVehicleWorld(Int32 vehicle_id, Int32 old_world, Int32 new_world); + void EmitVehicleImmunity(Int32 vehicle_id, Int32 old_immunity, Int32 new_immunity); void EmitServerOption(Int32 option, bool value, Int32 header, Object & payload); void EmitScriptReload(Int32 header, Object & payload); void EmitScriptLoaded(); @@ -1164,6 +1166,7 @@ private: Function mOnVehicleRotation; Function mOnVehicleOption; Function mOnVehicleWorld; + Function mOnVehicleImmunity; Function mOnServerOption; Function mOnScriptReload; Function mOnScriptLoaded; diff --git a/source/CoreEvents.cpp b/source/CoreEvents.cpp index 936a2cbd..7d3af987 100644 --- a/source/CoreEvents.cpp +++ b/source/CoreEvents.cpp @@ -846,6 +846,14 @@ void Core::EmitVehicleWorld(Int32 vehicle_id, Int32 old_world, Int32 new_world) Emit(mOnVehicleWorld, _vehicle.mObj, old_world, new_world); } +// ------------------------------------------------------------------------------------------------ +void Core::EmitVehicleImmunity(Int32 vehicle_id, Int32 old_immunity, Int32 new_immunity) +{ + VehicleInst & _vehicle = m_Vehicles.at(vehicle_id); + Emit(_vehicle.mOnImmunity, old_immunity, new_immunity); + Emit(mOnVehicleImmunity, _vehicle.mObj, old_immunity, new_immunity); +} + // ------------------------------------------------------------------------------------------------ void Core::EmitServerOption(Int32 option, bool value, Int32 header, Object & payload) { diff --git a/source/CoreUtils.cpp b/source/CoreUtils.cpp index 344dd5a0..2cc896a3 100644 --- a/source/CoreUtils.cpp +++ b/source/CoreUtils.cpp @@ -255,6 +255,7 @@ void Core::ResetFunc(VehicleInst & inst) inst.mOnRotation.ReleaseGently(); inst.mOnOption.ReleaseGently(); inst.mOnWorld.ReleaseGently(); + inst.mOnImmunity.ReleaseGently(); } // ------------------------------------------------------------------------------------------------ @@ -366,6 +367,7 @@ void Core::ResetFunc() Core::Get().mOnVehicleRotation.ReleaseGently(); Core::Get().mOnVehicleOption.ReleaseGently(); Core::Get().mOnVehicleWorld.ReleaseGently(); + Core::Get().mOnVehicleImmunity.ReleaseGently(); Core::Get().mOnServerOption.ReleaseGently(); Core::Get().mOnScriptReload.ReleaseGently(); Core::Get().mOnScriptLoaded.ReleaseGently(); @@ -482,6 +484,7 @@ Function & Core::GetEvent(Int32 evid) case EVT_VEHICLEROTATION: return mOnVehicleRotation; case EVT_VEHICLEOPTION: return mOnVehicleOption; case EVT_VEHICLEWORLD: return mOnVehicleWorld; + case EVT_VEHICLEIMMUNITY: return mOnVehicleImmunity; case EVT_SERVEROPTION: return mOnServerOption; case EVT_SCRIPTRELOAD: return mOnScriptReload; case EVT_SCRIPTLOADED: return mOnScriptLoaded; @@ -665,6 +668,7 @@ Function & Core::GetVehicleEvent(Int32 id, Int32 evid) case EVT_VEHICLEROTATION: return inst.mOnRotation; case EVT_VEHICLEOPTION: return inst.mOnOption; case EVT_VEHICLEWORLD: return inst.mOnWorld; + case EVT_VEHICLEIMMUNITY: return inst.mOnImmunity; default: return NullFunction(); } } diff --git a/source/Entity/Vehicle.cpp b/source/Entity/Vehicle.cpp index 9eeead35..d15ee24b 100644 --- a/source/Entity/Vehicle.cpp +++ b/source/Entity/Vehicle.cpp @@ -312,12 +312,22 @@ Int32 CVehicle::GetImmunity() const } // ------------------------------------------------------------------------------------------------ -void CVehicle::SetImmunity(Int32 flags) const +void CVehicle::SetImmunity(Int32 flags) { // Validate the managed identifier Validate(); - // Perform the requested operation + // Grab the current value for this property + const Int32 current = _Func->GetVehicleImmunityFlags(m_ID); + // Avoid property unwind from a recursive call _Func->SetVehicleImmunityFlags(m_ID, flags); + // Avoid infinite recursive event loops + if (!(m_CircularLocks & VEHICLECL_EMIT_VEHICLE_IMMUNITY)) + { + // Prevent this event from triggering while executed + BitGuardU32 bg(m_CircularLocks, VEHICLECL_EMIT_VEHICLE_IMMUNITY); + // Now forward the event call + Core::Get().EmitVehicleImmunity(m_ID, current, flags); + } } // ------------------------------------------------------------------------------------------------ diff --git a/source/Entity/Vehicle.hpp b/source/Entity/Vehicle.hpp index 55cb7332..5b42bb39 100644 --- a/source/Entity/Vehicle.hpp +++ b/source/Entity/Vehicle.hpp @@ -13,7 +13,8 @@ namespace SqMod { enum VehicleCircularLocks { VEHICLECL_EMIT_VEHICLE_OPTION = (1 << 0), - VEHICLECL_EMIT_VEHICLE_WORLD = (2 << 0) + VEHICLECL_EMIT_VEHICLE_WORLD = (2 << 0), + VEHICLECL_EMIT_VEHICLE_IMMUNITY = (3 << 0) }; /* ------------------------------------------------------------------------------------------------ @@ -259,7 +260,7 @@ public: /* -------------------------------------------------------------------------------------------- * Modify the immunity flags of the managed vehicle entity. */ - void SetImmunity(Int32 flags) const; + void SetImmunity(Int32 flags); /* -------------------------------------------------------------------------------------------- * Explode the managed vehicle entity. diff --git a/source/SqBase.hpp b/source/SqBase.hpp index 91680d8f..3d5b333c 100644 --- a/source/SqBase.hpp +++ b/source/SqBase.hpp @@ -391,6 +391,7 @@ enum EventType EVT_VEHICLEROTATION, EVT_VEHICLEOPTION, EVT_VEHICLEWORLD, + EVT_VEHICLEIMMUNITY, EVT_SERVEROPTION, EVT_SCRIPTRELOAD, EVT_SCRIPTLOADED,