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

Solved [L4D & L4D2] Using a cvar to filter maps or gamemodes


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 12-03-2017 , 06:32   [L4D & L4D2] Using a cvar to filter maps or gamemodes
Reply With Quote #1

Hello, I'd like to know if it's possible to filter maps or gamemodes by using cvars.

Let's say I want a plugin to only work on l4d2 finale maps, I'd have something like this as a cvar:

l4d2_filter_maps "c1m4_atrium,c2m5_concert"

If this is possible, please show me exactly how to implement this. I'm asking if this is possible because I'd like to implement an easier and shorter way to disable the different systems in my Anti-Speedrunner System on certain maps.

Thanks!
__________________

Last edited by Psyk0tik; 12-04-2017 at 03:10. Reason: Marked as [Solved]
Psyk0tik is offline
Lux
Veteran Member
Join Date: Jan 2015
Location: Cat
Old 12-03-2017 , 06:43   Re: [L4D & L4D2] Using a cvar to filter maps or gamemodes
Reply With Quote #2

Maybe you looking for this?

https://sm.alliedmods.net/new-api/string/ExplodeString
__________________
Connect
My Plugins: KlickME
[My GitHub]

Commission me for L4D
Lux is offline
midnight9
Senior Member
Join Date: Nov 2012
Old 12-03-2017 , 07:22   Re: [L4D & L4D2] Using a cvar to filter maps or gamemodes
Reply With Quote #3

