Raised This Month: $32 Target: $400
 8% 

Move 3 almost same functions to one


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lazarev
Veteran Member
Join Date: Sep 2008
Old 08-24-2010 , 07:12   Move 3 almost same functions to one
Reply With Quote #1

Hi, I need you to move those functions to client_command.
PHP Code:
// =========== the commands are ============
register_clcmd"__SETKILLS""CMD_SETKILLS"ADMIN_LEVEL );
register_clcmd"__SETHEADSHOTS""CMD_SETHEADSHOTS"ADMIN_LEVEL );
register_clcmd"__SETSURVIVES""CMD_SETSURVIVES"ADMIN_LEVEL );
// ======================================

public CMD_SETKILLSidlevelcid )
{
    if ( !
cmd_accessidlevelcid) )
        return 
PLUGIN_HANDLED;
        
    new 
szArg33 ];
    
read_argv1szArg32 );
    
    if( !
equalszArg"" ) )
    
g_GlobalScoreKILLS ] = str_to_numszArg );
    
ShowEventMenuid );
    
    return 
PLUGIN_HANDLED;
}

public 
CMD_SETHEADSHOTSidlevelcid )
{
    if ( !
cmd_accessidlevelcid) )
        return 
PLUGIN_HANDLED;
    
    new 
szArg33 ];
    
read_argv1szArg32 );
    if( !
equalszArg"" ) )
    
g_GlobalScoreHEADSHOTS ] = str_to_numszArg );
    
ShowEventMenuid );
    
    return 
PLUGIN_HANDLED;
}

public 
CMD_SETSURVIVESidlevelcid )
{
    if ( !
cmd_accessidlevelcid) )
        return 
PLUGIN_HANDLED;
        
    new 
szArg33 ];
    
read_argv1szArg32 );
    
    if( !
equalszArg"" ) )
    
g_GlobalScoreSURVIVES ] = str_to_numszArg );
    
ShowEventMenuid );
    
    return 
PLUGIN_HANDLED;

lazarev is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-24-2010 , 07:16   Re: Move 3 almost same functions to one
Reply With Quote #2

why ?
__________________
Arkshine is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 08-24-2010 , 07:47   Re: Move 3 almost same functions to one
Reply With Quote #3

You want to avoid code duplication?

You have to find what is different and take it out of the code:

PHP Code:
set_stuff(id,level,cid,type)
{
    if ( !
cmd_accessidlevelcid) )
        return 
PLUGIN_HANDLED;
        
    new 
szArg33 ];
    
read_argv1szArg32 );
    
    if( !
equalszArg"" ) )
    
g_GlobalScoretype ] = str_to_numszArg );
    
ShowEventMenuid );
    
    return 
PLUGIN_HANDLED;
}

public 
CMD_SETKILLSidlevelcid )
{
    return 
set_stuff(id,level,cid,KILLS

__________________
joaquimandrade is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-24-2010 , 07:52   Re: Move 3 almost same functions to one
Reply With Quote #4

Read the command and do a switch based off of that?

__SETKILLS
__SETHEADSHOTS
__SETSURVIVE

PHP Code:
// code...

new iSet;
switch ( 
szCmd] )
{
     case 
'K'iSet KILLS;
     case 
'H'iSet HEADSHOTS;
     case 
'S'iSet SURVIVES;
}

g_GlobalScoreiSet ] = str_to_numszArg );

// code... 
__________________
Bugsy is offline
Old 08-24-2010, 07:55
Arkshine
This message has been deleted by Arkshine. Reason: It pisses me off to see that.
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 08-24-2010 , 07:59   Re: Move 3 almost same functions to one
Reply With Quote #5

__________________
joaquimandrade is offline
lazarev
Veteran Member
Join Date: Sep 2008
Old 08-24-2010 , 10:24   Re: Move 3 almost same functions to one
Reply With Quote #6

thanks, Bugsy & joaquimandrade. both works

Last edited by lazarev; 08-24-2010 at 10:30.
lazarev is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:30.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode