Raised This Month: $32 Target: $400
 8% 

Solved Map tier


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Point
Junior Member
Join Date: Oct 2014
Old 05-18-2019 , 00:25   Map tier
Reply With Quote #1

Hello alliedmodders! I tried for some times but failed to create a simple plugin. And i thought to take my chances here. Can someone create for me a plugin that read maps names from a .ini file or something similar and besides that to add an atribute.
Example: mapstier.ini

deathrun_arctic - easy
deathrun_temple - hard

and so on in order to have a client cmd to display it, such as /tier , /mapinfo whatever.

If anyone has the time and is willing to help me i'd appreciate. Thanks in advance

Last edited by Point; 05-18-2019 at 20:54.
Point is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 05-18-2019 , 07:51   Re: Map tier
Reply With Quote #2

Untested:

PHP Code:
#include <amxmodx>
#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 const 
Regex:rPattern regex_compile(szPatternreterrcharsmax(err));
    new 
reterr[32];

    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(szFileLinerPattern)) {
            
            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);
    }

And in your maptiers.ini file:

Code:
deathrun_arctic Easy
deathrun_temple Hard
etc...
Make sure you follow the correct formatting and separate map name and tier by whitespace.

If you cannot compile and get any error, please post them.

Last edited by redivcram; 05-18-2019 at 08:08. Reason: Edit number googol: Should be fine now.
redivcram is offline
Point
Junior Member
Join Date: Oct 2014
Old 05-18-2019 , 19:34   Re: Map tier
Reply With Quote #3

PHP Code:
maptier.sma(40) : error 027invalid character constant
maptier
.sma(40) : error 027invalid character constant
maptier
.sma(41) : error 017undefined symbol "ret"
maptier.sma(41) : error 017undefined symbol "err"
maptier.sma(41) : error 029invalid expressionassumed zero
maptier
.sma(41) : fatal error 107too many error messages on one line 
Point is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 05-18-2019 , 19:41   Re: Map tier
Reply With Quote #4

@point try with 1.9.0 (1.8.3) amxmodx ?
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
Point
Junior Member
Join Date: Oct 2014
Old 05-18-2019 , 19:57   Re: Map tier
Reply With Quote #5

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];

new 
reterr[32];

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 const 
Regex:rPattern regex_compile(szPatternreterrcharsmax(err));
 
//   new ret, err[32];

    
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(szFileLinerPattern)) {
            
            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);
    }

now i get this
PHP Code:
maptier.sma(42) : error 027invalid character constant
maptier
.sma(42) : error 027invalid character constant
maptier
.sma(54) : error 035argument type mismatch (argument 2)
maptier.sma(79) : warning 204symbol is assigned a value that is never used"rPattern" 
@JocAnis i've tried on 1.9.0 too
Point is offline
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
Point
Junior Member
Join Date: Oct 2014
Old 05-18-2019 , 20:53   Re: Map tier
Reply With Quote #7

>
PHP Code:
new const szPattern[] = "(.+)(\w)(.+)$"
Works perfectly. Thank you very much!
Point is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 05-18-2019 , 21:01   Re: Map tier
Reply With Quote #8

Quote:
Originally Posted by Point View Post
>
PHP Code:
new const szPattern[] = "(.+)(\w)(.+)$"
Works perfectly. Thank you very much!
Awesome!
redivcram is offline
Reply



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 11:39.


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