You could use boolean, example:
Code:
public OnMapStart() {
	decl String:Map[64];
	GetCurrentMap(Map, sizeof(Map));
	if(StrEqual(Map, "c2m5_concert"))
	{
		EnablePlugin = true;
	}
midnight9 is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 12-03-2017 , 07:57   Re: [L4D & L4D2] Using a cvar to filter maps or gamemodes
Reply With Quote #4

Quote:
Originally Posted by midnight9 View Post
You could use boolean, example:
Code:
public OnMapStart() {
	decl String:Map[64];
	GetCurrentMap(Map, sizeof(Map));
	if(StrEqual(Map, "c2m5_concert"))
	{
		EnablePlugin = true;
	}
That's actually the current method I'm using. I made this thread in hopes that there can be a shorter way.
__________________
Psyk0tik is offline
Timocop
AlliedModders Donor
Join Date: Mar 2013
Location: Germany
Old 12-03-2017 , 08:23   Re: [L4D & L4D2] Using a cvar to filter maps or gamemodes
Reply With Quote #5

Only finale maps?

PHP Code:
bool IsFinaleMap()
{
    return (
FindEntityByClassname(-1"trigger_finale") != -1);

otherwise use ExplodeString() and split the cvar string (with the map names) into a string array.
PHP Code:
#define MAX_MAPS 64

//Get the current map
char sCurrentMap[128];
GetCurrentMap(sCurrentMapsizeof(sCurrentMap));

//Split cvar string into string array
char[] sCvarStr "ds_map1;ds_map2;ds_map3";

char sMaps[MAX_MAPS][128];
ExplodeString(sCvarStr";"sMapssizeof(sMaps), sizeof(sMaps[]));

//Check for map
bool bEnabled false;

for(
int i 0sizeof(sMaps); i++) {
    if(
StrEqual(sCurrentMapsMaps[i], false)) {
        
bEnabled true;
        break;
    }
}

//... 
Timocop is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 12-03-2017 , 08:39   Re: [L4D & L4D2] Using a cvar to filter maps or gamemodes
Reply With Quote #6

Quote:
Originally Posted by Timocop View Post
Only finale maps?

PHP Code:
bool IsFinaleMap()
{
    return (
FindEntityByClassname(-1"trigger_finale") != -1);

otherwise use ExplodeString() and split the cvar string (with the map names) into a string array.
PHP Code:
#define MAX_MAPS 64

//Get the current map
char sCurrentMap[128];
GetCurrentMap(sCurrentMapsizeof(sCurrentMap));

//Split cvar string into string array
char[] sCvarStr "ds_map1;ds_map2;ds_map3";

char sMaps[MAX_MAPS][128];
ExplodeString(sCvarStr";"sMapssizeof(sMaps), sizeof(sMaps[]));

//Check for map
bool bEnabled false;

for(
int i 0sizeof(sMaps); i++) {
    if(
StrEqual(sCurrentMapsMaps[i], false)) {
        
bEnabled true;
        break;
    }
}

//... 
How can I incorporate a public cvar into this? I'd like users to have the freedom to choose which maps they want certain systems to be disabled in. This would allow for multiple combinations as my Anti-Speedrunner System plugin consists of 5 systems in 1. The main reason for this cvar is to allow support for custom campaigns. If I set the maps within the plugin, there will be way more maps that won't be supported.
__________________
Psyk0tik is offline
Timocop
AlliedModders Donor
Join Date: Mar 2013
Location: Germany
Old 12-03-2017 , 10:04   Re: [L4D & L4D2] Using a cvar to filter maps or gamemodes
Reply With Quote #7

https://sm.alliedmods.net/new-api/co...etConVarString

Edit:
You want to save settings per map right? Why not use config files like for example stripper does.
I dont think cvars are the best way to store configs. Use KeyValues and parse them from files.
https://sm.alliedmods.net/new-api/keyvalues

ds_map1.cfg
Code:
"Systems"
{
    "AntiRush"      "1"
    "AntiSpam"     "0"
}

Last edited by Timocop; 12-03-2017 at 11:56.
Timocop is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 12-04-2017 , 03:10   Re: [L4D & L4D2] Using a cvar to filter maps or gamemodes
Reply With Quote #8

Thanks to everyone on this thread for your help and NgBUCKWANGS (author of ABM) for the following code.

I have decided to use this:
PHP Code:
char MapName[128]; //Use 128 in case of really long map names

public void OnPluginStart()
{
    
HookEvent("round_end"RoundEnd);
    
HookEvent("finale_win"FinaleWin);
}

public 
void OnConfigsExecuted()
{
    
GetCurrentMap(MapNamesizeof(MapName));
    
Format(MapNamesizeof(MapName), "cfg/sourcemod/l4d_anti-speedrunner/%s.cfg"MapName); //Specifies the path that the plugin will check for custom map configs
    
if(FileExists(MapNametrue))
    {
        
strcopy(MapNamesizeof(MapName), MapName[4]);
        
ServerCommand("exec \"%s\""MapName); //Executes map config if found
    
}

    else if(
FileExists("cfg/sourcemod/l4d_anti-speedrunner.cfg"true))
    {
        
ServerCommand("exec \"sourcemod/l4d_anti-speedrunner.cfg\""); //Executes the plugin's config if map config isn't found
    
}
}

public 
Action RoundEnd(Handle event, const char[] namebool dontBroadcast)
{
    
ServerCommand("exec \"sourcemod/l4d_anti-speedrunner.cfg\""); //Executes the plugin's config so cvars don't break on the next map
}

public 
Action FinaleWin(Handle event, const char[] namebool dontBroadcast)
{
    
ServerCommand("exec \"sourcemod/l4d_anti-speedrunner.cfg\""); //Executes the plugin's config so cvars don't break on the next campaign

This allows users to just create mapname.cfg files in cfg/sourcemod/l4d_anti-speedrunner folder. In those mapname.cfg files, users can just specify the values they want for certain cvars.

Example:
cfg/sourcemod/l4d_anti-speedrunner/c1m4_atrium.cfg
Code:
l4d_ass_incap_required "7"
l4d_ass_punish_enable "0"
l4d_ass_punish_incap "1"
l4d_ass_teleport_enable "0"
l4d_ass_teleport_incap "1"
__________________

Last edited by Psyk0tik; 12-08-2017 at 08:44. Reason: Added explanation for the code
Psyk0tik 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 06:01.


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