mirror of
				https://github.com/VCMP-SqMod/SqMod.git
				synced 2025-11-04 00:07:19 +01:00 
			
		
		
		
	Implement a new event to receive notifications when a player skin has changed.
This commit is contained in:
		@@ -425,6 +425,7 @@ protected:
 | 
				
			|||||||
        Function        mOnAdmin;
 | 
					        Function        mOnAdmin;
 | 
				
			||||||
        Function        mOnWorld;
 | 
					        Function        mOnWorld;
 | 
				
			||||||
        Function        mOnTeam;
 | 
					        Function        mOnTeam;
 | 
				
			||||||
 | 
					        Function        mOnSkin;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* --------------------------------------------------------------------------------------------
 | 
					    /* --------------------------------------------------------------------------------------------
 | 
				
			||||||
@@ -998,6 +999,7 @@ public:
 | 
				
			|||||||
    void EmitPlayerAdmin(Int32 player_id, bool old_admin, bool new_admin);
 | 
					    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 EmitPlayerWorld(Int32 player_id, Int32 old_world, Int32 new_world, bool secondary);
 | 
				
			||||||
    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 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);
 | 
				
			||||||
@@ -1138,6 +1140,7 @@ private:
 | 
				
			|||||||
    Function    mOnPlayerAdmin;
 | 
					    Function    mOnPlayerAdmin;
 | 
				
			||||||
    Function    mOnPlayerWorld;
 | 
					    Function    mOnPlayerWorld;
 | 
				
			||||||
    Function    mOnPlayerTeam;
 | 
					    Function    mOnPlayerTeam;
 | 
				
			||||||
 | 
					    Function    mOnPlayerSkin;
 | 
				
			||||||
    Function    mOnVehicleColour;
 | 
					    Function    mOnVehicleColour;
 | 
				
			||||||
    Function    mOnVehicleHealth;
 | 
					    Function    mOnVehicleHealth;
 | 
				
			||||||
    Function    mOnVehiclePosition;
 | 
					    Function    mOnVehiclePosition;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -749,6 +749,14 @@ void Core::EmitPlayerTeam(Int32 player_id, Int32 old_team, Int32 new_team)
 | 
				
			|||||||
    Emit(mOnPlayerTeam, _player.mObj, old_team, new_team);
 | 
					    Emit(mOnPlayerTeam, _player.mObj, old_team, new_team);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ------------------------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					void Core::EmitPlayerSkin(Int32 player_id, Int32 old_skin, Int32 new_skin)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    PlayerInst & _player = m_Players.at(player_id);
 | 
				
			||||||
 | 
					    Emit(_player.mOnSkin, old_skin, new_skin);
 | 
				
			||||||
 | 
					    Emit(mOnPlayerSkin, _player.mObj, old_skin, new_skin);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ------------------------------------------------------------------------------------------------
 | 
					// ------------------------------------------------------------------------------------------------
 | 
				
			||||||
void Core::EmitVehicleColour(Int32 vehicle_id, Int32 changed)
 | 
					void Core::EmitVehicleColour(Int32 vehicle_id, Int32 changed)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -230,6 +230,7 @@ void Core::ResetFunc(PlayerInst & inst)
 | 
				
			|||||||
    inst.mOnAdmin.ReleaseGently();
 | 
					    inst.mOnAdmin.ReleaseGently();
 | 
				
			||||||
    inst.mOnWorld.ReleaseGently();
 | 
					    inst.mOnWorld.ReleaseGently();
 | 
				
			||||||
    inst.mOnTeam.ReleaseGently();
 | 
					    inst.mOnTeam.ReleaseGently();
 | 
				
			||||||
 | 
					    inst.mOnSkin.ReleaseGently();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ------------------------------------------------------------------------------------------------
 | 
					// ------------------------------------------------------------------------------------------------
 | 
				
			||||||
@@ -347,6 +348,7 @@ void Core::ResetFunc()
 | 
				
			|||||||
    Core::Get().mOnPlayerAdmin.ReleaseGently();
 | 
					    Core::Get().mOnPlayerAdmin.ReleaseGently();
 | 
				
			||||||
    Core::Get().mOnPlayerWorld.ReleaseGently();
 | 
					    Core::Get().mOnPlayerWorld.ReleaseGently();
 | 
				
			||||||
    Core::Get().mOnPlayerTeam.ReleaseGently();
 | 
					    Core::Get().mOnPlayerTeam.ReleaseGently();
 | 
				
			||||||
 | 
					    Core::Get().mOnPlayerSkin.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();
 | 
				
			||||||
@@ -456,6 +458,7 @@ Function & Core::GetEvent(Int32 evid)
 | 
				
			|||||||
        case EVT_PLAYERADMIN:           return mOnPlayerAdmin;
 | 
					        case EVT_PLAYERADMIN:           return mOnPlayerAdmin;
 | 
				
			||||||
        case EVT_PLAYERWORLD:           return mOnPlayerWorld;
 | 
					        case EVT_PLAYERWORLD:           return mOnPlayerWorld;
 | 
				
			||||||
        case EVT_PLAYERTEAM:            return mOnPlayerTeam;
 | 
					        case EVT_PLAYERTEAM:            return mOnPlayerTeam;
 | 
				
			||||||
 | 
					        case EVT_PLAYERSKIN:            return mOnPlayerSkin;
 | 
				
			||||||
        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;
 | 
				
			||||||
@@ -615,6 +618,7 @@ Function & Core::GetPlayerEvent(Int32 id, Int32 evid)
 | 
				
			|||||||
        case EVT_PLAYERADMIN:           return inst.mOnAdmin;
 | 
					        case EVT_PLAYERADMIN:           return inst.mOnAdmin;
 | 
				
			||||||
        case EVT_PLAYERWORLD:           return inst.mOnWorld;
 | 
					        case EVT_PLAYERWORLD:           return inst.mOnWorld;
 | 
				
			||||||
        case EVT_PLAYERTEAM:            return inst.mOnTeam;
 | 
					        case EVT_PLAYERTEAM:            return inst.mOnTeam;
 | 
				
			||||||
 | 
					        case EVT_PLAYERSKIN:            return inst.mOnSkin;
 | 
				
			||||||
        default:                        return NullFunction();
 | 
					        default:                        return NullFunction();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -546,15 +546,30 @@ Int32 CPlayer::GetSkin() const
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ------------------------------------------------------------------------------------------------
 | 
					// ------------------------------------------------------------------------------------------------
 | 
				
			||||||
void CPlayer::SetSkin(Int32 skin) const
 | 
					void CPlayer::SetSkin(Int32 skin)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    // Validate the managed identifier
 | 
					    // Validate the managed identifier
 | 
				
			||||||
    Validate();
 | 
					    Validate();
 | 
				
			||||||
    // Perform the requested operation
 | 
					    // Grab the current value for this property
 | 
				
			||||||
    if (_Func->SetPlayerSkin(m_ID, skin) == vcmpErrorArgumentOutOfBounds)
 | 
					    const Int32 current = _Func->GetPlayerSkin(m_ID);
 | 
				
			||||||
 | 
					    // Don't even bother if it's the same value
 | 
				
			||||||
 | 
					    if (current == skin)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    // Avoid property unwind from a recursive call
 | 
				
			||||||
 | 
					    else if (_Func->SetPlayerSkin(m_ID, skin) == vcmpErrorArgumentOutOfBounds)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        STHROWF("Invalid skin identifier: %d", skin);
 | 
					        STHROWF("Invalid skin identifier: %d", skin);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    // Avoid infinite recursive event loops
 | 
				
			||||||
 | 
					    else if (!(m_CircularLocks & PCL_EMIT_PLAYER_SKIN))
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        // Prevent this event from triggering while executed
 | 
				
			||||||
 | 
					        BitGuardU32 bg(m_CircularLocks, PCL_EMIT_PLAYER_SKIN);
 | 
				
			||||||
 | 
					        // Now forward the event call
 | 
				
			||||||
 | 
					        Core::Get().EmitPlayerSkin(m_ID, current, skin);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ------------------------------------------------------------------------------------------------
 | 
					// ------------------------------------------------------------------------------------------------
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,6 +17,7 @@ enum PlayerCircularLocks
 | 
				
			|||||||
    PCL_EMIT_PLAYER_ADMIN           = (2 << 0),
 | 
					    PCL_EMIT_PLAYER_ADMIN           = (2 << 0),
 | 
				
			||||||
    PCL_EMIT_PLAYER_WORLD           = (3 << 0),
 | 
					    PCL_EMIT_PLAYER_WORLD           = (3 << 0),
 | 
				
			||||||
    PCL_EMIT_PLAYER_TEAM            = (4 << 0),
 | 
					    PCL_EMIT_PLAYER_TEAM            = (4 << 0),
 | 
				
			||||||
 | 
					    PCL_EMIT_PLAYER_SKIN            = (5 << 0),
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* ------------------------------------------------------------------------------------------------
 | 
					/* ------------------------------------------------------------------------------------------------
 | 
				
			||||||
@@ -376,7 +377,7 @@ public:
 | 
				
			|||||||
    /* --------------------------------------------------------------------------------------------
 | 
					    /* --------------------------------------------------------------------------------------------
 | 
				
			||||||
     * Modify the skin identifier of the managed player entity.
 | 
					     * Modify the skin identifier of the managed player entity.
 | 
				
			||||||
    */
 | 
					    */
 | 
				
			||||||
    void SetSkin(Int32 skin) const;
 | 
					    void SetSkin(Int32 skin);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* --------------------------------------------------------------------------------------------
 | 
					    /* --------------------------------------------------------------------------------------------
 | 
				
			||||||
     * Retrieve the color of the managed player entity.
 | 
					     * Retrieve the color of the managed player entity.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -379,6 +379,7 @@ enum EventType
 | 
				
			|||||||
    EVT_PLAYERADMIN,
 | 
					    EVT_PLAYERADMIN,
 | 
				
			||||||
    EVT_PLAYERWORLD,
 | 
					    EVT_PLAYERWORLD,
 | 
				
			||||||
    EVT_PLAYERTEAM,
 | 
					    EVT_PLAYERTEAM,
 | 
				
			||||||
 | 
					    EVT_PLAYERSKIN,
 | 
				
			||||||
    EVT_VEHICLECOLOUR,
 | 
					    EVT_VEHICLECOLOUR,
 | 
				
			||||||
    EVT_VEHICLEHEALTH,
 | 
					    EVT_VEHICLEHEALTH,
 | 
				
			||||||
    EVT_VEHICLEPOSITION,
 | 
					    EVT_VEHICLEPOSITION,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user