Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
|
01-21-2018
, 08:23
Re: 2D Array in Enum | cs_get_weapon_id in FM_SetModel
|
#14
|
Quote:
Originally Posted by Bugsy
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_V[ 128 ],
Weapon_P[ 128 ],
Weapon_W[ 128 ]
}
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 szConfigsName[ 256 ], szFilename[ 512 ];
get_configsdir( szConfigsName, charsmax( szConfigsName ) );
formatex( szFilename, charsmax( szFilename ), "%s/%s", szConfigsName, g_szFileIni );
new iFile = fopen( szFilename, "r" );
if( iFile )
{
new szData[ 128 ], szValue[ 64 ], szKey[ 32 ];
while( ! feof( iFile ) )
{
fgets( iFile, szData, charsmax( szData ) );
trim( szData );
switch( szData[ 0 ] )
{
case EOS, '#', ';':
continue;
default:
{
strtok( szData, szKey, charsmax( szKey ), szValue, charsmax( szValue ), '=' );
trim( szKey );
trim( szValue );
if( szValue[ 0 ] == EOS )
continue;
TrieSetString( g_tWeaponModels, szKey, szValue );
}
}
}
}
fclose( iFile );
}
public plugin_init( )
{
register_plugin( "CS Battle Royale Models", "1.0", "DoNii" );
ReadFile( );
for( new i; i < sizeof g_szWeapons; i++ )
RegisterHam( Ham_Item_Deploy, g_szWeapons[ i ][ 0 ], "fw_HamItemDeployPost", 1 );
}
public plugin_precache( )
{
g_tWeaponModels = TrieCreate( );
new iData[ ModelData ];
for( new i; i < sizeof g_szWeapons; i++ )
{
for( new x=1; x <= 3; x++ )
{
if( TrieGetString( g_tWeaponModels, g_szWeapons[ i ][ x ], iData, sizeof( iData ) ) )
{
precache_model( iData[ Weapon_V ] );
precache_model( iData[ Weapon_P ] );
precache_model( iData[ Weapon_W ] );
}
}
}
}
public fw_HamItemDeployPost( iEnt )
{
if( pev_valid( iEnt ) != 2 )
return HAM_IGNORED;
new id = get_pdata_cbase( iEnt, 41, 4 );
if( ! is_user_connected( id ) )
return HAM_IGNORED;
new iData[ ModelData ];
new szClassName[ 32 ];
pev( iEnt, pev_classname, szClassName, charsmax( szClassName ) );
for( new i; i < sizeof g_szWeapons; i++ )
{
if( equal( szClassName, g_szWeapons[ i ][ 0 ] ) )
{
for( new x = 1; x <= 2; x++ )
{
TrieGetString( g_tWeaponModels, g_szWeapons[ i ][ x ], iData, sizeof iData );
log_to_file( "TestDebug.txt", "#1 g_szWeapons[ i ][ x ]: %s", g_szWeapons[ i ][ x ] );
}
}
}
log_to_file( "TestDebug.txt", "#2 Weapon_V: %s | Weapon_P: %s", iData[ Weapon_V ], iData[ Weapon_P ] );
set_pev( id, pev_viewmodel2, iData[ Weapon_V ] );
set_pev( id, pev_weaponmodel2, iData[ Weapon_P ] );
return HAM_IGNORED;
}
Quote:
Originally Posted by HamletEagle
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(ConfigFilePath, charsmax(ConfigFilePath), "%s/%s", ConfigFilePath, ConfigFileName)
new FilePointer = fopen(ConfigFilePath,"rt")
if(FilePointer)
{
new LineData[160], TrieKey[32], TrieValue[128], ModelsForWeapon[ModelType], Counter
while(!feof(FilePointer))
{
fgets(FilePointer, LineData, charsmax(LineData))
trim(LineData)
if(LineData[0] == '/' || LineData[0] == EOS)
{
continue
}
strtok(LineData, TrieKey, charsmax(TrieKey), TrieValue, charsmax(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(HandleModelsTrie, TrieKey[2], ModelsForWeapon, sizeof ModelsForWeapon)
Counter = 0
}
}
}
fclose(FilePointer)
}
}
|
What does 'Counter' variable represent? How would the format of the external file look like?
__________________
|
|