Raised This Month: $12 Target: $400
 3% 

Solved 2D Array in Enum | cs_get_weapon_id in FM_SetModel


Post New Thread Reply   
 
Thread Tools Display Modes
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 01-20-2018 , 18:18   Re: 2D Array in Enum | cs_get_weapon_id in FM_SetModel
Reply With Quote #11

Quote:
Originally Posted by E1_531G View Post
Here you write string not array. Don't you see?

Go and read about how to use Trie***Array().

And, you have luck, Hamlet helps you, but you are incredible slow and blind...
What's the matter with you, douchebag? Who asked for you to come here and act like a d*ck? No offense but you're closed-minded and an idiot. Now get outta here.
__________________

Last edited by edon1337; 01-20-2018 at 18:26.
edon1337 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-20-2018 , 19:15   Re: 2D Array in Enum | cs_get_weapon_id in FM_SetModel
Reply With Quote #12

What is your question? Your latest post just says "Any ideas"
__________________
Bugsy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-21-2018 , 05:30   Re: 2D Array in Enum | cs_get_weapon_id in FM_SetModel
Reply With Quote #13

That's what I told you to do, but you did something totally different.
Stop and think before you do something. When you retrieve data from trie you retrieve an array with v, p, w models, which is correct.
But when you push the data to trie you try to push it string by string(by using the array native). How is this going to work? Isn't it logical that when you push the data you need to group the 3 models in a single array before doing TrieSetArray?

PHP Code:
#include <amxmodx>
#include <amxmisc>

enum _:ModelType
{
    
vModel[128],
    
pModel[128],
    
wModel[128]
}

new 
Trie:HandleModelsTrie

public plugin_precache()
{
    
HandleModelsTrie TrieCreate()
    if(
HandleModelsTrie == Invalid_Trie)
    {
        
set_fail_state("some message here")
    }
    
    
ReadConfigurationFile()
}

public 
plugin_end()
{
    
TrieDestroy(HandleModelsTrie)
}

ReadConfigurationFile()
{
    new const 
ConfigFileName[] = "models_test.ini"
    
    
new ConfigFilePath[256]
    
get_configsdir(ConfigFilePath,charsmax(ConfigFilePath))
    
format(ConfigFilePathcharsmax(ConfigFilePath), "%s/%s"ConfigFilePathConfigFileName)
    
    new 
FilePointer fopen(ConfigFilePath,"rt")
    if(
FilePointer)
    {
        new 
LineData[160], TrieKey[32], TrieValue[128], ModelsForWeapon[ModelType], Counter
        
        
while(!feof(FilePointer))
        {
            
fgets(FilePointerLineDatacharsmax(LineData))
            
trim(LineData)
            
            if(
LineData[0] == '/' || LineData[0] == EOS)
            {
                continue
            }

            
strtok(LineDataTrieKeycharsmax(TrieKey), TrieValuecharsmax(TrieValue), '=')
            
trim(TrieKey)
            
trim(TrieValue)
            
            switch(
Counter)
            {
                case 
0:
                {
                    
copy(ModelsForWeapon[vModel], charsmax(ModelsForWeapon[vModel]), TrieValue)
                    
Counter Counter 1
                
}
                case 
1:
                {
                    
copy(ModelsForWeapon[pModel], charsmax(ModelsForWeapon[pModel]), TrieValue)
                    
Counter Counter 1
                
}
                case 
2:
                {
                    
copy(ModelsForWeapon[wModel], charsmax(ModelsForWeapon[wModel]), TrieValue)
                    
                    
strtolower(TrieKey[2])
                    
TrieSetArray(HandleModelsTrieTrieKey[2], ModelsForWeaponsizeof ModelsForWeapon)
                
                    
Counter 0
                
}
            }
        }
        
        
fclose(FilePointer)
    }

To avoid further questions and headaches, the key is the weapon name: knife, ak47, aug, awp, etc. You DO NOT NEED to save all the keys in the plugin and loop. In item deploy you need to get the weapon name, remove the weapon_ prefix and use that as key.
When you precache, precache from the ReadConfigurationFile function, again, DO NOT ITERATE OVER ALL KEYS.
__________________

Last edited by HamletEagle; 01-21-2018 at 05:37.
HamletEagle is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 01-21-2018 , 08:23   Re: 2D Array in Enum | cs_get_weapon_id in FM_SetModel
Reply With Quote #14

Quote:
Originally Posted by Bugsy View Post
What is your question? Your latest post just says "Any ideas"
There was a comment inside the code, but never mind, that code was totally incorrect. I'm trying to fix this one, as for now. It isn't saving/retrieving data correctly but I'll find a solution.
PHP Code:
#include < amxmodx >
#include < amxmisc >
#include < hamsandwich >
#include < fakemeta >
#include < fun >

enum _:ModelData
{
    
Weapon_V128 ],
    
Weapon_P128 ],
    
