Ulysses

General => Developers Corner => Topic started by: PAL-18 on October 31, 2014, 01:24:20 PM

Title: Setting Engine Cvars?
Post by: PAL-18 on October 31, 2014, 01:24:20 PM
I have a bunch of engine cvars im trying to set to custom valid values (sk_barnacle_health, etc.) and i'm unable to get them to set.  In server.cfg it isin't applying and they even fail when added to init.lua in the gamemode.

I've tried the following code:
RunConsoleCommand("sk_barnacle_health", "1000")


Any idea how i can get it to apply?
Title: Re: Setting Engine Cvars?
Post by: Avoid on November 01, 2014, 05:12:52 AM
Hello there,
have you actually created the convars using CreateConVar (http://wiki.garrysmod.com/page/Global/CreateConVar)?

You can also define convars in your gamemode.txt:

Code: [Select]
"settings"
{
1
{
"name" "sk_maxfrags"
"text" "Max Frags"
"help" "The maxiumum number of frags before a map change"
"type" "Numeric"
"default" "20"
}


2
{
"name" "sk_grenades"
"text" "Allow Grenades"
"help" "If enabled ) then grenades are enabled"
"type" "CheckBox"
"default" "1"
}

}

Avoid
Title: Re: Setting Engine Cvars?
Post by: PAL-18 on November 01, 2014, 03:04:52 PM
They aren't custom cvars though.  They're cvars common to the SRCDS engine (they work in Gmod too).

I just tried that and it didnt work either.
Title: Re: Setting Engine Cvars?
Post by: Avoid on November 01, 2014, 05:38:30 PM
Ah, I see.
Sorry I didn't know such a convar existed! :')

Use a timer when setting the convar in the Initialize hook and it worked fine on my end:
Code: [Select]
timer.Simple(0.1, function()
RunConsoleCommand("sk_barnacle_health", "500")
end)
Title: Re: Setting Engine Cvars?
Post by: PAL-18 on November 02, 2014, 12:53:49 AM
Do you have the full code you used to get it to work?  I tried adding that timer to several places and i couldnt get it working.
Title: Re: Setting Engine Cvars?
Post by: Avoid on November 02, 2014, 02:59:07 AM
As I've written in my post earlier, simply put this into your Initialize (http://wiki.garrysmod.com/page/GM/Initialize) hook.

You can either overwrite the hook or simply add to it. :)
Title: Re: Setting Engine Cvars?
Post by: PAL-18 on November 04, 2014, 02:58:56 AM
Oh.

I didn't notice; but i did add it to my GM:Initialize hook.  It didn't work.

Here's part of what it looks like:

Code: [Select]
function GM:Initialize()
   MsgN("Trouble In Terrorist Town gamemode initializing...")
   ShowVersion()

   -- Force friendly fire to be enabled. If it is off, we do not get lag compensation.
   RunConsoleCommand("mp_friendlyfire", "1")
   
   -- NPC Cvars
   timer.Simple(0.1, function()
RunConsoleCommand("sk_barnacle_health", "1000")
RunConsoleCommand("sk_antlionguard_health", "300")
RunConsoleCommand("sk_antlionguard_dmg_charge", "7")
RunConsoleCommand("sk_antlionguard_dmg_shove", "2")
RunConsoleCommand("sk_antlion_health", "150")
RunConsoleCommand("sk_antlion_jump_damage", "5")
RunConsoleCommand("sk_antlion_swipe_damage", "1")
end)
Title: Re: Setting Engine Cvars?
Post by: PAL-18 on November 09, 2014, 02:28:55 PM
Sooo ... any idea why it doesnt work?
Title: Re: Setting Engine Cvars?
Post by: Zmaster on November 09, 2014, 02:32:51 PM
Does it give an error?
Title: Re: Setting Engine Cvars?
Post by: PAL-18 on November 10, 2014, 03:27:26 AM
Nope, no errors.  It just doesn't seem to accept the cvar.

Oddly if i do the cvar through rcon remotely or ulx rcon it runs fine.
Title: Re: Setting Engine Cvars?
Post by: PAL-18 on November 10, 2014, 09:36:02 PM
I managed to get it working myself by moving the timer from GM:Initialize function to BeginRound function.

Thanks for all the help :D