AMX MOD X
Пятница, 19.04.2024, 15:55:06



Приветствую Вас Гость | RSS
[ Главная ] [ Индивидуальный конфиг под каждую карту... - AMX Mod X Форум ] [ Регистрация ] [ Вход ]
[ Новые сообщения · Участники · Правила форума · Поиск · RSS ]

Вниманию участников! Данный форум теперь является архивом и вскором времени здесь нельзя будет создавать новых тем! Просьба всем для общения и создания новых тем перейти на наш новый форум: http://amxmodx.su/

  • Страница 1 из 1
  • 1
Модератор форума: slogic, AlMod  
AMX Mod X Форум » Скриптинг » Помощь по скриптингу » Индивидуальный конфиг под каждую карту...
Индивидуальный конфиг под каждую карту...
BeZuMeCДата: Пятница, 15.05.2009, 01:46:25 | Сообщение # 1
Рядовой
Группа: Пользователи
Сообщений: 2
Репутация: 0
Статус: Не в сети
Хочу сделать простенький плагин для сервака...
Принцип работы таков:
Подгружается карта, далее в файле "конфига плагина" ищется имя данной мапы, при нахождении таковой выполняется конфиг

Code
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <engine>

new g_scTitle[]   = "Map Config";
new g_scVersion[] = "0.0.1";
new g_scAuthor[]  = "BeZuMeC";

new gConfigFile[128]

public plugin_init()  
{
     register_plugin(g_scTitle, g_scVersion, g_scAuthor)
     new configsdir[64]
     get_configsdir(configsdir,sizeof(configsdir))
     format (gConfigFile,sizeof(gConfigFile),"%s/mapconfig.cfg",configsdir)
}

public plugin_cfg(){
     if(file_exists(gConfigFile))  
     {  
         new line, stxtsize  
         new data[192]  
         new cMap[32]
         get_mapname(cMap, 31)
         new MapName[32],aTime[36]
         while((line=read_file(gConfigFile,line,data,191,stxtsize))!=0)
         {  
             if ( data[0] == ';' ) continue
             parse(data,MapName,31,aTime,35)
             if (equal(MapName,cMap))  
         {
       set_cvar_string("exec",aTime)
       break
             }
         }
     }
     else
     {
         log_amx("[MapTime] Error!!! Failed To Load mapconfig.cfg!!!")
     }
}

А это код "конфига плагина"

Code
de_dust          /maps/de_dust.cfg
de_aztec_old          /maps/de_aztec_old.cfg
fy_deathworld          /maps/fy_deathworld.cfg

Если можно, ответьте:
1. почему мой плаг не работает
2. что нужно исправить чтоб он заработал
3. как его можно оптимизовать

 
PAHANCSДата: Пятница, 15.05.2009, 07:19:39 | Сообщение # 2
Полковник
Группа: Пользователи
Сообщений: 183
Репутация: 4
Статус: Не в сети
Quote (BeZuMeC)
3. как его можно оптимизовать

К примеру так:

Code

#include <amxmodx>  
#include <amxmisc>  

new g_scTitle[]= "Map Config";
new g_scVersion[] = "0.0.1";
new g_scAuthor[]= "BeZuMeC";

new cMap[32]
new MapCfg[64]
new configsdir[64]
new gConfigFile[128]

public plugin_init() {
register_plugin(g_scTitle, g_scVersion, g_scAuthor)
register_srvcmd("exec_mapconfig", "exec_mapconfig" /* ,flags=-1, const info[]="" */)
get_configsdir(configsdir,sizeof(configsdir))
format (gConfigFile,sizeof(gConfigFile),"%s/mapconfig.cfg",configsdir)
get_mapname(cMap, 31)
format(MapCfg, 63, "maps/%s.cfg",cMap)
mapconfig_cfg()
}

public exec_mapconfig(id) {
if(id != 1) return PLUGIN_CONTINUE
mapconfig_cfg()
return PLUGIN_CONTINUE
}

