Raised This Month: $ Target: $400
 0% 

Trying to add map support to my plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
valio_skull
Senior Member
Join Date: Jan 2013
Location: at home
Old 12-04-2015 , 13:33   Trying to add map support to my plugin
Reply With Quote #1

Can someone tell me what is wrong with this ?
I'm just trying to make it work by map cfg file...
PHP Code:
#include <sourcemod>
#include <sdktools>

#define PLUGIN_VERSION "1.1"

new Handle:g_CVarEnabled;

public 
Plugin myinfo =
{
    
name "Round Exec by Mado",
    
author "Mado",
    
description "none",
    
version PLUGIN_VERSION,
    
url "http://www.bluegames.ro/forum/"
}

public 
OnPluginStart()
{
    
g_CVarEnabled CreateConVar("sm_roundexec_enable""1""<1/0> Set to 1 to enable plugin.");
    
HookEvent("round_start"RoundStartEventHookMode_Post);
    
HookEvent("round_end"RoundEndEventHookMode_Post);
}

public 
Action:RoundStart(Handle:event, const String:name[], bool:dontBroadcast) {
    
decl String:file[PLATFORM_MAX_PATH], String:curmap[PLATFORM_MAX_PATH];
    
GetCurrentMap(curmapsizeof(curmap));
    {
        if (
GetConVarInt(g_CVarEnabled)){
        
ServerCommand("exec round_exec/%s_start.cfg"curmap);
        }
    }
    if (!
FileExists(file))
    {
        if (
GetConVarInt(g_CVarEnabled)){
            
ServerCommand("exec round_exec/round_start.cfg");
        }
    }
}

public 
Action:RoundEnd(Handle:event, const String:name[], bool:dontBroadcast) {
    
decl String:file[PLATFORM_MAX_PATH], String:curmap[PLATFORM_MAX_PATH];
    
GetCurrentMap(curmapsizeof(curmap));
    {
        if (
GetConVarInt(g_CVarEnabled)){
        
ServerCommand("exec round_exec/%s_end.cfg"curmap);
        }
    }
    if (!
FileExists(file))
    {
        if (
GetConVarInt(g_CVarEnabled)){
            
ServerCommand("exec round_exec/round_end.cfg");
        }
    }

__________________
valio_skull is offline
valio_skull
Senior Member
Join Date: Jan 2013
Location: at home
Old 12-04-2015 , 13:41   Re: Trying to add map support to my plugin
Reply With Quote #2

I've checked, when ti has the %s_start.cfg and %s_end.cfg files it exec the round_start.cfg and round_end.cfg . I want it to exec only the %s_start.cfg and %s_end.cfg
__________________
valio_skull is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-04-2015 , 14:55   Re: Trying to add map support to my plugin
Reply With Quote #3

This block looks funny:
Code:
    { 
        if (GetConVarInt(g_CVarEnabled)){ 
        ServerCommand("exec round_exec/%s_start.cfg", curmap); 
        } 
    } 
    if (!FileExists(file)) 
    { 
        if (GetConVarInt(g_CVarEnabled)){ 
            ServerCommand("exec round_exec/round_start.cfg"); 
        } 
    }
It should probably be
Code:
    Format(file, sizeof(file). "round_exec/%s_start.cfg", curmap);

    if (GetConVarBool(g_CVarEnabled))
    { 
        if (FileExists(file)) 
        { 
            ServerCommand("exec %s", file);
        } 
        else
        { 
            ServerCommand("exec round_exec/round_start.cfg"); 
        } 
    }
The round end one has the same problem.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 12-04-2015 at 15:19. Reason: Moved the if(GetConVarBool out of the loop, fixed file not being set
Powerlord is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-04-2015 , 15:17   Re: Trying to add map support to my plugin
Reply With Quote #4

Err... I also just noticed that you never set file to a value. So FileExists against it is always going to fail.

Edit: I've edited my previous post to account for that, although it has no security precautions for said file (i.e. checking for . or ..)
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 12-04-2015 at 15:40.
Powerlord is offline
valio_skull
Senior Member
Join Date: Jan 2013
Location: at home
Old 12-04-2015 , 16:20   Re: Trying to add map support to my plugin
Reply With Quote #5

Quote:
Originally Posted by Powerlord View Post
Err... I also just noticed that you never set file to a value. So FileExists against it is always going to fail.

Edit: I've edited my previous post to account for that, although it has no security precautions for said file (i.e. checking for . or ..)
Same thing. It execs both of the cfg files. I want just one of them.
If I'm on de_dust2 and and de_dust2_start.cfg it's present I want just it to be executed
and if isn't present, to execute round_start.cfg
Same with de_dust2_end and round_end cfg.
__________________
valio_skull is offline
jess
Member
Join Date: Aug 2015
Location: mb
Old 12-05-2015 , 06:21   Re: Trying to add map support to my plugin
Reply With Quote #6

You need to BuildPath using Path_SM for proper file location if you're going to be using !FileExists , here this is what I do in my rpg plugin:

Code:
BuildPath(Path_SM, cfgPath, sizeof(cfgPath), "configs/");
    Format(cfgPathEx, sizeof(cfgPathEx), "%s%s", cfgPath, CONFIG_MAIN);
    ClearArray(Handle:a_MainMenu);
    if (!ParseConfigFile(cfgPathEx)) SetFailState("%s Improperly formatted.", cfgPathEx);
    Format(cfgPathEx, sizeof(cfgPathEx), "%s%s", cfgPath, CONFIG_POINTS);
    ClearArray(Handle:a_Points);
It's not the exact same thing you're doing, but similarly, instead of using ParseConfigFile, use if (FileExists(cfgPathEx)) { //do }
jess is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-05-2015 , 23:16   Re: Trying to add map support to my plugin
Reply With Quote #7

Quote:
Originally Posted by jess View Post
You need to BuildPath using Path_SM for proper file location if you're going to be using !FileExists , here this is what I do in my rpg plugin:

Code:
BuildPath(Path_SM, cfgPath, sizeof(cfgPath), "configs/");
    Format(cfgPathEx, sizeof(cfgPathEx), "%s%s", cfgPath, CONFIG_MAIN);
    ClearArray(Handle:a_MainMenu);
    if (!ParseConfigFile(cfgPathEx)) SetFailState("%s Improperly formatted.", cfgPathEx);
    Format(cfgPathEx, sizeof(cfgPathEx), "%s%s", cfgPath, CONFIG_POINTS);
    ClearArray(Handle:a_Points);
It's not the exact same thing you're doing, but similarly, instead of using ParseConfigFile, use if (FileExists(cfgPathEx)) { //do }
If you want a file in one of SourceMod's folders you need BuildPath. However, the game uses its base directory for relative paths.

What's more, exec looks in cfg/ by default, which is why on a TF2 server, I can1 exec replay.cfg which is really the file tf/cfg/replay.cfg

1Note that I said can, not should. If you want to have replay enabled on a server, the -replay command line option is the best way to do it as it auto-adjusts the slot count.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 12-05-2015 at 23:20.
Powerlord 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 03:38.


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