Weapon_W128 ]
}

new 
Trie:g_tWeaponModels;

new const 
g_szWeapons[ ][ ][ ] =
{
    { 
"weapon_knife""KNIFE_V""KNIFE_P""KNIFE_W" },
    { 
"weapon_ak47""AK47_V""AK47_P""AK47_W" },
    { 
"weapon_aug""AUG_V""AUG_P""AUG_W" },
    { 
"weapon_awp""AWP_V""AWP_P""AWP_W" },
    { 
"weapon_flashbang""FLASHBANG_V""FLASHBANG_P""FLASHBANG_W" },
    { 
"weapon_g3sg1""G3SG1_V""G3SG1_P""G3SG1_W" },
    { 
"weapon_hegrenade""HEGRENADE_V""HEGRENADE_P""HEGRENADE_W" },
    { 
"weapon_m3""M3_V""M3_P""M3_W" },
    { 
"weapon_m4a1""M4A1_V""M4A1_P""M4A1_W" },
    { 
"weapon_m249""M249_V""M249_P""M249_W" },
    { 
"weapon_mac10""MAC10_V""MAC10_P""MAC10_W" },
    { 
"weapon_mp5navy""MP5NAVY_V""MP5NAVY_P""MP5NAVY_W" },
    { 
"weapon_p90""P90_V""P90_P""P90_W" },
    { 
"weapon_scout""SCOUT_V""SCOUT_P""SCOUT_W" },
    { 
"weapon_sg552""SG552_V""SG552_P""SG552_W" },
    { 
"weapon_smokegrenade""SMOKEGRENADE_V""SMOKEGRENADE_P""SMOKEGRENADE_W" },
    { 
"weapon_tmp""TMP_V""TMP_P""TMP_W" },
    { 
"weapon_ump45""UMP45_V""UMP45_P""UMP45_W" },
    { 
"weapon_xm1014""XM1014_V""XM1014_P""XM1014_W" }
}

new const 
g_szFileIni[ ] = "GameModels.ini";

ReadFile( )
{
    new 
szConfigsName256 ], szFilename512 ];
    
get_configsdirszConfigsNamecharsmaxszConfigsName ) );
    
    
formatexszFilenamecharsmaxszFilename ), "%s/%s"szConfigsNameg_szFileIni );
    
    new 
iFile fopenszFilename"r" );

    if( 
iFile )
    {
        new 
szData128 ], szValue64 ], szKey32 ];
        
        while( ! 
feofiFile ) )
        {
            
fgetsiFileszDatacharsmaxszData ) );
            
trimszData );
            
            switch( 
szData] )
            {
            case 
EOS'#'';'
                continue;
                
            default:
                {
                    
strtokszDataszKeycharsmaxszKey ), szValuecharsmaxszValue ), '=' );
                    
trimszKey ); 
                    
trimszValue );
                    
                    if( 
szValue] == EOS )
                    continue;
                    
                    
TrieSetStringg_tWeaponModelsszKeyszValue );
                }
            }
        }
    }
    
fcloseiFile );
}

public 
plugin_init( )
{
    
register_plugin"CS Battle Royale Models""1.0""DoNii" );

    
ReadFile( );
    
    for( new 
isizeof g_szWeaponsi++ )
    
RegisterHamHam_Item_Deployg_szWeapons][ ], "fw_HamItemDeployPost");
}

public 
plugin_precache( )
{
    
g_tWeaponModels TrieCreate( );

    new 
iDataModelData ];
    
    for( new 
isizeof g_szWeaponsi++ )
    {
        for( new 
x=1<= 3x++ )
        {
            if( 
TrieGetStringg_tWeaponModelsg_szWeapons][ ], iDatasizeofiData ) ) )
            {
                
precache_modeliDataWeapon_V ] );
                
precache_modeliDataWeapon_P ] );
                
precache_modeliDataWeapon_W ] );
            }
        }
    }
}

public 
fw_HamItemDeployPostiEnt )
{
    if( 
pev_validiEnt ) != )
    return 
HAM_IGNORED;
    
    new 
id get_pdata_cbaseiEnt41);
    
    if( ! 
is_user_connectedid ) )
    return 
HAM_IGNORED;
    
    new 
