Raised This Month: $51 Target: $400
 12% 

enable/disable plugin by cvar? Is it possible?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
-ynk
Junior Member
Join Date: Jun 2009
Old 06-16-2009 , 18:58   enable/disable plugin by cvar? Is it possible?
Reply With Quote #1

Hi there ;)

I have one question.. Is it possible to turn on plugin by cvar? For example, i have daily mapcycle(mapsycle.txt) and when comes night, i with task plugin turn mapchooser plugin on, and map rotation goes by maps.ini .
-ynk is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-16-2009 , 19:10   Re: enable/disable plugin by cvar? Is it possible?
Reply With Quote #2

Quote:
Originally Posted by -ynk View Post
Is it possible to turn on plugin by cvar?
Yes.

Quote:
Originally Posted by -ynk View Post
For example, i have daily mapcycle(mapsycle.txt) and when comes night, i with task plugin turn mapchooser plugin on, and map rotation goes by maps.ini .
What is "task plugin"?
__________________
fysiks is offline
-ynk
Junior Member
Join Date: Jun 2009
Old 06-17-2009 , 06:50   Re: enable/disable plugin by cvar? Is it possible?
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
Yes.

so? Could you explain me ?



What is "task plugin"?
http://forums.alliedmods.net/showthread.php?p=11751
A task scheduler to perform server commands at a specified interval or a specific time. Based on Clanmod's "cm_task".

For example to restart the round every 5 minutes use:
amx_task 5 "sv_restart 1" mr

My example:

amx_task 00:00 "enable plugin cvar" t
amx_task 00:01 "amx_say Night mode on" t
-ynk is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-17-2009 , 17:39   Re: enable/disable plugin by cvar? Is it possible?
Reply With Quote #4

Ok, so what you need is a cvar in the "mapchooser" plugin that will turn on and off it's functionality. Then with that and your task plugin you can turn the mapchooser on at midnight. Is this correct?
__________________
fysiks is offline
-ynk
Junior Member
Join Date: Jun 2009
Old 06-17-2009 , 18:01   Re: enable/disable plugin by cvar? Is it possible?
Reply With Quote #5

yes, and i don't know how to script that.. :/

The other way how i can do that, is crontab

Code:
0    23   *    *    *    cd /.../cstrike/addons/amxmodx/configs/ && mv plugins.ini plugins_day.ini && mv plugins_night.ini plugins.ini
0    9    *    *    *    cd /.../cstrike/addons/amxmodx/configs/ && mv plugins.ini plugins_night.ini && mv plugins_day.ini plugins.ini
-ynk is offline
Old 06-17-2009, 18:14
fra3nah.com
This message has been deleted by devicenull.
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-17-2009 , 18:28   Re: enable/disable plugin by cvar? Is it possible?
Reply With Quote #6

Quote:
Originally Posted by -ynk View Post
yes, and i don't know how to script that.. :/

The other way how i can do that, is crontab

Code:
0    23   *    *    *    cd /.../cstrike/addons/amxmodx/configs/ && mv plugins.ini plugins_day.ini && mv plugins_night.ini plugins.ini
0    9    *    *    *    cd /.../cstrike/addons/amxmodx/configs/ && mv plugins.ini plugins_night.ini && mv plugins_day.ini plugins.ini
Interesting. How would it get reset to day settings? Do you still want the cvar for mapchooser?
__________________
fysiks is offline
-ynk
Junior Member
Join Date: Jun 2009
Old 06-17-2009 , 18:48   Re: enable/disable plugin by cvar? Is it possible?
Reply With Quote #7

yes, it will be much easier ;)
-ynk is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-17-2009 , 23:21   Re: enable/disable plugin by cvar? Is it possible?
Reply With Quote #8

If you are using the default mapchooser:

PHP Code:
/* AMX Mod X
*   Nextmap Chooser Plugin
*
* by the AMX Mod X Development Team
*  originally developed by OLO
*
* This file is part of AMX Mod X.
*
*
*  This program is free software; you can redistribute it and/or modify it
*  under the terms of the GNU General Public License as published by the
*  Free Software Foundation; either version 2 of the License, or (at
*  your option) any later version.
*
*  This program is distributed in the hope that it will be useful, but
*  WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
*  General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software Foundation,
*  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*  In addition, as a special exception, the author gives permission to
*  link the code of this program with the Half-Life Game Engine ("HL
*  Engine") and Modified Game Libraries ("MODs") developed by Valve,
*  L.L.C ("Valve"). You must obey the GNU General Public License in all
*  respects for all of the code used other than the HL Engine and MODs
*  from Valve. If you modify this file, you may extend this exception
*  to your version of the file, but you are not obligated to do so. If
*  you do not wish to do so, delete this exception statement from your
*  version.
*/

