View Single Post
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-06-2021 , 12:03   Re: Owner Knife Only When CT
Reply With Quote #16

Made a few minor optimizations:
  • Eliminated redundant native calls in OnCurWeapon
  • Made OnCurWeapon only fire on weapon change (assuming this is the intent with the plugin). It was previously getting called on each weapon fire.

PHP Code:
#include <amxmodx>
#include <fakemeta>

// Credits : @Bugsy for some optimizations

#define MAX_PLAYERS 32

enum CSTeam
{
    
TEAM_UNASSIGNED 0,
    
TEAM_T,
    
TEAM_CT,
    
TEAM_SPEC
}

enum pWeapons
{
    
WeaponsID,
    
ModelV64 ],
    
ModelP64 ],
    
Access,
    
CSTeam:Teams
}

new const 
g_szWeapons[ ][ pWeapons ] = 
{
    
/* Weapon ID,         Model V,            Model P            Access */
    
CSW_KNIFE"models/ownerweapons/v_knife.mdl""models/vipweapons/p_knife.mdl"ADMIN_IMMUNITYTEAM_CT },// Owner knife model
    
CSW_AK47"models/ownerweapons/v_ak47.mdl"""ADMIN_IMMUNITYTEAM_CT },
    { 
CSW_M4A1"models/ownerweapons/v_m4a1.mdl"""ADMIN_IMMUNITYTEAM_CT }
};

new 
g_CurrentWeaponIDMAX_PLAYERS ];

public 
plugin_init() 
{
    
register_plugin("Weapon models""1.0.2""Supremache");
    
    
register_event("CurWeapon""OnCurWeapon""be""1=1");
}

public 
plugin_precache()
{
    for ( new 
sizeofg_szWeapons ) ; i++ )
    {
        if ( 
g_szWeapons][ ModelV ][ ] != EOS )
        {
            
precache_modelg_szWeapons][ ModelV ] )
        }
        
        if ( 
g_szWeapons][ ModelP ][ ] != EOS )
        {
            
precache_modelg_szWeapons][ ModelP ] )
        }
    }
}

public 
client_connectid )
{
    
g_CurrentWeaponIDid ] = 0;
}

public 
OnCurWeaponid )
{
    if( 
is_user_aliveid ) ) 
    {
        new 
iWeapon read_data);
        
        if ( 
iWeapon != g_CurrentWeaponIDid ] )
        {
            new 
CSTeam:csTeam CSTeam:get_user_teamid );
            new 
iFlags get_user_flagsid );
            
            for(new 
sizeofg_szWeapons ); i++ )
            {
                if( 
csTeam == g_szWeapons][ Teams ] && ( iFlags g_szWeapons][ Access ] == g_szWeapons][ Access ] ) && iWeapon == g_szWeapons][ WeaponsID ] )
                {
                    if( 
g_szWeapons][ ModelV ][ ] != EOS )                        
                        
set_pevidpev_viewmodel2g_szWeapons][ ModelV ] )
                
                    if( 
g_szWeapons][ ModelP ][ ] != EOS )
                        
set_pevidpev_weaponmodel2g_szWeapons][ ModelP ] )
                
                    break;
                }
            }
        }
        
        
g_CurrentWeaponIDid ] = iWeapon;
    }

__________________

Last edited by Bugsy; 11-06-2021 at 12:23.
Bugsy is offline