SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 25/06/2015, 09:44 PM   #1
DeadNudock
Huge Clucker
 
DeadNudock's Avatar
 
Join Date: Sep 2014
Posts: 218
Reputation: 1
Exclamation optimize code

resolvi smd..

Last edited by DeadNudock; 19/07/2015 at 04:19 PM.
DeadNudock is offline   Reply With Quote
Old 25/06/2015, 09:48 PM   #2
Stanford
Gangsta
 
Stanford's Avatar
 
Join Date: Feb 2012
Posts: 983
Reputation: 84
Default Re: optimize code

I don't think that removing { } would optimize your code, it might make it 'look' better for some people however, I think it doesn't affect that much in performance. Moreover, some people find this a cause for confusion due to you can remove the { } once there's one operation/function whatever to be done. For instance,

pawn Code:
if(Carlos == "good")
foreach(new i : Player)
{
      SendClientMessage(i, -1, "CARLOS IS GOOD!");
}

This is not a must!
__________________
******: "That code compiles perfectly, but I can tell you now it won't make me a cup of tea."

******: "I've said this before. People think that MySQL is some simple plug-and-play magic bullet that you can use to just make your mode instantly better. They don't realise that the "L" in "SQL" means "language". So instead of programming PAWN, and using a bit of this mystery thing, you are now programming in two languages at once. If you spend months learning PAWN, you should spend the same time learning SQL, if not more - it is probably the more complex of the two languages, and not something that just gets bolted on to the side."
Stanford is offline   Reply With Quote
Old 25/06/2015, 11:48 PM   #3
DeadNudock
Huge Clucker
 
DeadNudock's Avatar
 
Join Date: Sep 2014
Posts: 218
Reputation: 1
Default Re: optimize code

Not quite understand, but I'll try ..

@edit
I did not make it.. please
DeadNudock is offline   Reply With Quote
Old 25/06/2015, 11:54 PM   #4
!damo!spiderman
Huge Clucker
 
!damo!spiderman's Avatar
 
Join Date: Oct 2006
Posts: 244
Reputation: 160
Default Re: optimize code

Quote:
Originally Posted by DeadNudock View Post
I tried to let the faster code, let easier to understand, more can not, please someone can tell me how I can remove the

PHP Code:
{} 
without harming the code?

PHP Code:
                    if (IsGangueGRI(i))
                    {
                        if (
PlayerInfo[i][pCargo] == 1)
                        {
                            if (
CofreOrg[GetPlayerOrg(i)][salarioc1] == 0)
                            {}
///
                            
else if (CofreOrg[GetPlayerOrg(i)][Dinheiro] < CofreOrg[GetPlayerOrg(i)][salarioc1])
                            {
                                
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc1];
                                
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc1]);
                            }
                        }
                        if (
PlayerInfo[i][pCargo] == 2)
                        {
                            if (
CofreOrg[GetPlayerOrg(i)][salarioc2] == 0)
                            {}
/////
                            
else if (CofreOrg[GetPlayerOrg(i)][Dinheiro] >= CofreOrg[GetPlayerOrg(i)][salarioc2])
                            {
                                
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc2];
                                
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc2]);
                            }
                        }
                        if (
PlayerInfo[i][pCargo] == 3)
                        {
                            if (
CofreOrg[GetPlayerOrg(i)][salarioc3] == 0)
                            {}
////
                            
else if (CofreOrg[GetPlayerOrg(i)][Dinheiro] >= CofreOrg[GetPlayerOrg(i)][salarioc3])
                            {
                                
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc3];
                                
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc3]);
                            }
                        }
                        if (
PlayerInfo[i][pCargo] == 4)
                        {
                            if (
CofreOrg[GetPlayerOrg(i)][salarioc4] == 0)
                            {}
////
                            
else if (CofreOrg[GetPlayerOrg(i)][Dinheiro] >= CofreOrg[GetPlayerOrg(i)][salarioc4])
                            {
                                
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc4];
                                
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc4]);
                            }
                        }
                        if (
PlayerInfo[i][pCargo] == 5)
                        {
                            if (
CofreOrg[GetPlayerOrg(i)][salarioc5] == 0)
                            {}
///
                            
else if (CofreOrg[GetPlayerOrg(i)][Dinheiro] >= CofreOrg[GetPlayerOrg(i)][salarioc5])
                            {
                                
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc5];
                                
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc5]);
                            }
                        }
                        if (
PlayerInfo[i][pCargo] == 6)
                        {
                            if (
CofreOrg[GetPlayerOrg(i)][Dinheiro] >= 2000PlayerInfo[i][pSalario] += 2000SacarGranaOrg(GetPlayerOrg(i), 2000);
                        }
                    } 
PHP Code:
if (CofreOrg[GetPlayerOrg(i)][salarioc1] == 0
{}
/// 
else if (CofreOrg[GetPlayerOrg(i)][Dinheiro] < CofreOrg[GetPlayerOrg(i)][salarioc1]) 
 { 
          
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc1]; 
           
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc1]); 
 } 

// Change to
if (CofreOrg[GetPlayerOrg(i)][salarioc1] != && CofreOrg[GetPlayerOrg(i)][Dinheiro] < CofreOrg[GetPlayerOrg(i)][salarioc1]) 
 { 
          
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc1]; 
           
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc1]); 
 } 
__________________
!damo!spiderman is offline   Reply With Quote
Old 25/06/2015, 11:57 PM   #5
!damo!spiderman
Huge Clucker
 
!damo!spiderman's Avatar
 
Join Date: Oct 2006
Posts: 244
Reputation: 160
Default Re: optimize code

You could also change the whole thing into a switch statement which would be a lot nicer to read

PHP Code:
if (IsGangueGRI(i)) 
{
    switch(
PlayerInfo[i][pCargo]){
    case 
1:
        if (
CofreOrg[GetPlayerOrg(i)][salarioc1] != && CofreOrg[GetPlayerOrg(i)][Dinheiro] < CofreOrg[GetPlayerOrg(i)][salarioc1])  
        {  
            
PlayerInfo[i][pSalario] += CofreOrg[GetPlayerOrg(i)][salarioc1];  
            
SacarGranaOrg(GetPlayerOrg(i), CofreOrg[GetPlayerOrg(i)][salarioc1]);  
        }  
     case 
2:
          
// next section
      
case 3:
           
// etc
    
}

__________________
!damo!spiderman is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
optimize code JoshNudock Scripting Help 4 22/06/2015 07:38 PM
Optimize code Elite1337 Scripting Help 1 14/01/2015 12:07 PM
Optimize this code... Baltimore Scripting Help 3 15/11/2014 07:45 PM
Help optimize this code Raefal Scripting Help 8 06/09/2014 08:09 AM
help me to optimize my code armyoftwo Help Archive 3 14/11/2010 10:19 AM


All times are GMT. The time now is 08:49 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.