Raised This Month: $ Target: $400
 0% 

How to improve this code?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
pob18
Member
Join Date: Jun 2014
Old 07-02-2014 , 07:35   How to improve this code?
Reply With Quote #1

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 
szFilePath128 ]
    
get_configsdirszFilePathcmszFilePath ) )
    
addszFilePathcmszFilePath ), FILE )

    new 
fopenszFilePath"rt" )
    
    if( !
)
    {
        new 
szMessage256 ]
        
formatexszMessagecmszMessage ), "Unable to open %s"szFilePath )
        
set_fail_stateszMessage )
    }
    
    new 
szData128 ]
    new 
szAuthID35 ]
    new 
szDummy]
    
    while( !
feof) )
    {
    
fgetsfszDatacmszData ) )
        
    if( !
szData] || szData] == ';' || szData] == '/' && szData] == '/' )
    {
        continue
    }

    
trimszData )
    
parseszDataszAuthIDcmszAuthID ), szDummycmszDummy ) )
        
    
TrieSetCellg_tAuthIdOfPeopleszAuthID)
        
    }
    
    
fclose)
}

public 
bomb_planted(index)
{
    new 
szAuthID35 ]; get_user_authidindexszAuthIDcmszAuthID ) )
    new 
iDummy;
    
    new 
iPlayers32 ], iNumiPlayers;
    
get_playersiPlayersiNum"ceh""TERRORIST" )
    
    for( 
0iNumi++ )
    {
    
Players iPlayers];
        if( 
TrieGetCellg_tAuthIdOfPeopleszAuthIDiDummy ) )
        {
        
ColorChat(PlayersGREEN"[tag/etc] %s ^1planted the bomb"get_nick(index) )
        }   
        
        else
        
ColorChat(PlayersGREEN"%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 
szName32 ]; get_user_nameindexszNamecmszName ) );
    return 
szName;

pob18 is offline
 



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 21:17.


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