i want to run it on all maps.

Сообщения
3
Реакции
0
it only works with the map name in ambience.ini.
i want it to work on all maps.

C#:
/*
    New Style Ambience v3.1
                       */

#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fakemeta>

static const PLUGIN_NAME[] = "New Style Ambience"
static const PLUGIN_VERSION[] = "3.1"
static const PLUGIN_AUTHOR[] = "rrduna"

// map name
new g_map_name[32]

// sky
new g_sky_name[64]
new g_sky_enable
new g_sky_suffix[][] = { "bk", "dn", "ft", "lf", "rt", "up" }

// weather
new g_weather_rain
new g_weather_thunder
new g_weather_snow

// map light
new g_light_level[32]

// array thunder sounds
new thunder_sounds[][] = {
    "ns_ambience/thunder1",
    "ns_ambience/thunder2",
    "ns_ambience/thunder3",
    "ns_ambience/thunder4",
    "ns_ambience/thunder5"
}

public plugin_init(){
    register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
    
    // random message informing the activated map
    set_task(random_float(60.0, 120.0), "show_map_enabled")    
    
    return PLUGIN_CONTINUE;
}

public plugin_precache(){
     
    // load customization file
    if(!load_customization_from_files()) return;
    
    // precache tga files to sky
    new precache[64]
    for(new i; i < sizeof g_sky_suffix; i++){ 
        formatex(precache, 63, "gfx/env/%s%s.tga", g_sky_name, g_sky_suffix[i])
        precache_generic(precache)
    }

    // checking the map
    checking_map();
    
    // precache sounds
    precache_sound("ns_ambience/rain.wav");
    precache_sound("ns_ambience/snow_wind.wav");
    precache_sound("ns_ambience/thunder1.wav");
    precache_sound("ns_ambience/thunder2.wav");
    precache_sound("ns_ambience/thunder3.wav");
    precache_sound("ns_ambience/thunder4.wav");
    precache_sound("ns_ambience/thunder5.wav");
}

// file ambience.ini
load_customization_from_files(){
     
    new file[64]
    get_configsdir(file, charsmax(file))
    format(file, charsmax(file), "%s/%s", file, "ambience.ini")
    
    if (!file_exists(file)){
        new error[100]
        formatex(error, charsmax(error), "Cannot load customization file %s", file)
        set_fail_state(error)
    }
        
    new linedata[36], key[16], value[16], section
    new open=fopen(file,"r") 
     
    while(!feof(open)){
        linedata[0]='^0' 
        fgets(open, linedata, charsmax(linedata))
        trim(linedata) 
        
        if(!linedata[0] || linedata[0] == ';') continue;
        if (linedata[0] == '['){
            section++
            continue;
        }
        
        strtok(linedata, key, charsmax(key), value, charsmax(value), '=')
        trim(key)
        trim(value)
        
        if(section){
            section = 0
            if(g_map_name[0] && g_sky_enable && g_sky_name[0] && g_weather_rain && g_weather_thunder && g_weather_snow && g_light_level[0]){
                fclose(open)
                return FMRES_IGNORED
            }
        }
        
        if (equal(key, "MAP_NAME"))
            copy(g_map_name, charsmax(g_map_name), value)
        
        else if (equal(key, "SKY_ENABLE"))
            g_sky_enable = str_to_num(value)
        
        else if (equal(key, "SKY_NAME"))
            copy(g_sky_name, charsmax(g_sky_name), value)
            
        else if (equal(key, "RAIN_ENABLE"))
            g_weather_rain = str_to_num(value)
            
        else if (equal(key, "THUNDER_ENABLE"))
            g_weather_thunder = str_to_num(value)
            
        else if (equal(key, "SNOW_ENABLE"))
            g_weather_snow = str_to_num(value)
            
        else if (equal(key, "LIGHT_LEVEL"))
            copy(g_light_level, charsmax(g_light_level), value)
    }
    return FMRES_IGNORED
}

public checking_map(){
    new current_map[32]
    get_mapname(current_map, 31)
    
    if (g_map_name[0] == '0')
    return;
    
    if (equali(current_map, g_map_name[0]) ){
        
        // load func
        ambience_effects();
    }
}

public show_map_enabled(id){
    if (g_map_name[0] != '0'){
        set_task(random_float(60.0, 120.0), "show_map_enabled")
        client_print(id, print_chat, "[AMXX] New Style Ambience is enabled on the map: %s", g_map_name[0]);
    }
}