iDataModelData ];
    
    new 
szClassName32 ];
    
peviEntpev_classnameszClassNamecharsmaxszClassName ) );
    
    for( new 
isizeof g_szWeaponsi++ )
    {
        if( 
equalszClassNameg_szWeapons][ ] ) )
        {
            for( new 
1<= 2x++ )
            {
                
TrieGetStringg_tWeaponModelsg_szWeapons][ ], iDatasizeof iData );
                
log_to_file"TestDebug.txt""#1 g_szWeapons[ i ][ x ]: %s"g_szWeapons][ ] );
            }
        }
    }
    
log_to_file"TestDebug.txt""#2 Weapon_V: %s | Weapon_P: %s"iDataWeapon_V ], iDataWeapon_P ] );
    
    
set_pevidpev_viewmodel2iDataWeapon_V ] );
    
set_pevidpev_weaponmodel2iDataWeapon_P ] );
    
    return 
HAM_IGNORED;

Quote:
Originally Posted by HamletEagle View Post
PHP Code:
#include <amxmodx>
#include <amxmisc>

enum _:ModelType
{
    
vModel[128],
    
pModel[128],
    
wModel[128]
}

new 
Trie:HandleModelsTrie

public plugin_precache()
{
    
HandleModelsTrie TrieCreate()
    if(
HandleModelsTrie == Invalid_Trie)
    {
        
set_fail_state("some message here")
    }
    
    
ReadConfigurationFile()
}

public 
plugin_end()
{
    
TrieDestroy(HandleModelsTrie)
}

ReadConfigurationFile()
{
    new const 
ConfigFileName[] = "models_test.ini"
    
    
new ConfigFilePath[256]
    
get_configsdir(ConfigFilePath,charsmax(ConfigFilePath))
    
format(ConfigFilePathcharsmax(ConfigFilePath), "%s/%s"ConfigFilePathConfigFileName)
    
    new 
FilePointer fopen(ConfigFilePath,"rt")
    if(
FilePointer)
    {
        new 
LineData[160], TrieKey[32], TrieValue[128], ModelsForWeapon[ModelType], Counter
        
        
while(!feof(FilePointer))
        {
            
fgets(FilePointerLineDatacharsmax(LineData))
            
trim(LineData)
            
            if(
LineData[0] == '/' || LineData[0] == EOS)
            {
                continue
            }

            
strtok(LineDataTrieKeycharsmax(TrieKey), TrieValuecharsmax(TrieValue), '=')
            
trim(TrieKey)
            
trim(TrieValue)
            
            switch(
Counter)
            {
                case 
0:
                {
                    
copy(ModelsForWeapon[vModel], charsmax(ModelsForWeapon[vModel]), TrieValue)
                    
Counter Counter 1
                
}
                case 
1:
                {
                    
copy(ModelsForWeapon[pModel], charsmax(ModelsForWeapon[pModel]), TrieValue)
                    
Counter Counter 1
                
}
                case 
2:
                {
                    
copy(ModelsForWeapon[wModel], charsmax(ModelsForWeapon[wModel]), TrieValue)
                    
                    
strtolower(TrieKey[2])
                    
TrieSetArray(HandleModelsTrieTrieKey[2], ModelsForWeaponsizeof ModelsForWeapon)
                
                    
Counter 0
                
}
            }
        }
        
        
fclose(FilePointer)
    }

What does 'Counter' variable represent? How would the format of the external file look like?
__________________
edon1337 is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-21-2018 , 08:32   Re: 2D Array in Enum | cs_get_weapon_id in FM_SetModel
Reply With Quote #15

You do realise that the plugin precaching is called before the plugin init therefore when you are trying to precache the trie is empty... Because you are reading the file in plugin init
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 01-21-2018 , 08:37   Re: 2D Array in Enum | cs_get_weapon_id in FM_SetModel
Reply With Quote #16

Quote:
Originally Posted by Natsheh View Post
You do realise that the plugin precaching is called before the plugin init therefore when you are trying to precache the trie is empty... Because you are reading the file in plugin init
Yes, thanks for noticing, I was implementing Hamlet's suggestion so I got carried away.
I fixed a bit of the code, it doesn't show knife's model
PHP Code:
#include < amxmodx >
#include < amxmisc >
#include < hamsandwich >
#include < fakemeta >
#include < fun >

enum _:ModelData
{
    
Weapon_V128 ],
    
Weapon_P128 ],
    
Weapon_W128 ]
}

new 
Trie:g_tWeaponModels;

