Map Time

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1189
Gender:
United States of America

Map Time

Post by Archive-Poster »

I've done this code for a friend and I thought that it can be useful for other people.
This code adds different mp_timelimit for each map, which is good for public servers.

Code:

Code: Select all

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Map Time"
#define VERSION "1.0"
#define AUTHOR "EFFx"

#define LOG_FILE    "mt_log.log"

new g_iValue

public plugin_init() 
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    
    readIniFile()
}

readIniFile()
{
    new szConfig[32], szIniFile[115], szMapName[32]
    get_configsdir(szConfig, charsmax(szConfig))
    get_mapname(szMapName, charsmax(szMapName))
    formatex(szIniFile, charsmax(szIniFile), "%s/maps_time.ini", szConfig)
    if(!file_exists(szIniFile)) 
    {
        log_to_file(LOG_FILE, "[EFFx S]: Archive '%s' not found.", szIniFile)
        return
    }

    new iFile = fopen(szIniFile, "rt"), bool:bFound = false
    while(!feof(iFile))
    {
        new szBuffer[512], szKey[50], szValue[554]
        fgets(iFile, szBuffer, charsmax(szBuffer))
        trim(szBuffer)
        
        if(!szBuffer[0] || (szBuffer[0] == ';') || (szBuffer[0] == '/' && szBuffer[1] == '/'))
            continue

        strtok(szBuffer, szKey, charsmax(szKey), szValue, charsmax(szValue), '=')

        trim(szKey)
        trim(szValue)
        
        if(equal(szMapName, szKey))
        {
            if(!szValue[0])
            {
                log_to_file(LOG_FILE, "[EFFx S]: %s's time value not found. The map will use the default value.", szKey)
            }
            else
            {
                bFound = true
                g_iValue = str_to_num(szValue)
                break
            }
        }
        
    }
    fclose(iFile)

    if(!bFound)
    {
        log_to_file(LOG_FILE, "[EFFx S]: The current map is not in the maps_time.ini. The map will use the default value.")
    }
    else
    {
        if(g_iValue)
        {
            set_task(2.0, "setCvarValue")
        }
    }

}

public setCvarValue() 
{
    server_cmd("mp_timelimit %d", g_iValue)
} 
maps_time.ini

Code: Select all

; Format:
; MAPNAME = TIME IN MINUTES
; Example: de_dust2 = 55

de_inferno = 30

Who is online

Users browsing this forum: No registered users and 0 guests