#include <amxmodx>
#include <amxmisc>

#define SELECTMAPS  5

#define charsof(%1) (sizeof(%1)-1)

new Array:g_mapName;
new 
g_mapNums;

new 
g_nextName[SELECTMAPS]
new 
g_voteCount[SELECTMAPS 2]
new 
g_mapVoteNum
new g_teamScore[2]
new 
g_lastMap[32]

new 
g_coloredMenus
new bool:g_selected false

new g_pEnabled

public plugin_init()
{
    
register_plugin("Nextmap Chooser"AMXX_VERSION_STR"AMXX Dev Team")
    
register_dictionary("mapchooser.txt")
    
register_dictionary("common.txt")
    
    
g_mapName=ArrayCreate(32);
    
    new 
MenuName[64]
    
    
format(MenuName63"%L""en""CHOOSE_NEXTM")
    
register_menucmd(register_menuid(MenuName), (-1^(-1<<(SELECTMAPS+2))), "countVote")
    
register_cvar("amx_extendmap_max""90")
    
register_cvar("amx_extendmap_step""15")
    
    
// Add Cvar to enable functionality.
    
g_pEnabled register_cvar("mapchooser_enable""0")

    if (
cstrike_running())
        
register_event("TeamScore""team_score""a")

    
get_localinfo("lastMap"g_lastMap31)
    
set_localinfo("lastMap""")

    new 
maps_ini_file[64]
    
get_configsdir(maps_ini_file63);
    
format(maps_ini_file63"%s/maps.ini"maps_ini_file);
    
    if (!
file_exists(maps_ini_file))
        
get_cvar_string("mapcyclefile"maps_ini_file63)
    if (
loadSettings(maps_ini_file))
        
// set_task(15.0, "voteNextmap", 987456, "", 0, "b")
        
set_task(15.0"checkEnabled"987456""0"b")

    
g_coloredMenus colored_menus()
    
}

public 
checkEnabled()
{
    if(
get_pcvar_num(g_pEnabled))
    {
        
voteNextmap()
    }
}

public 
checkVotes()
{
    new 
0
    
    
for (new 0g_mapVoteNum; ++a)
        if (
g_voteCount[b] < g_voteCount[a])
            
a

    
    
if (g_voteCount[SELECTMAPS] > g_voteCount[b]
        && 
g_voteCount[SELECTMAPS] > g_voteCount[SELECTMAPS+1])
    {
        new 
mapname[32]
        
        
get_mapname(mapname31)
        new 
Float:steptime get_cvar_float("amx_extendmap_step")
        
set_cvar_float("mp_timelimit"get_cvar_float("mp_timelimit") + steptime)
        
client_print(0print_chat"%L"LANG_PLAYER"CHO_FIN_EXT"steptime)
        
log_amx("Vote: Voting for the nextmap finished. Map %s will be extended to next %.0f minutes"mapnamesteptime)
        
        return
    }
    
    new 
smap[32]
    if (
g_voteCount[b] && g_voteCount[SELECTMAPS 1] <= g_voteCount[b])
    {
        
ArrayGetString(g_mapNameg_nextName[b], smapcharsof(smap));
        
set_cvar_string("amx_nextmap"smap);
    }

    
    
get_cvar_string("amx_nextmap"smap31)
    
client_print(0print_chat"%L"LANG_PLAYER"CHO_FIN_NEXT"smap)
    
log_amx("Vote: Voting for the nextmap finished. The nextmap will be %s"smap)
}

public 
countVote(idkey)
{
    if (
get_cvar_float("amx_vote_answers"))
    {
        new 
name[32]
        
get_user_name(idname31)
        
        if (
key == SELECTMAPS)
            
client_print(0print_chat"%L"LANG_PLAYER"CHOSE_EXT"name)
        else if (
key SELECTMAPS)
        {
            new 
map[32];
            
ArrayGetString(g_mapNameg_nextName[key], mapcharsof(map));
            
client_print(0print_chat"%L"LANG_PLAYER"X_CHOSE_X"namemap);
        }
    }
    ++
g_voteCount[key]
    
    return 
PLUGIN_HANDLED
}

bool:isInMenu(id)
{
    for (new 
0g_mapVoteNum; ++a)
        if (
id == g_nextName[a])
            return 
true
    
return false
}

