Raised This Month: $ Target: $400
 0% 

help with switch,case


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 03-07-2010 , 18:13   help with switch,case
Reply With Quote #1

Hi guys.

I am working on something that needs a switch, but when i compile it gives expression has no effect.
so i hope someone can explain a bit about switch and cases.

this is the part i have trouble with.
There are 5 ranks and the menu the player gets depends on his rank.
The ranks 2-5 are commented because they are'nt ready yet.
And check_user(id) is a stock that checks if user is connected to avoid runtime errors

PHP Code:
public skillmenu(id)
{
    
check_user(id)
    new 
rank
    rank 
== playerrank[id]
    switch(
rank)
    {
        case 
1:
        {
            
skillmenu_1(id)
        }
        
/*
        case 2:
        {
            skillmenu_2(id)
        }
        
        case 3:
        {
            skillmenu_3(id)
        }
        case 4:
        {
            skillmenu_4(id)
        }
        case 5:
        {
            skillmenu_5(id)
        }
        return PLUGIN_HANDLED*/
    
}

__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 03-07-2010 , 18:18   Re: help with switch,case
Reply With Quote #2

PHP Code:
rank playerrank[id
Use == for comparisons.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-07-2010 , 18:19   Re: help with switch,case
Reply With Quote #3

Also, return PLUGIN_HANDLED cannot be in the switch statement (unless it's in a case). Only cases can be in the switch statment.

If you don't use "rank" more than once then totally skip making that variable.
__________________

Last edited by fysiks; 03-07-2010 at 19:06. Reason: typo
fysiks is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 03-07-2010 , 18:23   Re: help with switch,case
Reply With Quote #4

ok, i fixed it.
Can i ask another question to?
How can i use something that return a random number, and do something when the number equals a other number.
I tryed this but i don't think it works
PHP Code:
if(playerlevel[id] == 1)
        {
            if(
random_num(1,20) == 5)
            
give_item(id"weapon_hegrenade")
        }
        
        else
        {
            
client_print(idprint_chat"%s Sorry, no luck today"PREFIX)
        } 
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.

Last edited by drekes; 03-07-2010 at 18:26.
drekes is offline
Send a message via MSN to drekes
wrecked_
Veteran Member
Join Date: Jan 2010
Location: New York (GMT-5)
Old 03-07-2010 , 18:26   Re: help with switch,case
Reply With Quote #5

That would work.

PHP Code:
new rnum random_num120 )

switch( 
rnum )
{
    case 
1:
    {}
    case 
2:
    
// ...

If you're doing stuff with random numbers you can check out my Russian Roulette.
__________________
[ Paid Requests ]
DO NOT PM ME ABOUT BLOCKMAKER
NO PRIVATE SUPPORT
wrecked_ is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 03-07-2010 , 18:31   Re: help with switch,case
Reply With Quote #6

Oke, thx guys for the fast reply's
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
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 08:37.


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