AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved get_cvar_string( returns empty string for amx_* cvars (https://forums.alliedmods.net/showthread.php?t=343650)

damage220 08-17-2023 20:14

get_cvar_string( returns empty string for amx_* cvars
 
I used to make custom db tuple using hardcoded credentials. I have moved all the data to configs/sql.cfg but when I try to create tuple using SQL_MakeStdTuple it gives me error saying it cannot connect to mysql socket. I found out that it is due to get_cvar_string returns empty string on any amx_* cvars including amx_sql_* ones. I tried to obtain these data in plugin_precache and thought they are empty because of wrong timing (i.e. config files are loaded after this native) but when I moved the code to plugin_init the issue is still persist. Could someone please explain why is that and what am I doing wrong?

I do not really care which of the functions I have to use: SQL_MakeStdTuple or SQL_MakeDbTuple, get_[p]cvar_string or anything else I simply do not want to write my own parser for the config file.

fysiks 08-17-2023 23:21

Re: get_cvar_string( returns empty string for amx_* cvars
 
Technically, get_cvar_string() doesn't return anything (strings are populated by reference) but I can't tell if that's what you're doing because you didn't provide any code to look at . . .

Have you verified that the cvar has the value in it at all? It looks like AMX Mod X's default admin plugin executes this file in plugin_init() so you shouldn't expect it before then. In fact, you should probably not do anything with your custom code until plugin_cfg() (or the newer version of it). If you're not running the default AMX Mod X admin plugin, are you sure it's getting executed at all?

damage220 08-18-2023 12:42

Re: get_cvar_string( returns empty string for amx_* cvars
 
I should have provided the code to you, my bad.

PHP Code:

get_cvar_string("amx_sql_host"hostcharsmax(host));
get_cvar_string("amx_sql_user"usercharsmax(user));
get_cvar_string("amx_sql_pass"passcharsmax(pass));
get_cvar_string("amx_sql_db"dbcharsmax(db));
server_print("host: %s^nuser: %s^npass: %s^ndb: %s"hostuserpassdb); 

It simply prints the content of these variables before I try to create a connection tuple.
From your comment I realized that it is the admin plugin that handles all the routine. And the reason why I get empty string is that I do not use this plugin) I thought these variables are read by amxmodx module itself or any other module, not plugins. I have checked admin.sma code, it first calls register_cvar to register custom variables, then it executes server command
PHP Code:

exec "path_to_config.cfg" 

to get real values. Thank you, it now works.

bigdaddy424 08-18-2023 18:14

Re: get_cvar_string( returns empty string for amx_* cvars
 
heres a quick way https://www.amxmodx.org/api/sqlx/SQL_MakeStdTuple

damage220 08-18-2023 20:47

Re: get_cvar_string( returns empty string for amx_* cvars
 
Quote:

Originally Posted by bigdaddy424 (Post 2808830)

It works this way only if you plug admin.amxx into the system, whereas I do not.

fysiks 08-18-2023 22:29

Re: get_cvar_string( returns empty string for amx_* cvars
 
Quote:

Originally Posted by damage220 (Post 2808834)
It works this way only if you plug admin.amxx into the system, whereas I do not.

It's effectively just a macro so you can still use it, you just need to register those cvars and execute the .cfg file yourself before you can use it.

This makes me think that it wasn't a good idea to include it as part of the AMX Mod X include files and should be relegated to a code snippet/example.

Kowalsky 08-19-2023 05:28

Re: get_cvar_string( returns empty string for amx_* cvars
 
Quote:

Originally Posted by fysiks (Post 2808843)
It's effectively just a macro so you can still use it, you just need to register those cvars and execute the .cfg file yourself before you can use it.

This makes me think that it wasn't a good idea to include it as part of the AMX Mod X include files and should be relegated to a code snippet/example.

Why didnt you ask if he is running a steam server?

Post us your version / meta list

damage220 08-19-2023 11:42

Re: get_cvar_string( returns empty string for amx_* cvars
 
Quote:

Originally Posted by Kowalsky (Post 2808859)
Why didnt you ask if he is running a steam server?

Post us your version / meta list

I run steam version. Meta list will list none of the standard plugins shipped with amxmodx, because I do not use them. Anyway issue is gone, and the thread is marked as Solved. No further help is needed, thanks.

damage220 08-19-2023 11:45

Re: get_cvar_string( returns empty string for amx_* cvars
 
Quote:

Originally Posted by fysiks (Post 2808843)
It's effectively just a macro so you can still use it, you just need to register those cvars and execute the .cfg file yourself before you can use it.

This makes me think that it wasn't a good idea to include it as part of the AMX Mod X include files and should be relegated to a code snippet/example.

True. I would also add that after server_cmd you need server_exec as well if you create connection tuple right after. Otherwise, server_cmd will add your command to the queue which will be executed on next frame.


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

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