public 
voteNextmap()
{
    new 
winlimit get_cvar_num("mp_winlimit")
    new 
maxrounds get_cvar_num("mp_maxrounds")
    
    if (
winlimit)
    {
        new 
winlimit 2
        
        
if ((g_teamScore[0]) && (g_teamScore[1]))
        {
            
g_selected false
            
return
        }
    }
    else if (
maxrounds)
    {
        if ((
maxrounds 2) > (g_teamScore[0] + g_teamScore[1]))
        {
            
g_selected false
            
return
        }
    } else {
        new 
timeleft get_timeleft()
        
        if (
timeleft || timeleft 129)
        {
            
g_selected false
            
return
        }
    }

    if (
g_selected)
        return

    
g_selected true
    
    
new menu[512], amkeys = (1<<SELECTMAPS 1)

    new 
pos format(menu511g_coloredMenus "\y%L:\w^n^n" "%L:^n^n"LANG_SERVER"CHOOSE_NEXTM")
    new 
dmax = (g_mapNums SELECTMAPS) ? SELECTMAPS g_mapNums
    
    
for (g_mapVoteNum 0g_mapVoteNum dmax; ++g_mapVoteNum)
    {
        
random_num(0g_mapNums 1)
        
        while (
isInMenu(a))
            if (++
>= g_mapNums0
        
        g_nextName
[g_mapVoteNum] = a
        pos 
+= format(menu[pos], 511"%d. %a^n"g_mapVoteNum 1ArrayGetStringHandle(g_mapNamea));
        
mkeys |= (1<<g_mapVoteNum)
        
g_voteCount[g_mapVoteNum] = 0
    
}
    
    
menu[pos++] = '^n'
    
g_voteCount[SELECTMAPS] = 0
    g_voteCount
[SELECTMAPS 1] = 0
    
    
new mapname[32]
    
get_mapname(mapname31)

    if ((
winlimit maxrounds) == && (get_cvar_float("mp_timelimit") < get_cvar_float("amx_extendmap_max")))
    {
        
pos += format(menu[pos], 511"%d. %L^n"SELECTMAPS 1LANG_SERVER"EXTED_MAP"mapname)
        
mkeys |= (1<<SELECTMAPS)
    }

    
format(menu[pos], 511"%d. %L"SELECTMAPS+2LANG_SERVER"NONE")
    new 
MenuName[64]
    
    
format(MenuName63"%L""en""CHOOSE_NEXTM")
    
show_menu(0mkeysmenu15MenuName)
    
set_task(15.0"checkVotes")
    
client_print(0print_chat"%L"LANG_SERVER"TIME_CHOOSE")
    
client_cmd(0"spk Gman/Gman_Choose2")
    
log_amx("Vote: Voting for the nextmap started")
}
stock bool:ValidMap(mapname[])
{
    if ( 
is_map_valid(mapname) )
    {
        return 
true;
    }
    
// If the is_map_valid check failed, check the end of the string
    
new len strlen(mapname) - 4;
    
    
// The mapname was too short to possibly house the .bsp extension
    
if (len 0)
    {
        return 
false;
    }
    if ( 
equali(mapname[len], ".bsp") )
    {
        
// If the ending was .bsp, then cut it off.
        // the string is byref'ed, so this copies back to the loaded text.
        
mapname[len] = '^0';
        
        
// recheck
        
if ( is_map_valid(mapname) )
        {
            return 
true;
        }
    }
    
    return 
false;
}

loadSettings(filename[])
{
    if (!
file_exists(filename))
        return 
0

    
new szText[32]
    new 
currentMap[32]
    
    new 
buff[256];
    
    
get_mapname(currentMap31)

    new 
fp=fopen(filename,"r");
    
    while (!
feof(fp))
    {
        
buff[0]='^0';
        
        
fgets(fpbuffcharsof(buff));
        
        
parse(buffszTextcharsof(szText));
        
        
        if (
szText[0] != ';' &&
            
ValidMap(szText) &&
            !
equali(szTextg_lastMap) &&
            !
equali(szTextcurrentMap))
        {
            
ArrayPushString(g_mapNameszText);
            ++
g_mapNums;
        }
        
    }
    
    
fclose(fp);

    return 
g_mapNums
}

public 
team_score()
{
    new 
team[2]
    
    
read_data(1team1)
    
g_teamScore[(team[0]=='C') ? 1] = read_data(2)
}

public 
plugin_end()
{
    new 
current_map[32]

    
get_mapname(current_map31)
    
set_localinfo("lastMap"current_map)

I added the cvar "mapchooser_enable" and it defaults to 0 (off). The only downside to this is that the task will always be running (however negligible), where as in your crontab solution it will not be running at all which is nice .

In your crontab I would use the copy function instead, this means that plugins_day.ini and plugins_night.ini will always exist.


Code:
cp /.../cstrike/addons/amxmodx/configs/plugins_day.ini /.../cstrike/addons/amxmodx/configs/plugins.ini
cp /.../cstrike/addons/amxmodx/configs/plugins_night.ini /.../cstrike/addons/amxmodx/configs/plugins.ini
however, if you change your plugins.ini often you might lose something if you edit plugins.ini directly instead of only editing the plugins_*.ini files only, if you know what I mean.
__________________

Last edited by fysiks; 06-17-2009 at 23:28.
fysiks is offline
-ynk
Junior Member
Join Date: Jun 2009
Old 06-18-2009 , 02:05   Re: enable/disable plugin by cvar? Is it possible?
Reply With Quote #9

Yes, great ;) , but -

PHP Code:
/* AMX Mod X
*   NextMap Plugin
*
* by the AMX Mod X Development Team
*  originally developed by OLO
*
* This file is part of AMX Mod X.
*
*
*  This program is free software; you can redistribute it and/or modify it
*  under the terms of the GNU General Public License as published by the
*  Free Software Foundation; either version 2 of the License, or (at
*  your option) any later version.
*
*  This program is distributed in the hope that it will be useful, but
*  WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
*  General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software Foundation,
*  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*  In addition, as a special exception, the author gives permission to
*  link the code of this program with the Half-Life Game Engine ("HL
*  Engine") and Modified Game Libraries ("MODs") developed by Valve,
*  L.L.C ("Valve"). You must obey the GNU General Public License in all
*  respects for all of the code used other than the HL Engine and MODs
*  from Valve. If you modify this file, you may extend this exception
*  to your version of the file, but you are not obligated to do so. If
*  you do not wish to do so, delete this exception statement from your
*  version.
*/

#include <amxmodx>

// WARNING: If you comment this line make sure
// that in your mapcycle file maps don't repeat.
// However the same map in a row is still valid.
#define A = "shine"
#define OBEY_MAPCYCLE

new g_nextMap[32]
new 
g_mapCycle[32]
new 
g_mapCycle_night[32]
new 
g_pos

public plugin_init()
{
    
register_plugin("NextMap"AMXX_VERSION_STR"AMXX Dev Team")
    
register_dictionary("nextmap.txt")
    
register_event("30""changeMap""a")
    
register_clcmd("say nextmap""sayNextMap"0"- displays nextmap")
    
register_clcmd("say currentmap""sayCurrentMap"0"- display current map")
    
register_clcmd("say ff""sayFFStatus"0"- display friendly fire status")
    
register_cvar("amx_nextmap"""FCVAR_SERVER|FCVAR_EXTDLL|FCVAR_SPONLY)

    new 
szString[32], szString2[32], szString3[8]
    
    
get_localinfo("lastmapcycle"szString31)
    
parse(szStringszString231szString37)
    
g_pos str_to_num(szString3)
    
get_cvar_string("mapcyclefile"g_mapCycle31)
    
format(g_mapCycle_night31"mapcycle_night.txt")
    
    new 
thours[6]
    
get_time("%H"thours5)
    new 
hours str_to_num(thours)
    
    if(
hours >= && hours <= 10)
        
readMapCycle(g_mapCycle_nightg_nextMap31)
    else
        
readMapCycle(g_mapCycleg_nextMap31)
        
    
set_cvar_string("amx_nextmap"g_nextMap)
    
format(szString331"%s %d"g_mapCycleg_pos)    // save lastmapcycle settings
    
set_localinfo("lastmapcycle"szString3)
}

getNextMapName(szArg[], iMax)
{
    new 
len get_cvar_string("amx_nextmap"szArgiMax)
    
    if (
is_map_valid(szArg)) return len
    len 
copy(szArgiMaxg_nextMap)
    
set_cvar_string("amx_nextmap"g_nextMap)
    
    return 
len
}

public 
sayNextMap()
{
    new 
name[32]
    
    
getNextMapName(name31)
    
client_print(0print_chat"%L %s"LANG_PLAYER"NEXT_MAP"name)
}

public 
sayCurrentMap()
{
    new 
mapname[32]

    
get_mapname(mapname31)
    
client_print(0print_chat"%L: %s"LANG_PLAYER"PLAYED_MAP"mapname)
}

public 
sayFFStatus()
{
    
client_print(0print_chat"%L: %L"LANG_PLAYER"FRIEND_FIRE"LANG_PLAYERget_cvar_num("mp_friendlyfire") ? "ON" "OFF")
}

public 
delayedChange(param[])
{
    
set_cvar_float("mp_chattime"get_cvar_float("mp_chattime") - 2.0)
    
server_cmd("changelevel %s"param)
}

public 
changeMap()
{
    new 
string[32]
    new 
Float:chattime get_cvar_float("mp_chattime")
    
    
set_cvar_float("mp_chattime"chattime 2.0)        // make sure mp_chattime is long
    
new len getNextMapName(string31) + 1
    set_task
(chattime"delayedChange"0stringlen)    // change with 1.5 sec. delay
}

new 
g_warning[] = "WARNING: Couldn't find a valid map or the file doesn't exist (file ^"%s^")"

#if defined OBEY_MAPCYCLE
readMapCycle(szFileName[], szNext[], iNext)
{
    new 
b0iMaps 0
    
new szBuffer[32], szFirst[32]

    if (
file_exists(szFileName))
    {
        while (
read_file(szFileNamei++, szBuffer31b))
        {
            if (!
isalnum(szBuffer[0]) || !is_map_valid(szBuffer)) continue
            if (!
iMaps)
                
copy(szFirst31szBuffer)
            
            if (++
iMaps g_pos)
            {
                
copy(szNextiNextszBuffer)
                
g_pos iMaps
                
return
            }
        }
    }

    if (!
iMaps)
    {
        
log_amx(g_warningszFileName)
        
get_mapname(szFirst31)
    }

    
copy(szNextiNextszFirst)
    
g_pos 1
}

#else

readMapCycle(szFileName[], szNext[], iNext)
{
    new 
b0iMaps 0
    
new szBuffer[32], szFirst[32], szCurrent[32]
    
    
get_mapname(szCurrent31)
    
    new 
g_pos

    
if (file_exists(szFileName))
    {
        while (
read_file(szFileNamei++, szBuffer31b))
        {
            if (!
isalnum(szBuffer[0]) || !is_map_valid(szBuffer)) continue
            
            if (!
iMaps)
            {
                
iMaps 1
                copy
(szFirst31szBuffer)
            }
            
            if (
iMaps == 1)
            {
                if (
equali(szCurrentszBuffer))
                {
                    if (
a-- == 0)
                        
iMaps 2
                
}
            } else {
                if (
equali(szCurrentszBuffer))
                    ++
g_pos
                
else
                    
g_pos 0
                
                copy
(szNextiNextszBuffer)
                return
            }
        }
    }
    
    if (!
iMaps)
    {
        
log_amx(g_warningszFileName)
        
copy(szNextiNextszCurrent)
    }
    else
        
copy(szNextiNextszFirst)
    
    
g_pos 0
}
#endif 
I found modified nextmap plugin, this plugin change mapcycles.
0:00 change to mapcycle_night.txt and 10:00 change back to default mapcycle.txt.

PHP Code:
if(hours >= && hours <= 10)
        
readMapCycle(g_mapCycle_nightg_nextMap31)
    else
        
readMapCycle(g_mapCycleg_nextMap31
Can you add to this mapchooser_enable cvar ?
When comes 0:00 plugin takes mapcycle_night.txt and mapchooser_enable sets to 1 and olso when comes 10:00 mapchooser disables.

Last edited by -ynk; 06-18-2009 at 02:08.
-ynk is offline
DJEarthQuake
Veteran Member
Join Date: Jan 2014
Location: Astral planes
Old 12-04-2018 , 20:26   Re: enable/disable plugin by cvar? Is it possible?
Reply With Quote #10

amxx pause mapchooser
Paused plugin "mapchooser.amxx"
amxx unpause mapchooser
Unpaused plugin "mapchooser.amxx"

Back to the crontab method. Have cron run the script. Avoid putting the script in the cron although it is tolerant.
One can do a symbolic link to plugins.ini and just change it out to whatever and whenever or with copy command and the 2 source files.

Quote:
Originally Posted by fysiks View Post
The only downside to this is that the task will always be running (however negligible), where as in your crontab solution it will not be running at all which is nice .
As we can see here the author mentioned it is better to disable it entirely via crontab. I prefer to utilize files like plugins-cs.ini myself in the addons/amxmodx/configs/maps directory but we are not doing exactly the same thing.


@daily /path/./script1.sh <--- runs daily at midnight
33 10 * * * /path/./script2.sh <--- runs daily 1033.
05 13 * * * /path/./script3.sh <--- runs daily 1305.
__________________
DJEarthQuake 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 22:24.


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