Raised This Month: $ Target: $400
 0% 

Help with Optimization!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 07-30-2010 , 08:58   Help with Optimization!
Reply With Quote #1

In my plugin , i remade 2 bools , this are called in Takedamage , but i hate make this in the takedamage

PHP Code:
new boolmy_bool[33], boolmy_bool2[33]


/////
if( my_bool[id] )
          
// Something

if( my_bool2[id] )
          
// Something 2

if( ... ) //more bools

if( ... ) // more bools. 
Its possible optimize the code ? with switch or anything ?
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.

Last edited by lucas_7_94; 07-30-2010 at 11:31.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 07-30-2010 , 14:28   Re: Help with Optimization!
Reply With Quote #2

Quote:
Originally Posted by lucas_7_94 View Post
In my plugin , i remade 2 bools , this are called in Takedamage , but i hate make this in the takedamage

PHP Code:
new boolmy_bool[33], boolmy_bool2[33]


/////
if( my_bool[id] )
          
// Something

if( my_bool2[id] )
          
// Something 2

if( ... ) //more bools

if( ... ) // more bools. 
Its possible optimize the code ? with switch or anything ?
I cant understand what u want....?
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 07-30-2010 , 14:41   Re: Help with Optimization!
Reply With Quote #3

optimizate the bools , because , i make a plugin with a special weapons , and i created more bools , in the takedamage have more if if if , i need optimizate this with another method or swith or anything.
__________________
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
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-30-2010 , 15:12   Re: Help with Optimization!
Reply With Quote #4

Provide more informations what does each bool, what do you want to with it, etc..
__________________
Arkshine is offline
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 07-30-2010 , 15:46   Re: Help with Optimization!
Reply With Quote #5

the idea is , the weapons have special effects , can freeze TTS or Kill CTS , change weapon model etc , but , i hate have more bools .

I'm searching for a good optimization , like swith or anything.

when the player drop the weapon with special effects , the bools are in false.
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.

Last edited by lucas_7_94; 07-30-2010 at 15:50.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-30-2010 , 15:54   Re: Help with Optimization!
Reply With Quote #6

You don't explain enough, you do what in these checks ?
__________________
Arkshine is offline
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 07-30-2010 , 16:02   Re: Help with Optimization!
Reply With Quote #7

i check if the player have the BOOL in TRUE , he have the power when is attacking a enemy .EX

PHP Code:
[ ... Takedamage ... ]
        if(
g_thunder[attacker])
        {
                     
// do stuff
        
}
        if(
g_citizen[attacker])
        {
                     
// do stuff
        

when the player drop the weapon with power , the booleans are in false.

my problem is , i have more bools , and i hate have more bools in the plugin , therefore i'm searching a optimizate this.

if you doesn't understand , post please.
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.

Last edited by lucas_7_94; 07-30-2010 at 16:27.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 07-30-2010 , 17:06   Re: Help with Optimization!
Reply With Quote #8

like this thread

http://forums.alliedmods.net/showthr...ighlight=bools

look , its possible to make a switch with the array in these case? ex?
__________________
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
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 07-30-2010 , 18:22   Re: Help with Optimization!
Reply With Quote #9

First of all if you are using classes (or something like that) you can optimize the code alot for eg in ZP MeRcyLeZZ uses different bools to identify a user's class like for a zombie player it would be this : g_zombie[id] or for survivor it would be this: g_survivor[id]

Instead you can use a single variable to store a player's class and update it whenever you want
If you cant understand then i will give you an example where MeRcyLeZZ forgot to optimize the code:
Instead of seperate bools to identify a player's class you can do it like this:
new g_players_class[ 33 ]

and on places where player changes class you can store it as a number
[In my eg zombie is taken as 1 and nemesis as 2]
g_players_class[ id ] = 1 // Means player is a zombie

Or like this

g_players_class[ id ] = 2 // Means player is a nemesis

And so you can use switch like this:
PHP Code:
switch( g_players_classid ] )
{
        case 
CLASS_THUNDER:
        {
                     
// do stuff
        
}
        case 
CLASS_CITIZEN:
        {
                     
// do stuff
        
}

__________________

My Plugins For ZP

Inactive due to College and Studies

Last edited by abdul-rehman; 07-30-2010 at 18:26.
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 07-30-2010 , 18:44   Re: Help with Optimization!
Reply With Quote #10

sorry , i'm no talking about the human class , are a simple weapons with new model , damage, power , etc.
__________________
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 00:13.


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