new const 
g_szWeapons[ ][ ][ ] =
{
    { 
"weapon_knife""KNIFE_V""KNIFE_P""KNIFE_W" },
    { 
"weapon_ak47""AK47_V""AK47_P""AK47_W" },
    { 
"weapon_aug""AUG_V""AUG_P""AUG_W" },
    { 
"weapon_awp""AWP_V""AWP_P""AWP_W" },
    { 
"weapon_flashbang""FLASHBANG_V""FLASHBANG_P""FLASHBANG_W" },
    { 
"weapon_g3sg1""G3SG1_V""G3SG1_P""G3SG1_W" },
    { 
"weapon_hegrenade""HEGRENADE_V""HEGRENADE_P""HEGRENADE_W" },
    { 
"weapon_m3""M3_V""M3_P""M3_W" },
    { 
"weapon_m4a1""M4A1_V""M4A1_P""M4A1_W" },
    { 
"weapon_m249""M249_V""M249_P""M249_W" },
    { 
"weapon_mac10""MAC10_V""MAC10_P""MAC10_W" },
    { 
"weapon_mp5navy""MP5NAVY_V""MP5NAVY_P""MP5NAVY_W" },
    { 
"weapon_p90""P90_V""P90_P""P90_W" },
    { 
"weapon_scout""SCOUT_V""SCOUT_P""SCOUT_W" },
    { 
"weapon_sg552""SG552_V""SG552_P""SG552_W" },
    { 
"weapon_smokegrenade""SMOKEGRENADE_V""SMOKEGRENADE_P""SMOKEGRENADE_W" },
    { 
"weapon_tmp""TMP_V""TMP_P""TMP_W" },
    { 
"weapon_ump45""UMP45_V""UMP45_P""UMP45_W" },
    { 
"weapon_xm1014""XM1014_V""XM1014_P""XM1014_W" }
}

new const 
g_szFileIni[ ] = "GameModels.ini";

public 
plugin_init( )
{
    
register_plugin"CS Battle Royale Models""1.0""DoNii" );

    for( new 
isizeof g_szWeaponsi++ )
    
RegisterHamHam_Item_Deployg_szWeapons][ ], "fw_HamItemDeployPost");
}

public 
plugin_precache( )
{
    
g_tWeaponModels TrieCreate( );
    
ReadFile( );
}

public 
fw_HamItemDeployPostiEnt )
{
    if( 
pev_validiEnt ) != )
    return 
HAM_IGNORED;
    
    new 
id get_pdata_cbaseiEnt41);
    
    if( ! 
is_user_connectedid ) )
    return 
HAM_IGNORED;
    
    new 
iDataModelData ];
    
    new 
szClassName32 ];
    
peviEntpev_classnameszClassNamecharsmaxszClassName ) );
    
    for( new 
isizeof g_szWeaponsi++ )
    {
        if( 
equalszClassNameg_szWeapons][ ] ) )
        {
            for( new 
1<= 2x++ )
            {
                
TrieGetStringg_tWeaponModelsg_szWeapons][ ], iDatasizeof iData );
                
log_to_file"TestDebug.txt""#1 g_szWeapons[ i ][ x ]: %s"g_szWeapons][ ] );
            }
        }
    }
    
log_to_file"TestDebug.txt""#2 Weapon_V: %s | Weapon_P: %s"iDataWeapon_V ], iDataWeapon_P ] );
    
    
set_pevidpev_viewmodel2iDataWeapon_V ] );
    
set_pevidpev_weaponmodel2iDataWeapon_P ] );
    
    return 
HAM_IGNORED;
}

ReadFile( )
{
    new 
szConfigsName256 ], szFilename512 ];
    
get_configsdirszConfigsNamecharsmaxszConfigsName ) );
    
    
formatexszFilenamecharsmaxszFilename ), "%s/%s"szConfigsNameg_szFileIni );
    
    new 
iFile fopenszFilename"r" );

    if( 
iFile )
    {
        new 
szData128 ], szValue64 ], szKey32 ];
        
        while( ! 
feofiFile ) )
        {
            
fgetsiFileszDatacharsmaxszData ) );
            
trimszData );
            
            switch( 
szData] )
            {
            case 
EOS'#'';'
                continue;
                
            default:
                {
                    
strtokszDataszKeycharsmaxszKey ), szValuecharsmaxszValue ), '=' );
                    
trimszKey ); 
                    
trimszValue );
                    
                    if( 
szValue] == EOS )
                    continue;
                    
                    
TrieSetStringg_tWeaponModelsszKeyszValue );
                    
