Raised This Month: $32 Target: $400
 8% 

Solved Cfg Execution by Cvar


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
WhiteFang1319
Senior Member
Join Date: Jan 2017
Old 12-18-2017 , 06:56   Cfg Execution by Cvar
Reply With Quote #1

Hello.
I needed to do cfg executions which can be changeable by cvar. So i tried to make some code but it didnt work.

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "Cfg Test"
#define VERSION "1.0"
#define AUTHOR "WhiteFang"

new cfg

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
cfg register_cvar("amx_cfgfile""pub.cfg");
    
register_clcmd("say /cfg""test_cfg");
    
}
public 
test_cfg()
{
    
server_cmd("exec %s"cfg)

It compiles without any error but the cfg isn't executed. I tried using amx_cfg instead of exec but it didnt work.
Also I get this output in the console when the above code is used:
Code:
Momo : /cfg
exec <filename> : execute a script file

Last edited by WhiteFang1319; 12-18-2017 at 08:31. Reason: Solved
WhiteFang1319 is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 12-18-2017 , 08:08   Re: Cfg Execution by Cvar
Reply With Quote #2

You must read the value of the cvar like string: get_pcvar_string()
__________________
My English is A0
E1_531G is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 12-18-2017 , 08:15   Re: Cfg Execution by Cvar
Reply With Quote #3

Code:
new fCvar, fDirectory[32] fCvar = register_cvar("the_cvar", "configurationfile") get_pcvar_string(fCvar, fDirectory, charsmax(fDirectory) server_exec("exec %s.cfg", fDirectory)
__________________
Relaxing is offline
WhiteFang1319
Senior Member
Join Date: Jan 2017
Old 12-18-2017 , 08:31   Re: Cfg Execution by Cvar
Reply With Quote #4

Quote:
Originally Posted by E1_531G View Post
You must read the value of the cvar like string: get_pcvar_string()
Oh. I tried get_pcvar_num() but It was the wrong one I guess..

Quote:
Originally Posted by Relaxing View Post
Code:
new fCvar, fDirectory[32] fCvar = register_cvar("the_cvar", "configurationfile") get_pcvar_string(fCvar, fDirectory, charsmax(fDirectory) server_exec("exec %s.cfg", fDirectory)
Thank you. It works
WhiteFang1319 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-18-2017 , 13:01   Re: Cfg Execution by Cvar
Reply With Quote #5

Quote:
Originally Posted by WhiteFang1319 View Post
Oh. I tried get_pcvar_num() but It was the wrong one I guess..
That's because "num" means number. Your cvar does not contain a number, it contains a string also, you couldn't use a number in any case.
__________________
fysiks is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 12-18-2017 , 14:34   Re: Cfg Execution by Cvar
Reply With Quote #6

Quote:
Originally Posted by Relaxing View Post
Code:
new fCvar, fDirectory[32] fCvar = register_cvar("the_cvar", "configurationfile") get_pcvar_string(fCvar, fDirectory, charsmax(fDirectory) server_exec("exec %s.cfg", fDirectory)
I see an unclosed bracket up there.
__________________
Relaxing is offline
WhiteFang1319
Senior Member
Join Date: Jan 2017
Old 12-19-2017 , 07:39   Re: Cfg Execution by Cvar
Reply With Quote #7

Quote:
Originally Posted by fysiks View Post
That's because "num" means number. Your cvar does not contain a number, it contains a string also, you couldn't use a number in any case.
Oh. Thanks.

Quote:
Originally Posted by Relaxing View Post
I see an unclosed bracket up there.
Yeah I noticed. Also it should be server_cmd() instead of server_exec() lol
WhiteFang1319 is offline
Reply


Thread Tools
Display Modes

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 08:46.


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