public mapconfig_cfg() {
if(!file_exists(gConfigFile)) { // если нет файла gConfigFile то создаётся
new MapNewLine[130]
format(MapNewLine, 129, "// This file contains references to files containing adjusting the map^n^n%s",MapCfg)
write_file(gConfigFile, MapNewLine)
}
if(!file_exists(MapCfg)) {
write_file(MapCfg, "// This file contains adjusting the map^n^n") // если нет файла MapCfg то создаётся
}
new bool:is_contain = true
new data[192], line, stxtsize
while((line=read_file(gConfigFile,line,data,191,stxtsize))!=0) {
if(!stxtsize || data[0] == '/' && data[1] == '/') continue
if(equal(data, MapCfg)) {
server_cmd("exec %s",MapCfg)
is_contain = true
break
}
is_contain = false
}
if(is_contain == false) { // если нет записи в gConfigFile MapCfg то записывается
write_file(gConfigFile, MapCfg)
}
}



PAHANCS
 
BeZuMeCДата: Пятница, 15.05.2009, 09:39:40 | Сообщение # 3
Рядовой
Группа: Пользователи
Сообщений: 2
Репутация: 0
Статус: Не в сети
PAHANCS, огромный неземной псиб
 
predatorДата: Пятница, 15.05.2009, 10:19:26 | Сообщение # 4
Лейтенант
Группа: Пользователи
Сообщений: 54
Репутация: 5
Статус: Не в сети
А так не проще?
Code

public plugin_init ( )
{
  register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)

  new mapconfig[64]

  get_mapname ( mapconfig, sizeof ( mapconfig ) - 1 )

  format ( mapconfig, sizeof ( mapconfig ) - 1, "maps/%s.cfg", g_configsdir, mapconfig )
   
  if ( file_exists ( mapconfig ) )
   server_cmd ( "exec %s", mapconfig )
}

и вообще в amxx 1.8.х это уже встроено...

 
WhiteBearДата: Пятница, 15.05.2009, 16:23:33 | Сообщение # 5
Подполковник
Группа: Пользователи
Сообщений: 132
Репутация: 2
Статус: Не в сети
стандартные возможности amx http://wiki.alliedmods.net/Configuring_AMX_Mod_X
Code
Map Config Files

For each map, you can also add a configuration file that will execute when the map loads. This is useful to set certain settings for 3rd party maps, say, removing the freeze time on fy_iceworld.

To do this, simply create a folder in amxmodx/configs called "maps" and place a .cfg file named after the map with the settings in it, for example, you might have amxmodx/configs/maps/fy_iceworld.cfg:

mp_startmoney 16000
mp_freezetime 0
mp_timelimit 20

Be sure to include the following line into your server.cfg. This ensures that you go back (or fall back on) to your default server settings. It is suggested that anything you place in custom config files are also put in your server.cfg or amxx.cfg (at default settings) for best use of this feature.

mapchangecfgfile server.cfg

As of AMX Mod X 1.8.0, you are now able to create config files for map prefixes. To do this, create a file called prefix_<prefix>.cfg, where <prefix> would mean de, cs, awp, surf, ect. All prefix config files go in the same location as per map, the amxmodx/configs/map/ directory.

configs/maps/prefix_de.cfg  - Would run on any de_* map.
configs/maps/prefix_cs.cfg  - Would run on any cs_* map.

Configuration files are map prefix first (prefix_de.cfg) and map configuration second (de_dust2.cfg).

For Counter-Strike, you can restrict certain weapons using these config files. It requires the restmenu.amxx plugin to be enabled on your server (usually is by default). You can find more information on how to do this here.
 
PAHANCSДата: Пятница, 15.05.2009, 18:10:25 | Сообщение # 6
Полковник
Группа: Пользователи
Сообщений: 183
Репутация: 4
Статус: Не в сети
Quote (predator)
А так не проще?

Проще, но по моему методу эфективнее, и как хотелось автору темы MapCfg грузится через gConfigFile.


PAHANCS

Сообщение отредактировал PAHANCS - Пятница, 15.05.2009, 18:13:14
 
AMX Mod X Форум » Скриптинг » Помощь по скриптингу » Индивидуальный конфиг под каждую карту...
  • Страница 1 из 1
  • 1
Поиск:

AMX Mod X Russian Community © 2006-2024