precache_modelszValue );
                }
            }
        }
    }
    
fcloseiFile );

debug
PHP Code:
L 01/21/2018 01:12:20#1 g_szWeapons[ i ][ x ]: KNIFE_V
L 01/21/2018 01:12:20#1 g_szWeapons[ i ][ x ]: KNIFE_P
L 01/21/2018 01:12:20#2 Weapon_V:  | Weapon_P: 
L 01/21/2018 01:12:20#1 g_szWeapons[ i ][ x ]: KNIFE_V
L 01/21/2018 01:12:20#1 g_szWeapons[ i ][ x ]: KNIFE_P
L 01/21/2018 01:12:20#2 Weapon_V:  | Weapon_P: 
L 01/21/2018 01:12:36#1 g_szWeapons[ i ][ x ]: SG552_V
L 01/21/2018 01:12:36#1 g_szWeapons[ i ][ x ]: SG552_P
L 01/21/2018 01:12:36#2 Weapon_V: models/NewSG552_V.mdl | Weapon_P: 
L 01/21/2018 14:41:14#1 g_szWeapons[ i ][ x ]: KNIFE_V
L 01/21/2018 14:41:14#1 g_szWeapons[ i ][ x ]: KNIFE_P
L 01/21/2018 14:41:14#2 Weapon_V:  | Weapon_P: 
L 01/21/2018 14:41:14#1 g_szWeapons[ i ][ x ]: KNIFE_V
L 01/21/2018 14:41:14#1 g_szWeapons[ i ][ x ]: KNIFE_P
L 01/21/2018 14:41:14#2 Weapon_V:  | Weapon_P: 
L 01/21/2018 14:41:51#1 g_szWeapons[ i ][ x ]: M3_V
L 01/21/2018 14:41:51#1 g_szWeapons[ i ][ x ]: M3_P
L 01/21/2018 14:41:51#2 Weapon_V: models/NewM3_V.mdl | Weapon_P: 
L 01/21/2018 14:41:53#1 g_szWeapons[ i ][ x ]: KNIFE_V
L 01/21/2018 14:41:53#1 g_szWeapons[ i ][ x ]: KNIFE_P
L 01/21/2018 14:41:53#2 Weapon_V:  | Weapon_P: 
L 01/21/2018 14:41:54#1 g_szWeapons[ i ][ x ]: M3_V
L 01/21/2018 14:41:54#1 g_szWeapons[ i ][ x ]: M3_P
L 01/21/2018 14:41:54#2 Weapon_V: models/NewM3_V.mdl | Weapon_P: 
L 01/21/2018 14:42:00#1 g_szWeapons[ i ][ x ]: KNIFE_V
L 01/21/2018 14:42:00#1 g_szWeapons[ i ][ x ]: KNIFE_P
L 01/21/2018 14:42:00#2 Weapon_V:  | Weapon_P: 
L 01/21/2018 14:42:09#1 g_szWeapons[ i ][ x ]: M3_V
L 01/21/2018 14:42:09#1 g_szWeapons[ i ][ x ]: M3_P
L 01/21/2018 14:42:09#2 Weapon_V: models/NewM3_V.mdl | Weapon_P: 
L 01/21/2018 14:42:12#1 g_szWeapons[ i ][ x ]: KNIFE_V
L 01/21/2018 14:42:12#1 g_szWeapons[ i ][ x ]: KNIFE_P
L 01/21/2018 14:42:12#2 Weapon_V:  | Weapon_P: 
L 01/21/2018 14:42:13#1 g_szWeapons[ i ][ x ]: AWP_V
L 01/21/2018 14:42:13#1 g_szWeapons[ i ][ x ]: AWP_P
L 01/21/2018 14:42:13#2 Weapon_V: models/NewAwp_V.mdl | Weapon_P: 
L 01/21/2018 14:42:15#1 g_szWeapons[ i ][ x ]: KNIFE_V
L 01/21/2018 14:42:15#1 g_szWeapons[ i ][ x ]: KNIFE_P
L 01/21/2018 14:42:15#2 Weapon_V:  | Weapon_P: 
L 01/21/2018 14:42:20#1 g_szWeapons[ i ][ x ]: AWP_V
L 01/21/2018 14:42:20#1 g_szWeapons[ i ][ x ]: AWP_P
L 01/21/2018 14:42:20#2 Weapon_V: models/NewAwp_V.mdl | Weapon_P: 
L 01/21/2018 14:42:20#1 g_szWeapons[ i ][ x ]: KNIFE_V
L 01/21/2018 14:42:20#1 g_szWeapons[ i ][ x ]: KNIFE_P
L 01/21/2018 14:42:20#2 Weapon_V:  | Weapon_P: 
L 01/21/2018 14:42:22#1 g_szWeapons[ i ][ x ]: AWP_V
L 01/21/2018 14:42:22#1 g_szWeapons[ i ][ x ]: AWP_P
L 01/21/2018 14:42:22#2 Weapon_V: models/NewAwp_V.mdl | Weapon_P: 
L 01/21/2018 14:42:22#1 g_szWeapons[ i ][ x ]: KNIFE_V
L 01/21/2018 14:42:22#1 g_szWeapons[ i ][ x ]: KNIFE_P
L 01/21/2018 14:42:22#2 Weapon_V:  | Weapon_P: 
L 01/21/2018 14:42:23#1 g_szWeapons[ i ][ x ]: M4A1_V
L 01/21/2018 14:42:23#1 g_szWeapons[ i ][ x ]: M4A1_P
L 01/21/2018 14:42:23#2 Weapon_V: models/NewM4A1_V.mdl | Weapon_P: 
L 01/21/2018 14:42:23#1 g_szWeapons[ i ][ x ]: KNIFE_V
L 01/21/2018 14:42:23#1 g_szWeapons[ i ][ x ]: KNIFE_P
L 01/21/2018 14:42:23#2 Weapon_V:  | Weapon_P: 
L 01/21/2018 14:42:24#1 g_szWeapons[ i ][ x ]: M4A1_V
L 01/21/2018 14:42:24#1 g_szWeapons[ i ][ x ]: M4A1_P
L 01/21/2018 14:42:24#2 Weapon_V: models/NewM4A1_V.mdl | Weapon_P: 
L 01/21/2018 14:42:35#1 g_szWeapons[ i ][ x ]: KNIFE_V
L 01/21/2018 14:42:35#1 g_szWeapons[ i ][ x ]: KNIFE_P
L 01/21/2018 14:42:35#2 Weapon_V:  | Weapon_P: 
L 01/21/2018 14:42:37#1 g_szWeapons[ i ][ x ]: M4A1_V
L 01/21/2018 14:42:37#1 g_szWeapons[ i ][ x ]: M4A1_P
L 01/21/2018 14:42:37#2 Weapon_V: models/NewM4A1_V.mdl | Weapon_P: 
L 01/21/2018 14:43:00#1 g_szWeapons[ i ][ x ]: KNIFE_V
L 01/21/2018 14:43:00#1 g_szWeapons[ i ][ x ]: KNIFE_P
L 01/21/2018 14:43:00#2 Weapon_V:  | Weapon_P: 
L 01/21/2018 14:43:04#1 g_szWeapons[ i ][ x ]: M4A1_V
L 01/21/2018 14:43:04#1 g_szWeapons[ i ][ x ]: M4A1_P
L 01/21/2018 14:43:04#2 Weapon_V: models/NewM4A1_V.mdl | Weapon_P: 
L 01/21/2018 14:43:05#1 g_szWeapons[ i ][ x ]: KNIFE_V
L 01/21/2018 14:43:05#1 g_szWeapons[ i ][ x ]: KNIFE_P
L 01/21/2018 14:43:05#2 Weapon_V:  | Weapon_P: 
L 01/21/2018 14:43:05#1 g_szWeapons[ i ][ x ]: AUG_V
L 01/21/2018 14:43:05#1 g_szWeapons[ i ][ x ]: AUG_P
L 01/21/2018 14:43:05#2 Weapon_V: models/NewAug_V.mdl | Weapon_P: 
L 01/21/2018 14:43:11#1 g_szWeapons[ i ][ x ]: KNIFE_V
L 01/21/2018 14:43:11#1 g_szWeapons[ i ][ x ]: KNIFE_P
L 01/21/2018 14:43:11#2 Weapon_V:  | Weapon_P: 
L 01/21/2018 14:43:11#1 g_szWeapons[ i ][ x ]: M4A1_V
L 01/21/2018 14:43:11#1 g_szWeapons[ i ][ x ]: M4A1_P
L 01/21/2018 14:43:11#2 Weapon_V: models/NewM4A1_V.mdl | Weapon_P: 
L 01/21/2018 14:43:12#1 g_szWeapons[ i ][ x ]: KNIFE_V
L 01/21/2018 14:43:12#1 g_szWeapons[ i ][ x ]: KNIFE_P
L 01/21/2018 14:43:12#2 Weapon_V:  | Weapon_P: 
L 01/21/2018 14:43:12#1 g_szWeapons[ i ][ x ]: AUG_V
L 01/21/2018 14:43:12#1 g_szWeapons[ i ][ x ]: AUG_P
L 01/21/2018 14:43:12#2 Weapon_V: models/NewAug_V.mdl | Weapon_P: 
__________________

