Thread: [Solved] Map tier
View Single Post
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 05-18-2019 , 20:23   Re: Map tier
Reply With Quote #6

What the...

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

new const g_szPluginName[]     = "Map Tiers";
new const 
g_szPluginVersion[] = "v1.0.0";
new const 
g_szPluginAuthor[] = "Cram";

new const 
g_szINIFileName[]     = "maptiers.ini";

new 
g_szCurrentMap[32];
new 
g_szTier[16];

public 
plugin_init() {
    
    
register_plugin(g_szPluginNameg_szPluginVersiong_szPluginAuthor);
    
    
register_clcmd("say /maptier""cmdShowCurrentMapTier");
    
    
get_mapname(g_szCurrentMapcharsmax(g_szCurrentMap));

    
getCurrentMapTier();
}

public 
cmdShowCurrentMapTier(id) {
    
    
client_print(idprint_chat"[MAP TIERS] Current: %s, Tier: %s"g_szCurrentMapg_szTier);
    return 
PLUGIN_CONTINUE;
}

stock getCurrentMapTier() {

    new 
szINIFilePath[256];

    
get_configsdir(szINIFilePathcharsmax(szINIFilePath));
    
format(szINIFilePathcharsmax(szINIFilePath),"%s/%s"szINIFilePathg_szINIFileName);
    
    
// Make sure each line in the INI is written properly "<anything><whitespace><anything>"
    // Otherwise, the line will be ignored and will be logged
    
new const szPattern[] = "^(.+)(\w)(.+)$";

    new 
pFile fopen(szINIFilePath"r");
    new 
szFileLine[64];
    new 
iFaultyLines 0;
    
    
copy(g_szTiercharsmax(g_szTier), "Not Specified");
    
    while(
fgets(pFileszFileLinecharsmax(szFileLine))) {
        
        if(
regex_match(szFileLineszPattern)) {
            
            new 
szLeft[32], szRight[16];
            
split(szFileLineszLeftcharsmax(szLeft), szRightcharsmax(szRight), " ");
            
            if(
equal(szLeftg_szCurrentMap)) {
                
                
copy(g_szTiercharsmax(g_szTier), szRight);
                break;
            }
        }
        else
            
iFaultyLines++;
    }
    
fclose(pFile);
    
    if(
iFaultyLines 0) {
        
        
// Log all of the imporperly formatted lines in your INI file to fix rather than cause an error
        
new szLog[256];
        
format(szLogcharsmax(szLog), "[MAP TIERS] In: %s, number of improperly formatted lines: (%d)"g_szINIFileNameiFaultyLines);
        
        
server_print(szLog);
        
log_amx(szLog);
    }

Try this now. I'm still learning Regular Expressions in Pawn. Got used to Java's syntax and methods lmao
redivcram is offline