AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Execute cfg via chat (https://forums.alliedmods.net/showthread.php?t=347222)

fjlep 04-12-2024 20:41

Execute cfg via chat
 
Some time ago I found a plugin that the function was to execute cfg using the say, for example to execute lo3.cfg I wrote in the chat lo3 and the configuration was loaded, but I don't remember where I saw it, I hope you can help me.

georgik57 04-17-2024 09:47

Re: Execute cfg via chat
 
you can do amx_rcon exec lo3.cfg

tedaimlocks 04-17-2024 10:08

Re: Execute cfg via chat
 
Quote:

Originally Posted by fjlep (Post 2820871)
Some time ago I found a plugin that the function was to execute cfg using the say, for example to execute lo3.cfg I wrote in the chat lo3 and the configuration was loaded, but I don't remember where I saw it, I hope you can help me.

this should work, i guess


HTML Code:

#include <amxmodx>

#define PLUGIN "CFG Via Chat"
#define VERSION "1.0"
#define AUTHOR "tedaimlocks"

#define FLAG ADMIN_CFG

public plugin_init() {
        register_plugin(PLUGIN, VERSION, AUTHOR);
        register_clcmd("say /lo3", "cfg")
        register_clcmd("say_team /lo3", "cfg")
}

public cfg() {
        if(!get_user_flags(id) & FLAG) {
            return PLUGIN_HANDLED;
        }
        server_cmd("exec lo3.cfg");
}


fjlep 04-20-2024 23:02

Re: Execute cfg via chat
 
Quote:

Originally Posted by tedaimlocks (Post 2821075)
this should work, i guess


HTML Code:

#include <amxmodx>

#define PLUGIN "CFG Via Chat"
#define VERSION "1.0"
#define AUTHOR "tedaimlocks"


public plugin_init() {
        register_plugin(PLUGIN, VERSION, AUTHOR);
        register_clcmd("say /lo3", "cfg")
        register_clcmd("say_team /lo3", "cfg")
}

public cfg() {
        server_cmd("exec lo3.cfg");
}


It works! How do I add more cfg's to the same plugin?

fjlep 04-20-2024 23:07

Re: Execute cfg via chat
 
Quote:

Originally Posted by georgik57 (Post 2821071)
you can do amx_rcon exec lo3.cfg

I want to avoid using the console, I like to use the "say .lo3" =D

Bugsy 04-20-2024 23:25

Re: Execute cfg via chat
 
Quote:

Originally Posted by fjlep (Post 2821307)
I want to avoid using the console, I like to use the "say .lo3" =D

Add your config files to the array, excluding the ".cfg" extension. Do you want to limit who can execute config files to admins only?

This will support saying /lo3 or .lo3
PHP Code:

#include <amxmodx>

new const Version[] = "0.1";

new const 
configs[][] = 
{
    
"lo3",
    
"lo4",
    
"lo5"
};

public 
plugin_init() 
{
    
register_plugin"Say Exec Config" Version "bugsy" );
    
    
register_clcmd"say" "SayHook" );
    
register_clcmd"say_team" "SayHook" ); 
}

public 
SayHook() 
{
    new 
szArg];
    
    
read_argvszArg charsmaxszArg ) );
    
    for ( new 
sizeofconfigs ) ; i++ )
    {
        if ( 
equalszArg] , configs] ) )
        {
            
server_cmd"exec %s.cfg" szArg] );
            break;
        }
    }



fjlep 04-21-2024 18:12

Re: Execute cfg via chat
 
Quote:

Originally Posted by Bugsy (Post 2821308)
Add your config files to the array, excluding the ".cfg" extension. Do you want to limit who can execute config files to admins only?

This will support saying /lo3 or .lo3
PHP Code:

#include <amxmodx>

new const Version[] = "0.1";

new const 
configs[][] = 
{
    
"lo3",
    
"lo4",
    
"lo5"
};

public 
plugin_init() 
{
    
register_plugin"Say Exec Config" Version "bugsy" );
    
    
register_clcmd"say" "SayHook" );
    
register_clcmd"say_team" "SayHook" ); 
}

public 
SayHook() 
{
    new 
szArg];
    
    
read_argvszArg charsmaxszArg ) );
    
    for ( new 
sizeofconfigs ) ; i++ )
    {
        if ( 
equalszArg] , configs] ) )
        {
            
server_cmd"exec %s.cfg" szArg );
            break;
        }
    }



When I type .lo3 in chat in console I get this "couldn't exec .lo3.cfg" I have the files in /cstrike/, if I type /lo3 I get this exec /lo3.cfg: invalid path and I would like admin's only to be able to use this option.

fysiks 04-21-2024 19:46

Re: Execute cfg via chat
 
That's because it's currently passing the whole chat argument through to the command line. You need to remove the first character in the same way that it was done for the comparison. I.e. add the indexing of the szArg array in the server_cmd() function like this:

Code:

server_cmd( "exec %s.cfg" , szArg[1] );

Bugsy 04-21-2024 19:51

Re: Execute cfg via chat
 
Ah, my bad.

As fysiks said, you can do:
server_cmd( "exec %s.cfg" , szArg[ 1 ] );
or
server_cmd( "exec %s.cfg" , configs[ i ] );
both will do the exact same thing.

fjlep 04-23-2024 21:02

Re: Execute cfg via chat
 
Bugsy and fysiks Thanks for your help!


All times are GMT -4. The time now is 00:07.

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