Raised This Month: $ Target: $400
 0% 

How to create 3random possibilites with random_num??? Help needed.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
iPro
Junior Member
Join Date: Jun 2012
Old 06-24-2012 , 11:12   How to create 3random possibilites with random_num??? Help needed.
Reply With Quote #1

how do you make that when random_num(1,100) is 90-100 you get a dgl, 45-89 you get a fiveseven and 1-45 you get a glock18?
Our code sofar: new number = random_num(1,100);

if( number >= 90 )
{
give_item( id, "weapon_deagle" );
new weapon_id = find_ent_by_owner(-1, "weapon_deagle", id);
if(weapon_id)
{
cs_set_weapon_ammo(weapon_id, 1);
}

cs_set_user_bpammo(id, CSW_GLOCK18, 0)
}
if( number >= 45 )
{
give_item( id, "weapon_fiveseven" );
new weapon_id = find_ent_by_owner(-1, "weapon_fiveseven", id);
if(weapon_id)
{
cs_set_weapon_ammo(weapon_id, 1);
}

cs_set_user_bpammo(id, CSW_FIVESEVEN, 0)
}
if( number < 45 )
{
give_item( id, "weapon_glock18" );
new weapon_id = find_ent_by_owner(-1, "weapon_glock18", id);
if(weapon_id)
{
cs_set_weapon_ammo(weapon_id, 1);
}

cs_set_user_bpammo(id, CSW_GLOCK18, 0)
}
iPro is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 06-24-2012 , 12:39   Re: How to create 3random possibilites with random_num??? Help needed.
Reply With Quote #2

PHP Code:
    switch(number)
    {
        case 
90-100:
        {
// give deagle
        
}
        case 
45-89:
        {
// give fiveseven
        
}
        case 
0-44:
        {
// give glock
        

__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 06-24-2012 , 12:50   Re: How to create 3random possibilites with random_num??? Help needed.
Reply With Quote #3

Quote:
Originally Posted by bibu View Post
PHP Code:
    switch(number)
    {
        case 
90-100:
        {
// give deagle
        
}
        case 
45-89:
        {
// give fiveseven
        
}
        case 
0-44:
        {

        } 
shouldn't it be?
PHP Code:
switch(number)
    {
        case 
90..100:
        {
// give deagle
        
}
        case 
45..89:
        {
// give fiveseven
        
}
        case 
0..44:
        {
//give glock
        
}
   } 
EDIT: LOL!
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.

Last edited by pokemonmaster; 06-24-2012 at 17:31.
pokemonmaster is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-24-2012 , 12:51   Re: How to create 3random possibilites with random_num??? Help needed.
Reply With Quote #4

Quote:
Originally Posted by pokemonmaster View Post
shouldn't it be?
PHP Code:
switch(number)
    {
        case 
90..100:
        {
// give deagle
        
}
        case 
45..89:
        {
// give fiveseven
        
}
        case 
0..44:
        {
// give glock 
Yes but you forgot to close all your braces.
__________________
fysiks is offline
Kidev
Veteran Member
Join Date: Jun 2010
Location: France
Old 06-25-2012 , 01:37   Re: How to create 3random possibilites with random_num??? Help needed.
Reply With Quote #5

Don't use switch, when you write:
PHP Code:
case .. 44
Compiler will write:
PHP Code:
case 0:
case 
1:
case 
2:
case 
3:
// ... 
So just use if / else if / else.
__________________
Kidev is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-25-2012 , 02:13   Re: How to create 3random possibilites with random_num??? Help needed.
Reply With Quote #6

Quote:
Originally Posted by -Kid- View Post
Don't use switch, when you write:
PHP Code:
case .. 44
Compiler will write:
PHP Code:
case 0:
case 
1:
case 
2:
case 
3:
// ... 
So just use if / else if / else.
This is true.
But the wiki, on optimization part, says to use a switch when there is more than 3 conditions (something like that), i would be glad if someone could clarify the whole thing and make an approximative rule on this.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-25-2012 , 19:03   Re: How to create 3random possibilites with random_num??? Help needed.
Reply With Quote #7

Quote:
Originally Posted by -Kid- View Post
Don't use switch, when you write:
PHP Code:
case .. 44
Compiler will write:
PHP Code:
case 0:
case 
1:
case 
2:
case 
3:
// ... 
So just use if / else if / else.
If the switch really is less efficient then all the OP needs to do is add some else's in his/her code since the cases are mutually exclusive.
__________________
fysiks is offline
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

Forum Jump


All times are GMT -4. The time now is 06:19.


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