Raised This Month: $ Target: $400
 0% 

randomizing


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
iCap
BANNED
Join Date: Oct 2007
Old 10-08-2007 , 17:02   randomizing
Reply With Quote #1

how do you make something random like case 1: and case 2: and stuff like that?
iCap is offline
M249-M4A1
I <3 Mac
Join Date: May 2005
Location: Not interested
Old 10-08-2007 , 17:09   Re: randomizing
Reply With Quote #2

PHP Code:
public DoSomethingRandom() {
    switch(
random_num(1,10)) { // create a random number between 1 and 10, inclusive
        
case 1client_print(0print_chat"[AMXX] Random number: 1")
        case 
2client_print(0print_chat"[AMXX] Random number: 2")
        case 
3client_print(0print_chat"[AMXX] Random number: 3")
        case 
4..9client_print(0print_chat"[AMXX] Random number between 4 and 9 (inclusive)"// Something between 4 and 9, inclusive
        
default: client_print(0print_chat"[AMXX] This doesn't fit any of the above cases."// If nothing fits the case, do this
    
}

__________________

Last edited by M249-M4A1; 10-08-2007 at 20:40.
M249-M4A1 is offline
iCap
BANNED
Join Date: Oct 2007
Old 10-08-2007 , 17:24   Re: randomizing
Reply With Quote #3

okay i'm doing it right, thanks.
iCap is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 10-08-2007 , 17:26   Re: randomizing
Reply With Quote #4

One question: When is the default brach executed ?!?
_Master_ is offline
TheNewt
Donor
Join Date: Jun 2006
Location: Where I live.
Old 10-08-2007 , 19:01   Re: randomizing
Reply With Quote #5

When something that isn't defined with "case <variable> :" like he did case 0-9, if something other then 0-9 was put in like 10 or -1, the default case would be in effect.
__________________
Quote:
toe3_ left the chat room. (G-lined (AUTO Excessive connections from a single host.))
TheNewt is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 10-09-2007 , 05:28   Re: randomizing
Reply With Quote #6

Wrong.
The default case will NEVER be executed because of the limits in random_num()
_Master_ is offline
M249-M4A1
I <3 Mac
Join Date: May 2005
Location: Not interested
Old 10-09-2007 , 07:32   Re: randomizing
Reply With Quote #7

Quote:
Originally Posted by _Master_ View Post
Wrong.
The default case will NEVER be executed because of the limits in random_num()
Wrong.
The default case DOES execute if random_num returns 10.
__________________
M249-M4A1 is offline
iCap
BANNED
Join Date: Oct 2007
Old 10-09-2007 , 06:49   Re: randomizing
Reply With Quote #8

This is what i'm doing and i think it's the best way I could do it. I'm half-way finished with the other stuff in the code but this is this random part; is it correct? i just started coding so please take it easy if somethings wrong

PHP Code:
public give_award(id)
{
    if (!
get_pcvar_num(killawards))
    return 
PLUGIN_HANDLED
    
    
new attacker read_data(1)
    new 
random random_num(113)
    
    switch(
random)
    {
        case 
1:
        {
            
client_print(attackerprint_chat"*Recieved Health Award")
            
health_award(id)
        }
        case 
2:
        {
            
client_print(attackerprint_chat"*Recieved Armor Award")
            
armor_award(id)
        }
        case 
3:
        {
            
client_print(attackerprint_chat"*Recieved Ammo Award")
            
ammo_award(id)
        }
        case 
4:
        {
            
client_print(attackerprint_chat"*Recieved Speed Award")
            
speed_award(id)
        }
        case 
5:
        {
            
client_print(attackerprint_chat"*Recieved Gravity Award")
            
gravity_award(id)
        }
        case 
6:
        {
            
client_print(attackerprint_chat"*Recieved Assualt Award")
            
assault_award(id)
        }
        case 
7:
        {
            
client_print(attackerprint_chat"*Recieved Money Award")
            
money_award(id)
        }
        case 
8:
        {
            
client_print(attackerprint_chat"*Recieved Noclip Award")
            
noclip_award(id)
        }
        case 
9:
        {
            
client_print(attackerprint_chat"*Recieved Random Award")
            
random_award(id)
        }
        case 
10:
        {
            
client_print(attackerprint_chat"*Recieved Blank Award")
            
blank_award(id)
        }
        case 
11:
        {
            
client_print(attackerprint_chat"*Recieved Suit Award")
            
suit_award(id)
        }
        case 
12:
        {
            
client_print(attackerprint_chat"*Recieved HP+AP Award")
            
hpap_award(id)
        }
    }
    return 
PLUGIN_HANDLED

iCap is offline
purple_pixie
Veteran Member
Join Date: Jun 2007
Location: Winchester, England
Old 10-09-2007 , 06:51   Re: randomizing
Reply With Quote #9

Looks fine.

Although you can just switch the return value of random_num, you don't have to store it.
purple_pixie is offline
iCap
BANNED
Join Date: Oct 2007
Old 10-09-2007 , 06:59   Re: randomizing
Reply With Quote #10

could you explain that a little more please? sorry i just want to try to be good like alot of you guys
iCap is offline
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 16:02.


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