Raised This Month: $ Target: $400
 0% 

question about enums and switch


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Alekkkk
Member
Join Date: Mar 2012
Location: Bulgaria
Old 05-21-2012 , 13:42   Re: question about enums and switch
Reply With Quote #1

PHP Code:
enum Weapon
{
    
Deagle,
    
AWP,
    
Knife,
    
Grenade,
    
Scout,
    
SG550,
    
G3SG1,
    
AK47,
    
M4A1
}
new 
gWeapon[MAX_PLAYERS 1][Weapon]

new const 
gNames[Weapon][10] =
{
    
"Deagle",
    
"AWP",
    
"Knife",
    
"Grenade",
    
"Scout",
    
"SG550",
    
"G3SG1",
    
"AK47",
    
"M4A1"
}
new 
Weapon:gName[MAX_PLAYERS 1
Usage:
PHP Code:
gWeapon[id][Deagle] = true 
PHP Code:
if(gWeapon[id][Deagle])
        
gName[id] = Deagle 
PHP Code:
switch(gName[id])
{
     case 
Deagle:
          {
                
// Do something
          
}

Is this right ?
__________________

Last edited by Alekkkk; 05-21-2012 at 14:08.
Alekkkk is offline
Send a message via Skype™ to Alekkkk
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-21-2012 , 14:00   Re: question about enums and switch
Reply With Quote #2

More correct code would be :

new Weapon :gWeapon[MAX_PLAYERS + 1]

And then :

gWeapon[id] = Deagle

Considering a player can be in only once duel type at the same time.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Alekkkk
Member
Join Date: Mar 2012
Location: Bulgaria
Old 05-21-2012 , 14:14   Re: question about enums and switch
Reply With Quote #3

fixed
PHP Code:
new Weapon:gName[MAX_PLAYERS 1
this part. (That was my fault)

If i set only gWeapon[id] = Deagle , can i use it in print_chat like that:

PHP Code:
client_print_color(0Red,"%s"gWeapon[gName[id]]) 
Edit:
I can't set gWeapon[id] = Deagle (Error : Array must be indexed)
When i set gName[id] = Deagle , i can use it in chat : client_print_color(0, Red,"%s", gNames[gName[id]])
I think it is solved .
__________________

Last edited by Alekkkk; 05-21-2012 at 15:29.
Alekkkk is offline
Send a message via Skype™ to Alekkkk
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 00:26.


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