Thread: Weapon Glow
View Single Post
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-15-2008 , 13:41   Re: wp_glow (on ground)
Reply With Quote #19

Here an optimized version of your current plugin.
  • Use a swith() when you can. Instead using several if() in the forward, it's better to use a switch in such case.
  • No need to create several variables 'r', 'g', 'b', use random_num() directly in the fm_set_rendering() function.
  • It's more readable to write the defined name 'PLUGIN_HANDLED', 'FMRES_IGNORED', etc.. instead of writing its value.
  • cmd_access ( id, level, cid, 2 ) : The correct value is 2 because you have to count the command + the argument, so 2.
  • In your plugin/case, no need to return something in each 'case:'. It's more readable to remove them.
  • You have forget to retrieve the mode value passed into the command.
  • Since you're using one function from fakemeta_util, just copy it into your plugin.
  • You have missed the mode value into the command function.
  • Like connor said, fun is not used, remove it.
  • (Optionnal) : Since fakemeta is using, you can use the player's private data to retrieve the team value. Then you can remove cstrike requirement.

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

    
new gi_Mode;
    new 
gi_MaxClients;

    
enum
    
{
        
CS_TEAM_T 1,
        
CS_TEAM_CT
    
}

    
#define OFFSET_TEAM 114
    #define cs_get_user_team(%1)  get_pdata_int( %1, OFFSET_TEAM )

    
public plugin_init ()
    {
        
register_plugin "wp_glow""0.2a""Radiance" );

        
register_forward FM_SetModel"fw_model" );
        
register_concmd "amx_wpglow""cmd_wpglow"ADMIN_LEVEL_A"cmd_wpglow <1|2|3> : switches wpglow modes" );
    }

    public 
plugin_cfg ()
    {
        
gi_MaxClients global_get glb_maxClients );
    }

    public 
cmd_wpglow idlevelcid )
    {
        if ( !
cmd_access idlevelcid) )
        {
            return 
PLUGIN_HANDLED;
        }

        new 
s_Arg];
        
read_argv 1s_Argsizeof s_Arg );
        
        
gi_Mode str_to_num s_Arg );

        switch ( 
gi_Mode )
        {
            case 
1  client_print idprint_console"%s""[AMXX] wp_glow switched to <team mode>." );
            case 
2  client_print idprint_console"%s""[AMXX] wp_glow switched to <random mode>." );
            default : 
client_print idprint_console"%s""[AMXX] wp_glow disabled." );
        }

        return 
PLUGIN_HANDLED;
    }

    public 
fw_model i_Ent,  const s_Model[] )
    {
        static 
id;
        
id pev i_Entpev_owner );

        if ( !( 
<= id <= gi_MaxClients ) )
        {
            return 
FMRES_IGNORED;
        }

        switch ( 
gi_Mode )
        {
            case 
:
            {
                switch ( 
cs_get_user_team id ) )
                {
                    case 
CS_TEAM_T  fm_set_rendering i_EntkRenderFxGlowShell25500kRenderNormal10 );
                    case 
CS_TEAM_CT fm_set_rendering i_EntkRenderFxGlowShell00255kRenderNormal10 );
                }
            }
            case 
:
            {
                
fm_set_renderingi_EntkRenderFxGlowShellrandom_num1,255 ), random_num1255 ), random_num1255 ), kRenderNormal10 );
            }
        }

        return 
FMRES_IGNORED;
    }

    
fm_set_rendering i_Enti_Fx kRenderFxNonei_R 0i_G 0i_B 0i_Render kRenderNormali_Amount 16 )
    {
        static 
Float:vf_RenderColor[3];

        
vf_RenderColor] = floati_R );
        
vf_RenderColor] = floati_G );
        
vf_RenderColor] = floati_B );

        
set_pev i_Entpev_renderfx   i_Fx );
        
set_pev i_Entpev_rendercolorvf_RenderColor );
        
set_pev i_Entpev_rendermode i_Render );
        
set_pev i_Entpev_renderamt  float i_Amount ) );
    } 
__________________

Last edited by Arkshine; 04-15-2008 at 13:58.
Arkshine is offline