Last edited by edon1337; 01-21-2018 at 08:52.
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-21-2018 , 08:58   Re: 2D Array in Enum | cs_get_weapon_id in FM_SetModel
Reply With Quote #17

Quote:
Originally Posted by edon1337 View Post
What does 'Counter' variable represent? How would the format of the external file look like?
OMFG. It's your file format, come on dude...

Code:
V_KNIFE = models/NewKnife_V.mdl
P_KNIFE =
W_KNIFE =

V_AK47 = models/NewAk47_V.mdl
P_AK47 =
W_AK47 =

V_AUG = models/NewAug_V.mdl
P_AUG =
W_AUG =

V_AWP = models/NewAwp_V.mdl
P_AWP =
W_AWP =
Figure what Counter does by yourself, that's the least you can do. Put some effort into learning. If you can't figure it out, open the spoiler:
Spoiler
__________________

Last edited by HamletEagle; 01-21-2018 at 09:05.
HamletEagle is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 01-21-2018 , 09:07   Re: 2D Array in Enum | cs_get_weapon_id in FM_SetModel
Reply With Quote #18

Quote:
Originally Posted by HamletEagle View Post
OMFG. It's your file format, come on dude...

Code:
V_KNIFE = models/NewKnife_V.mdl
P_KNIFE =
W_KNIFE =

