AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with Optimization! (https://forums.alliedmods.net/showthread.php?t=133943)

lucas_7_94 07-30-2010 08:58

Help with Optimization!
 
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 ?

abdul-rehman 07-30-2010 14:28

Re: Help with Optimization!
 
Quote:

Originally Posted by lucas_7_94 (Post 1256027)
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....?

lucas_7_94 07-30-2010 14:41

Re: Help with Optimization!
 
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.

Arkshine 07-30-2010 15:12

Re: Help with Optimization!
 
Provide more informations what does each bool, what do you want to with it, etc..

lucas_7_94 07-30-2010 15:46

Re: Help with Optimization!
 
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.

Arkshine 07-30-2010 15:54

Re: Help with Optimization!
 
You don't explain enough, you do what in these checks ?

lucas_7_94 07-30-2010 16:02

Re: Help with Optimization!
 
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.

lucas_7_94 07-30-2010 17:06

Re: Help with Optimization!
 
like this thread

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

look , its possible to make a switch with the array in these case? ex?

abdul-rehman 07-30-2010 18:22

Re: Help with Optimization!
 
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
        
}



lucas_7_94 07-30-2010 18:44

Re: Help with Optimization!
 
sorry , i'm no talking about the human class , are a simple weapons with new model , damage, power , etc.


All times are GMT -4. The time now is 15:37.

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