public ambience_effects(){
    
    // sky
    if (g_sky_name[0] && g_sky_enable){
        set_cvar_string("sv_skyname", g_sky_name)
        
        set_cvar_num("sv_skycolor_r", 0)
        set_cvar_num("sv_skycolor_g", 0)
        set_cvar_num("sv_skycolor_b", 0)
    }
    
    // rain
    if (g_weather_rain){
        if (g_weather_rain == 0)
        return;
        
        if (g_weather_rain == 1){
            // load event
            engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "env_rain"));
            
            // load rain sound
            set_task(14.0, "rain_sound");
        }
    }
    
    // thunder
    if (g_weather_thunder){
        if (g_weather_thunder == 0)
        return;
        
        if (g_weather_thunder == 1){
            // load thunder events
            set_task(random_float(30.0,  60.0), "thunder_effect");
        }
    }

    // snow
    if (g_weather_snow){
        if (g_weather_snow == 0)
        return;
        
        if (g_weather_snow == 1){
            // load event
            engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "env_snow"));
            
            // load snow wind sound
            set_task(random_float(40.0,  80.0), "snow_wind_sound");
        }
    }
    
    // map light
    if (g_light_level[0]){
        if (g_light_level[0] == '0')
        return;
        
        if (g_light_level[0] >= 'a' && g_light_level[0] <= 'z'){
            
            // light defined in ambience.ini
            set_lights(g_light_level);
        }
    }
}

// raind sound
public rain_sound(){
    set_task(14.0, "rain_sound");
    client_cmd(0,"spk ns_ambience/rain");
}

// thunder effects (light and sound)
public thunder_effect() {
    set_task(random_float(30.0,  60.0), "thunder_effect");
    
    // clear light 
    set_lights("z");
    
    // random sounds
    client_cmd(0,"spk %s",thunder_sounds[random(sizeof thunder_sounds)]);
    
    // restore the light
    set_task(0.3, "restore_light")
    return FMRES_HANDLED
}

// restores the light defined in ambience.ini or not
public restore_light() {
    if (g_light_level[0] == '0'){
        set_lights("m");
    }
    else{
        set_lights(g_light_level);
    }
}

// snow wind sound
public snow_wind_sound(){
    set_task(random_float(40.0,  80.0), "snow_wind_sound");
    client_cmd(0,"spk ns_ambience/snow_wind");
}

public client_putinserver(id){
    set_task(35.0, "confirmation_message", id)
}

public confirmation_message(id){
    if (g_map_name[0] == '0'){
        client_print(id, print_chat, "[AMXX] New Style Ambience: No map name has been defined.");
    }
    
    new current_map[32]
    get_mapname(current_map, 31)
    if (equali(current_map, g_map_name[0])){
        if (g_sky_enable == 1){
            client_print(id, print_chat, "[AMXX] New Style Ambience: custom sky activated.");
        }
        if (g_weather_rain == 1){
            client_print(id, print_chat, "[AMXX] New Style Ambience: rain activated.");
        }
        if (g_weather_thunder == 1){
            client_print(id, print_chat, "[AMXX] New Style Ambience: thunder activated.");
        }
        if (g_weather_snow == 1){
            client_print(id, print_chat, "[AMXX] New Style Ambience: snow activated.");
        }
        if (g_light_level[0] != '0'){
            client_print(id, print_chat, "[AMXX] New Style Ambience: custom map light activated.");
        }
    }
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ ansicpg1252\\ deff0\\ deflang1046{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ f0\\ fs16 \n\\ par }
*/
 
Последнее редактирование:
Сообщения
491
Реакции
89
Помог
5 раз(а)
Удали всё, что связано с
Код:
g_map_name,current_map
etc.
27 Фев 2024
Pessimist
Код:
The thread should post attempts (diff code or sequence of actions) to find a solution on your own.
 
Сообщения
13
Реакции
2
Помог
1 раз(а)
1. Delete everything related to g_map_name,current_map
2. Delete 136 - 148 (check map function)
3. Line 61 delete and change to ambience_effects();
 
Сообщения
18
Реакции
4
Помог
1 раз(а)
Pessimist,

Код:
public plugin_precache(){
    
    // load customization file
    if(!load_customization_from_files()) return;
    
    // precache tga files to sky
    new precache[64]
    for(new i; i < sizeof g_sky_suffix; i++){
        formatex(precache, 63, "gfx/env/%s%s.tga", g_sky_name, g_sky_suffix[i])
        precache_generic(precache)
    }

    // get the current map name
    new mapname[32];
    get_mapname(mapname, sizeof(mapname));

    // checking the map
    checking_map(mapname);
    
    // precache sounds
    precache_sound("ns_ambience/rain.wav");
    precache_sound("ns_ambience/snow_wind.wav");
    precache_sound("ns_ambience/thunder1.wav");
    precache_sound("ns_ambience/thunder2.wav");
    precache_sound("ns_ambience/thunder3.wav");
    precache_sound("ns_ambience/thunder4.wav");
    precache_sound("ns_ambience/thunder5.wav");
}
 

Пользователи, просматривающие эту тему

Сейчас на форуме нет ни одного пользователя.
Сверху Снизу