V_AK47 = models/NewAk47_V.mdl
P_AK47 =
W_AK47 =

V_AUG = models/NewAug_V.mdl
P_AUG =
W_AUG =

V_AWP = models/NewAwp_V.mdl
P_AWP =
W_AWP =
Figure what Counter does by yourself, that's the least you can do. Put some effort into learning.
But, that kind of format is such a pain, first of all I will have to remove the weapon_ prefix in Ham_Item_Deploy then remove the prefix of the key (V_AK47) so
PHP Code:
equali"ak47""AK47" 
Counter, tells whether it's V_/P_ or W_ model the one that's getting retrieved, right?

EDIT: I didn't look at the spoiler, so it might be incorrect
__________________

Last edited by edon1337; 01-21-2018 at 09:08.
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-21-2018 , 09:11   Re: 2D Array in Enum | cs_get_weapon_id in FM_SetModel
Reply With Quote #19

I agree, the format is stupid, but that's what you asked for, that's what I gave you.

But you are still wrong. You will have only to remove the weapon_ prefix(which is not a big deal). The key is not V_AK47, it's "ak47" because when the file is read I'm using TrieKey[2](so AK47) and then strtolower.

Yeah, that's what Counter does.
__________________

Last edited by HamletEagle; 01-21-2018 at 09:13.
HamletEagle is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 01-21-2018 , 10:07   Re: 2D Array in Enum | cs_get_weapon_id in FM_SetModel
Reply With Quote #20

Quote:
Originally Posted by HamletEagle View Post
I agree, the format is stupid, but that's what you asked for, that's what I gave you.

But you are still wrong. You will have only to remove the weapon_ prefix(which is not a big deal). The key is not V_AK47, it's "ak47" because when the file is read I'm using TrieKey[2](so AK47) and then strtolower.
I did what you said but apparently the key isn't being found.
PHP Code:
#include < amxmodx >
#include < amxmisc >
#include < hamsandwich >
#include < fakemeta >
#include < fun >

enum _:ModelType
{
    
vModel128 ],
    
pModel128 ],
    
wModel128 ]
}


new const 
g_szWeapons[ ][ ] =
{
    
"weapon_knife",
    
"weapon_ak47",
    
"weapon_aug",
    
"weapon_awp",
    
"weapon_flashbang",
    
"weapon_g3sg1",
    
"weapon_hegrenade",
    
"weapon_m3",
    
"weapon_m4a1",
    
"weapon_m249",
    
"weapon_mac10",
    
"weapon_mp5navy",
    
"weapon_p90",
    
"weapon_scout",
    
"weapon_sg552",
    
"weapon_smokegrenade",
    
"weapon_tmp",
    
"weapon_ump45",
    
"weapon_xm1014"
}

new 
Trie:g_tWeaponModels;

new const 
g_szFileIni[ ] = "GameModels.ini";

