AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Strings in enums? (https://forums.alliedmods.net/showthread.php?t=162467)

sake 07-19-2011 09:12

Strings in enums?
 
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

Exolent[jNr] 07-19-2011 09:18

Re: Strings in enums?
 
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?

sake 07-19-2011 10:44

Re: Strings in enums?
 
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); 


Exolent[jNr] 07-19-2011 10:56

Re: Strings in enums?
 
PHP Code:

        case M4A1:
        case 
AK47:
        case 
SG552:
        case 
AUG:
        case 
M3:
        case 
MP5:
        case 
PARA:
        case 
AWP

Show where those are defined.

sake 07-19-2011 11:06

Re: Strings in enums?
 
PHP Code:

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



Exolent[jNr] 07-19-2011 11:23

Re: Strings in enums?
 
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);

sake 07-19-2011 12:12

Re: Strings in enums?
 
Hmmm... It can be so easy :). Thanks!

Doc-Holiday 07-19-2011 19:34

Re: Strings in enums?
 
Quote:

Originally Posted by Exolent[jNr] (Post 1513866)
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?

Exolent[jNr] 07-19-2011 19:39

Re: Strings in enums?
 
Quote:

Originally Posted by Doc-Holiday (Post 1514201)
is Ham_GiveAmmo better then the cs natives?

Not sure. I was just following his code.


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

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