Raised This Month: $ Target: $400
 0% 

Strings in enums?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sake
Senior Member
Join Date: Jul 2011
Old 07-19-2011 , 09:12   Strings in enums?
Reply With Quote #1

Hello there,

I have been wondering if something like that would be possible:

PHP Code:
enum sampleEnumeration
{
    
stringEnum[] = "hello world"//doesn't seem to work
    
numberEnum // works!

What am I doing wrong?

greetings

sake
sake is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-19-2011 , 09:18   Re: Strings in enums?
Reply With Quote #2

Enums are used to act as data structures or provide an easier way to declare constants, except for strings/arrays.
How are you trying to use this string?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
sake
Senior Member
Join Date: Jul 2011
Old 07-19-2011 , 10:44   Re: Strings in enums?
Reply With Quote #3

PHP Code:
switch(primary[id])
    {
        case 
M4A1:
        {
            
give_item(id,"weapon_m4a1");
            
ExecuteHam(Ham_GiveAmmoid200"556nato"200);
            
        }    
        case 
AK47:
        {
            
give_item(id,"weapon_ak47");
            
ExecuteHam(Ham_GiveAmmoid200"762nato"200);
        }
        case 
SG552:
        {
            
give_item(id,"weapon_sg552");
            
ExecuteHam(Ham_GiveAmmoid200"556nato"200);
        }
        case 
AUG:
        {
            
give_item(id,"weapon_aug");
            
ExecuteHam(Ham_GiveAmmoid200"556nato"200);
        }
        case 
M3:
        {
            
give_item(id,"weapon_m3");
            
ExecuteHam(Ham_GiveAmmoid200"buckshot"200);
        }
        case 
MP5:
        {
            
give_item(id,"weapon_mp5navy");
            
ExecuteHam(Ham_GiveAmmoid200"9mm"200);
        }
        case 
PARA:
        {
            
give_item(id,"weapon_m249");
            
ExecuteHam(Ham_GiveAmmoid200"556natobox"200);
        }
        case 
AWP:
        {
            
give_item(id,"weapon_awp");
            
ExecuteHam(Ham_GiveAmmoid200"338magnum"200);
        }
    } 
I want to make this less code by using

PHP Code:
give_item(id,INSERTWEAPONCONSTANTHERE);
ExecuteHam(Ham_GiveAmmoid200"338magnum"200); 
sake is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-19-2011 , 10:56   Re: Strings in enums?
Reply With Quote #4

PHP Code:
        case M4A1:
        case 
AK47:
        case 
SG552:
        case 
AUG:
        case 
M3:
        case 
MP5:
        case 
PARA:
        case 
AWP
Show where those are defined.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
sake
Senior Member
Join Date: Jul 2011
Old 07-19-2011 , 11:06   Re: Strings in enums?
Reply With Quote #5

PHP Code:
enum PrimaryWeapons
{
    
M4A1,
    
AK47,
    
SG552,
    
AUG,
    
M3,
    
MP5,
    
PARA,
    
AWP

sake is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-19-2011 , 11:23   Re: Strings in enums?
Reply With Quote #6

Then you can do this:
Code:
new const g_weapon_name[PrimaryWeapons][] = {     "weapon_m4a1",     "weapon_ak47",     "weapon_sg552",     "weapon_aug",     "weapon_m3",     "weapon_mp5navy",     "weapon_m249",     "weapon_awp" }; new const g_weapon_ammo[PrimaryWeapons][] = {     "556nato",     "762nato",     "556nato",     "556nato",     "buckshot",     "9mm",     "556natobox",     "338magnum" }; // .. give_item(id,g_weapon_name[g_primary[id]]); ExecuteHam(Ham_GiveAmmo, id, 200, g_weapon_ammo[g_primary[id]], 200);
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Doc-Holiday
AlliedModders Donor
Join Date: Jul 2007
Old 07-19-2011 , 19:34   Re: Strings in enums?
Reply With Quote #7

Quote:
Originally Posted by Exolent[jNr] View Post
Then you can do this:
Code:
new const g_weapon_name[PrimaryWeapons][] = { "weapon_m4a1", "weapon_ak47", "weapon_sg552", "weapon_aug", "weapon_m3", "weapon_mp5navy", "weapon_m249", "weapon_awp" }; new const g_weapon_ammo[PrimaryWeapons][] = { "556nato", "762nato", "556nato", "556nato", "buckshot", "9mm", "556natobox", "338magnum" }; // .. give_item(id,g_weapon_name[g_primary[id]]); ExecuteHam(Ham_GiveAmmo, id, 200, g_weapon_ammo[g_primary[id]], 200);
is Ham_GiveAmmo better then the cs natives?
Doc-Holiday is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-19-2011 , 19:39   Re: Strings in enums?
Reply With Quote #8

Quote:
Originally Posted by Doc-Holiday View Post
is Ham_GiveAmmo better then the cs natives?
Not sure. I was just following his code.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
sake
Senior Member
Join Date: Jul 2011
Old 07-19-2011 , 12:12   Re: Strings in enums?
Reply With Quote #9

Hmmm... It can be so easy . Thanks!
sake 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 01:08.


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