Raised This Month: $ Target: $400
 0% 

Help with Optimization!


Post New Thread Reply   
 
Thread Tools Display Modes
Raddish
BANNED
Join Date: Jul 2008
Location: Argentina
Old 07-30-2010 , 19:38   Re: Help with Optimization!
Reply With Quote #11

Quote:
Originally Posted by lucas_7_94 View Post
sorry , i'm no talking about the human class , are a simple weapons with new model , damage, power , etc.

I can't speak english.

[ES]

Lo que podes hacer es crear una variable + un enum y haces lo que te dijo de utilizar un switch.
Raddish is offline
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 07-30-2010 , 20:06   Re: Help with Optimization!
Reply With Quote #12

Quote:
Originally Posted by Raddish View Post
I can't speak english.

[ES]

Lo que podes hacer es crear una variable + un enum y haces lo que te dijo de utilizar un switch.
ok , but i need a full example , because i'm tryting but i cant D:
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-30-2010 , 20:15   Re: Help with Optimization!
Reply With Quote #13

I don't understand exactly what you're trying to accomplish but since you're working with bools this may help.
PHP Code:
//You can do up to 32 options (all at the same time if needed) with this method
enum Flags ( <<=)
{
    
Freeze 1,
    
Glow,     
    
Gravity,  
    
Fire,
    
Explode,
    
Crush
}

new 
Flags:g_WeaponFlags33 ];

#define SetFlag(%1,%2)        (g_WeaponFlags[%1] |= %2)
#define RemoveFlag(%1,%2)    (g_WeaponFlags[%1] &= ~%2)
#define CheckFlag(%1,%2)    (g_WeaponFlags[%1] & %2)
#define ClearFlags(%1)        (g_WeaponFlags[%1] = Flags:0)

public TestFuncid 
{
    
SetFlagid Freeze );
    
SetFlagid Fire );
    
    
RemoveFlagid Glow );
    
RemoveFlagid Crush );
    
    if ( 
CheckFlagid Fire ) )
    {
        
//Do this
    
}
    
    
ClearFlagsid );

__________________

Last edited by Bugsy; 07-30-2010 at 20:24.
Bugsy is offline
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 07-30-2010 , 20:19   Re: Help with Optimization!
Reply With Quote #14

Something like this?

Code:
#define MAX_POWERS 5 enum {     NO_POWER = 0,     POWER_1,     POWER_2,     POWER_3 }; new g_Power[33]; public function(id) {     g_Power[id] = random_num(NO_POWER, POWER_3); } public FwdTakeDamage(id, iInflictor, iAttacker, Float:fDamage, iDamagebits) {     switch(g_Power[id])     {         case NO_POWER:  // stuff         case POWER_1:   // stuff         case POWER_2:   // sutff         case POWER_3:   // stuff     } }
__________________
Approved Plugins - Steam Profile

Public non-terminated projects:
All Admins Menu, HLTV parameters, Subnick,
Second Password (cool style), InfoZone,
Binary C4 plant/defuse, and more...

Private projects:
NoSpec (+menu), NV Surf Management,
PM Adanved System, KZ longjump2, and more...
Alucard^ is offline
Send a message via Skype™ to Alucard^
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 07-30-2010 , 20:24   Re: Help with Optimization!
Reply With Quote #15

Great !!

But one cuestion , i need make more 'CheckFlags' , its possible a make with switch ?

#Alucard^

You never used MAX_POWERS
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.

Last edited by lucas_7_94; 07-30-2010 at 20:26.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-30-2010 , 20:25   Re: Help with Optimization!
Reply With Quote #16

Quote:
Originally Posted by lucas_7_94 View Post
Great !!

But one cuestion , i need make more 'CheckFlags' , its possible a make with switch ?
Bugsy's method is very similar to bools. You can't use a switch. You can only use a switch with integers, hence why people mentioned 'classes'.
__________________
fysiks is online now
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-30-2010 , 20:26   Re: Help with Optimization!
Reply With Quote #17

Quote:
Originally Posted by lucas_7_94 View Post
Great !!

But one cuestion , i need make more 'CheckFlags' , its possible a make with switch ?
A switch may not be necessary, this is what makes bit-fields so useful. Give me an example condition where you would need a switch.
__________________
Bugsy is offline
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 07-30-2010 , 20:33   Re: Help with Optimization!
Reply With Quote #18

i have changed this about you code.

PHP Code:
enum _:Flags ( <<=)
{
    
WEAPON1 1,
    
WEAPON2,
    
WEAPON3,
    
WEAPON4,
    
WEAPON5,
    
WEAPON6
}

public 
fw_TakeDamage(victiminflictorattackerFloat:damagedamage_type)
{
    if ( 
is_user_connectedattacker ) ) return HAM_IGNORED
    
    
if ( CheckFlagattacker WEAPON1 ) )
    {
         
    }
    
    if ( 
CheckFlagattacker WEAPON2) )
    {
         
    }
    if ( 
CheckFlagattacker WEAPON3) )
    {
         
    }
    if ( 
CheckFlagattacker WEAPON4) )
    {
         
    }
    if ( 
CheckFlagattacker WEAPON5) )
    {
         
    }
    if ( 
CheckFlagattacker WEAPON6) )
    {
         
    }

look , more if if if , i'ts possible make with switch ?
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-30-2010 , 20:37   Re: Help with Optimization!
Reply With Quote #19

Sometimes an 'if' is needed (even if you have multiple), it all depends on the situation. See Alucards code above for switch usage. I was eliminating bool variables for you.
__________________

Last edited by Bugsy; 07-30-2010 at 20:39.
Bugsy is offline
Old 07-30-2010, 21:16
lucas_7_94
This message has been deleted by lucas_7_94.
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 07-31-2010 , 10:59   Re: Help with Optimization!
Reply With Quote #20

Ready , Alucard's code works fine , thanks you , Bugsy too , interesting method ^^.
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
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 18:01.


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