SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 21/05/2020, 02:29 PM   #1
Calinut200
Big Clucker
 
Join Date: Jun 2016
Posts: 74
Reputation: 0
Default new random

Helo!
If i have a code like that
PHP Code:
            new rand random(5);
            switch(
rand)
            {
                case 
0:
                {
                    new 
rand random(5);
                    {
                        and 
there others random
                    
}
                }
                case 
1:
                {
                    new 
rand random(5);
                    {
                        and 
there others random
                    
}
                }
                case 
2:
                {
                    new 
rand random(5);
                    {
                        and 
there others random
                    
}
                }
                case 
3:
                {
                    new 
rand random(5);
                    {
                        and 
there others random
                    
}
                }
                case 
4:
                {
                    new 
rand random(5);
                    {
                        and 
there others random
                    
}
                } 
I have how to optimize? Or to kill some random and still work?
Calinut200 is offline   Reply With Quote
Old 21/05/2020, 02:40 PM   #2
Skimmer
Gangsta
 
Skimmer's Avatar
 
Join Date: Oct 2012
Location: Germany
Posts: 484
Reputation: 56
Default Re: new random

No need to initialize random values within each case. Also the brackets are useless there.

pawn Code:
new rand = random(5);
switch(rand)
{
    case 0:
    {

    }
    case 1:
    {

    }
    case 2:
    {

    }
    case 3:
    {

    }
    case 4:
    {

    }
}
Skimmer is offline   Reply With Quote
Old 21/05/2020, 04:48 PM   #3
Calinut200
Big Clucker
 
Join Date: Jun 2016
Posts: 74
Reputation: 0
Default Re: new random

Quote:
Originally Posted by Skimmer View Post
No need to initialize random values within each case. Also the brackets are useless there.

pawn Code:
new rand = random(5);
switch(rand)
{
    case 0:
    {

    }
    case 1:
    {

    }
    case 2:
    {

    }
    case 3:
    {

    }
    case 4:
    {

    }
}
you not understand, in each case i have a'n random man
Calinut200 is offline   Reply With Quote
Old 21/05/2020, 05:02 PM   #4
Adamoneoone
Huge Clucker
 
Join Date: Sep 2014
Posts: 485
Reputation: 37
Default Re: new random

Code:
new rand = random(5);
{
and there others random
}
what are the point of having the brackets here? Does it even compile?
Anyway, if you're having a random number calculated everytime, why not do it once below the first random?
(i.e. having
Code:
new rand1 = random(5); 
new rand2 = random(5);
switch(rand1)
...
)
The code would be cleaner. Besides that, nothing to improve really.
__________________
If you want to have your own custom script, or even want to have one of our already released scripts, join our SCRIPTING SERVICES DISCORD, or send me a private message!
Adamoneoone 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
[Tutorial] Random Aspects - Using numargs(), getarg(...) and random(...) to make random systems dynamic and easier! SickAttack Tutorials 7 10/05/2015 10:39 AM
[Ajuda] Coordenada random + Nome Random DevilAgain Português/Portuguese 10 03/08/2014 06:05 AM
How to make a random that chooses each random selection once Mennims Scripting Help 6 17/09/2013 06:56 AM
[Include] Insanity Random Lists(generate a random number from your list) CyNiC Includes 10 23/07/2011 01:45 PM
Random location + Random skin Naruto4 Help Archive 2 03/12/2009 04:07 PM


All times are GMT. The time now is 07:23 PM.


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