I got this code that reads steam ids from a config file.
After that when you plant/defuse the bomb, the plugin will check the steamids stored in the cfg and print in chat a message.
Like:
your steamidxxx -> [tag/etc] Player planted the bomb
non steamidxxx from -cfg -> Player planted the bomb...
But what if I want to use this for other functions? I always need to copy/paste the same function?
Isn't this a mistake?
How to improve this?
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <csx>
#include <colorchat>
new Trie:g_tAuthIdOfPeople
#define FILE "/Steams.cfg"
#define cm(%0) ( sizeof(%0) - 1 )
public plugin_init()
{
g_tAuthIdOfPeople = TrieCreate()
ReadFile()
}
public ReadFile()
{
new szFilePath[ 128 ]
get_configsdir( szFilePath, cm( szFilePath ) )
add( szFilePath, cm( szFilePath ), FILE )
new f = fopen( szFilePath, "rt" )
if( !f )
{
new szMessage[ 256 ]
formatex( szMessage, cm( szMessage ), "Unable to open %s", szFilePath )
set_fail_state( szMessage )
}
new szData[ 128 ]
new szAuthID[ 35 ]
new szDummy[ 4 ]
while( !feof( f ) )
{
fgets( f, szData, cm( szData ) )
if( !szData[ 0 ] || szData[ 0 ] == ';' || szData[ 0 ] == '/' && szData[ 1 ] == '/' )
{
continue
}
trim( szData )
parse( szData, szAuthID, cm( szAuthID ), szDummy, cm( szDummy ) )
TrieSetCell( g_tAuthIdOfPeople, szAuthID, 1 )
}
fclose( f )
}
public bomb_planted(index)
{
new szAuthID[ 35 ]; get_user_authid( index, szAuthID, cm( szAuthID ) )
new iDummy;
new iPlayers[ 32 ], iNum, i, Players;
get_players( iPlayers, iNum, "ceh", "TERRORIST" )
for( i = 0; i < iNum; i++ )
{
Players = iPlayers[ i ];
if( TrieGetCell( g_tAuthIdOfPeople, szAuthID, iDummy ) )
{
ColorChat(Players, GREEN, "[tag/etc] %s ^1planted the bomb", get_nick(index) )
}
else
ColorChat(Players, GREEN, "%s ^1planted the bomb", get_nick(index) )
}
}
public bomd_defused(index)
{
// Paste the code below again? This is not the best way right?
// How to improve?
}
get_nick( const index )
{
new szName[ 32 ]; get_user_name( index, szName, cm( szName ) );
return szName;
}