public 
plugin_init( )
{
    
register_plugin"CS Battle Royale Models""1.0""DoNii" );

    for( new 
isizeof g_szWeaponsi++ )
    
RegisterHamHam_Item_Deployg_szWeapons], "fw_HamItemDeployPost");
}

public 
plugin_precache( )
{
    
g_tWeaponModels TrieCreate( );
    
ReadFile( );
}

public 
plugin_end( )
TrieDestroyg_tWeaponModels );

public 
fw_HamItemDeployPostiEnt )
{
    if( 
pev_validiEnt ) != )
    return 
HAM_IGNORED;
    
    new 
id get_pdata_cbaseiEnt41);
    
    if( ! 
is_user_connectedid ) )
    return 
HAM_IGNORED;
    
    new 
szClassName32 ], iDataModelType ];
    
peviEntpev_classnameszClassNamecharsmaxszClassName ) );
    
    
replaceszClassNamecharsmaxszClassName ), "weapon_""" );
    
trimszClassName );
    
    
log_to_file"DebugModels.txt""#1 szClassName: %s"szClassName );
    
    if( 
TrieGetArrayg_tWeaponModelsszClassNameiDatasizeof iData ) )
    {
        if( 
iDatavModel ][ ] )
        
set_pevidpev_viewmodel2iDatavModel ] );
        
        if( 
iDatapModel ][ ] )
        
set_pevidpev_weaponmodel2iDatapModel ] );
        
        
log_to_file"DebugModels.txt""#2 vModel: %s | pModel: %s"iDatavModel ], iDatapModel ] );
    }
    return 
HAM_IGNORED;
}


ReadFile( )
{
    new 
szConfigFilePath256 ];
    
get_configsdirszConfigFilePathcharsmaxszConfigFilePath ) );
    
formatszConfigFilePathcharsmaxszConfigFilePath ), "%s/%s"szConfigFilePathg_szFileIni );
    
    new 
iFilePointer fopenszConfigFilePath"rt" );
    if( 
iFilePointer )
    {
        new 
iLineData160 ], szTrieKey32 ], szTrieValue128 ], szModelsForWeaponModelType ], iCounter;
        
        while( ! 
feofiFilePointer ) )
        {
            
fgetsiFilePointeriLineDatacharsmaxiLineData ) );
            
trimiLineData );
            
            if( 
iLineData] == '/' || iLineData] == EOS )
            {
                continue;
            }

            
strtokiLineDataszTrieKeycharsmax (szTrieKey ), szTrieValuecharsmaxszTrieValue ), '=' );
            
trimszTrieKey );
            
trimszTrieValue );
            
            switch( 
iCounter )
            {
            case 
0:
                {
                    
copyszModelsForWeaponvModel ], charsmaxszModelsForWeaponvModel ] ), szTrieValue );
                    
iCounter iCounter 1;
                    
                    if( 
szTrieValue] )
                    
precache_modelszTrieValue );
                }
            case 
1:
                {
                    
copyszModelsForWeaponpModel ], charsmax(szModelsForWeaponpModel ] ), szTrieValue )
                    
iCounter iCounter 1;
                    
                    if( 
szTrieValue] )
                    
precache_modelszTrieValue );
                }
            case 
2:
                {
                    
copyszModelsForWeaponwModel ], charsmaxszModelsForWeaponwModel ] ), szTrieValue );
                    
                    
strtolowerszTrieKey] );
                    
TrieSetArrayg_tWeaponModelsszTrieKey], szModelsForWeaponsizeof szModelsForWeapon );
                    
                    
iCounter 0;
                    
                    if( 
szTrieValue] )
                    
precache_modelszTrieValue );
                }
            }
        }
        
fcloseiFilePointer );
    }

#2 never prints
PHP Code:
L 01/21/2018 15:59:47#1 szClassName: knife
L 01/21/2018 15:59:47#1 szClassName: knife
L 01/21/2018 16:00:00#1 szClassName: m249
L 01/21/2018 16:00:01#1 szClassName: knife
L 01/21/2018 16:00:09#1 szClassName: hegrenade
L 01/21/2018 16:00:11#1 szClassName: m249
L 01/21/2018 16:03:59#1 szClassName: knife
L 01/21/2018 16:03:59#1 szClassName: knife
L 01/21/2018 16:04:20#1 szClassName: g3sg1
L 01/21/2018 16:04:22#1 szClassName: knife
L 01/21/2018 16:04:26#1 szClassName: g3sg1 
__________________

Last edited by edon1337; 01-21-2018 at 11:14.
edon1337 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 05:22.


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