Raised This Month: $ Target: $400
 0% 

Solved get_cvar_string( returns empty string for amx_* cvars


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
damage220
Member
Join Date: Jul 2022
Location: Ukraine
Old 08-17-2023 , 20:14   get_cvar_string( returns empty string for amx_* cvars
Reply With Quote #1

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.

Last edited by damage220; 08-18-2023 at 12:43. Reason: Solved
damage220 is online now
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-17-2023 , 23:21   Re: get_cvar_string( returns empty string for amx_* cvars
Reply With Quote #2

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?
__________________
fysiks is offline
damage220
Member
Join Date: Jul 2022
Location: Ukraine
Old 08-18-2023 , 12:42   Re: get_cvar_string( returns empty string for amx_* cvars
Reply With Quote #3

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.
damage220 is online now
bigdaddy424
Senior Member
Join Date: Oct 2021
Location: Jupiter
Old 08-18-2023 , 18:14   Re: get_cvar_string( returns empty string for amx_* cvars
Reply With Quote #4

heres a quick way https://www.amxmodx.org/api/sqlx/SQL_MakeStdTuple
__________________
bigdaddy424 is offline
damage220
Member
Join Date: Jul 2022
Location: Ukraine
Old 08-18-2023 , 20:47   Re: get_cvar_string( returns empty string for amx_* cvars
Reply With Quote #5

Quote:
Originally Posted by bigdaddy424 View Post
It works this way only if you plug admin.amxx into the system, whereas I do not.
damage220 is online now
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-18-2023 , 22:29   Re: get_cvar_string( returns empty string for amx_* cvars
Reply With Quote #6

Quote:
Originally Posted by damage220 View Post
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.
__________________
fysiks is offline
Kowalsky
Senior Member
Join Date: Mar 2015
Location: Poland
Old 08-19-2023 , 05:28   Re: get_cvar_string( returns empty string for amx_* cvars
Reply With Quote #7

Quote:
Originally Posted by fysiks View Post
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
__________________
I ONLY LOVE STEAM, NON-STEAM IS VERY BAD FOR YOUR HEALTH!
Kowalsky is offline
damage220
Member
Join Date: Jul 2022
Location: Ukraine
Old 08-19-2023 , 11:42   Re: get_cvar_string( returns empty string for amx_* cvars
Reply With Quote #8

Quote:
Originally Posted by Kowalsky View Post
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 is online now
damage220
Member
Join Date: Jul 2022
Location: Ukraine
Old 08-19-2023 , 11:45   Re: get_cvar_string( returns empty string for amx_* cvars
Reply With Quote #9

Quote:
Originally Posted by fysiks View Post
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.
damage220 is online now
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 00:33.


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