AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   help with switch,case (https://forums.alliedmods.net/showthread.php?t=120764)

drekes 03-07-2010 18:13

help with switch,case
 
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*/
    
}



wrecked_ 03-07-2010 18:18

Re: help with switch,case
 
PHP Code:

rank playerrank[id

Use == for comparisons.

fysiks 03-07-2010 18:19

Re: help with switch,case
 
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.

drekes 03-07-2010 18:23

Re: help with switch,case
 
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)
        } 


wrecked_ 03-07-2010 18:26

Re: help with switch,case
 
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.

drekes 03-07-2010 18:31

Re: help with switch,case
 
Oke, thx guys for the fast reply's


All times are GMT -4. The time now is 08:37.

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