PDA

View Full Version : Get cvar's string in plugin_precache()


hleV
04-22-2008, 05:09
Let's say I add a cvar:
register_cvar("jm_custom", "sound/misc/file.mp3") // Set the way to the .mp3 file by cvar
And then I want to precache this file.
public plugin_precache()
{
static custom[128]
get_cvar_string("jm_custom", custom, 127)

precache_sound("%s", custom) // Get the cvar's "jm_custom" string and put it into precache_sound
}
But it doesn't work. I can't use this in plugin_precache(). It failes to compile and shows this:
number of arguments does not match destinition
So is it another way to get cvar's string in plugin_precache?

jim_yang
04-22-2008, 05:39
precache_sound(custom)

hleV
04-22-2008, 06:35
Compiled fine but when I start a Dedicated Server it gets an error:
Host_Error: PF_precache_sound_I: Bad string "

Drak
04-22-2008, 06:38
Compiled fine but when I start a Dedicated Server it gets an error:
Host_Error: PF_precache_sound_I: Bad string "
Where are you adding the CVAR? In the same plugin?
plugin_precache() is called BEFORE plugin_init(). If you registered it in 'plugin_init()' then when you're getting the string, the cvar isn't even created yet.

hleV
04-22-2008, 07:32
#include <amxmodx>
#include <amxmisc>

public plugin_init()
{
register_cvar("jm_custom", "sound/misc/file.mp3")
}

public plugin_precache()
{
static custom[128]
get_cvar_num("jm_custom", custom, 127)

precache_sound(custom)
}
How can I make so the plugin_precache() would be called after creating a cvar in plugin_init()?

Exolent[jNr]
04-22-2008, 07:32
Just register the cvar in the plugin_precache().

YamiKaitou
04-22-2008, 08:36
How can I make so the plugin_precache() would be called after creating a cvar in plugin_init()?

No. You will have to do what X-olent said

hleV
04-22-2008, 09:43
Thanks for the help.