AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Get mapname from config file (https://forums.alliedmods.net/showthread.php?t=77272)

Mlk27 09-09-2008 06:52

Get mapname from config file
 
well i want this script to use config file which contains list of map to remove weapon entities from.


weapon_stripper.cfg
Quote:

de_map1
de_map2
cs_map
Weapons Stripper
Code:
#include <amxmodx> #include <fakemeta> #define PLUGIN    "Weapons Stripper" #define AUTHOR    "Jim" #define VERSION    "1.0" public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR) } public plugin_precache() {     register_forward(FM_Spawn, "fwd_spawn") } public fwd_spawn(ent) {     new classname[32]     pev(ent, pev_classname, classname, 31)     if(classname[0] == 'a' && classname[1] == 'r')     {         engfunc(EngFunc_RemoveEntity, ent)         return FMRES_SUPERCEDE     }     return FMRES_IGNORED }

thanks in advanced and +1 karma

Exolent[jNr] 09-09-2008 07:19

Re: Get mapname from config file
 
Just use per-map feature for plugins. Read up on the AMXX Changelog and you will see it.

Mlk27 09-09-2008 07:27

Re: Get mapname from config file
 
i know that but i prefer this way since config in one file is more simple to manage

Alka 09-09-2008 07:35

Re: Get mapname from config file
 
You can use this stock
Code:
stock bool:is_map_in_file(const file[], const map[]) {  new iFile = fopen(file, "rt");    if(!iFile)   return false;    new szBuffer[32];  while(!feof(iFile))  {   fgets(iFile, szBuffer, sizeof szBuffer - 1);   trim(szBuffer);     if(!sBuffer[0] || sBuffer[0] == ';')    continue;     if(equali(szBuffer, map, strlen(map)))    return true;  }  fclose(iFile);  return false; }

if(is_map_in_file("../file path", "de_dust2"))
{
//map de_dust2 is in file.
}

Exolent[jNr] 09-09-2008 15:19

Re: Get mapname from config file
 
@Alka, you had a few errors:
Code:
stock bool:is_map_in_file(const file[], const map[]) {  new iFile = fopen(file, "rt");    if(!iFile)   return false;    new szBuffer[64], szMap[32];  // I think it's better to parse the map and other text in case of a comment next to it?  while(!feof(iFile))  {   fgets(iFile, szBuffer, sizeof szBuffer - 1);   trim(szBuffer);     if(!szBuffer[0] || szBuffer[0] == ';') // you put sBuffer, not szBuffer    continue;     parse(szBuffer, szMap, sizeof szMap - 1);     if(equali(szMap, map, strlen(map)))   {    fclose(iFile); // you forgot to close    return true;   }  }  fclose(iFile);  return false; }


All times are GMT -4. The time now is 03:09.

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