AMX Mod X Plugin Approver
|
04-15-2008
, 13:41
Re: wp_glow (on ground)
|
#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 ( id, level, cid )
{
if ( !cmd_access ( id, level, cid, 2 ) )
{
return PLUGIN_HANDLED;
}
new s_Arg[ 2 ];
read_argv ( 1, s_Arg, sizeof s_Arg - 1 );
gi_Mode = str_to_num ( s_Arg );
switch ( gi_Mode )
{
case 1 : client_print ( id, print_console, "%s", "[AMXX] wp_glow switched to <team mode>." );
case 2 : client_print ( id, print_console, "%s", "[AMXX] wp_glow switched to <random mode>." );
default : client_print ( id, print_console, "%s", "[AMXX] wp_glow disabled." );
}
return PLUGIN_HANDLED;
}
public fw_model ( i_Ent, const s_Model[] )
{
static id;
id = pev ( i_Ent, pev_owner );
if ( !( 1 <= id <= gi_MaxClients ) )
{
return FMRES_IGNORED;
}
switch ( gi_Mode )
{
case 1 :
{
switch ( cs_get_user_team ( id ) )
{
case CS_TEAM_T : fm_set_rendering ( i_Ent, kRenderFxGlowShell, 255, 0, 0, kRenderNormal, 10 );
case CS_TEAM_CT : fm_set_rendering ( i_Ent, kRenderFxGlowShell, 0, 0, 255, kRenderNormal, 10 );
}
}
case 2 :
{
fm_set_rendering( i_Ent, kRenderFxGlowShell, random_num( 1,255 ), random_num( 1, 255 ), random_num( 1, 255 ), kRenderNormal, 10 );
}
}
return FMRES_IGNORED;
}
fm_set_rendering ( i_Ent, i_Fx = kRenderFxNone, i_R = 0, i_G = 0, i_B = 0, i_Render = kRenderNormal, i_Amount = 16 )
{
static Float:vf_RenderColor[3];
vf_RenderColor[ 0 ] = float( i_R );
vf_RenderColor[ 1 ] = float( i_G );
vf_RenderColor[ 2 ] = float( i_B );
set_pev ( i_Ent, pev_renderfx , i_Fx );
set_pev ( i_Ent, pev_rendercolor, vf_RenderColor );
set_pev ( i_Ent, pev_rendermode , i_Render );
set_pev ( i_Ent, pev_renderamt , float ( i_Amount ) );
}
__________________
Last edited by Arkshine; 04-15-2008 at 13:58.
|
|