Author Topic: Setting Engine Cvars?  (Read 3345 times)

0 Members and 2 Guests are viewing this topic.

Offline PAL-18

  • Full Member
  • ***
  • Posts: 142
  • Karma: 1
Setting Engine Cvars?
« 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?
« Last Edit: October 31, 2014, 04:05:20 PM by PAL-18 »

Offline Avoid

  • Full Member
  • ***
  • Posts: 142
  • Karma: 42
Re: Setting Engine Cvars?
« Reply #1 on: November 01, 2014, 05:12:52 AM »
Hello there,
have you actually created the convars using 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

Offline PAL-18

  • Full Member
  • ***
  • Posts: 142
  • Karma: 1
Re: Setting Engine Cvars?
« Reply #2 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.
« Last Edit: November 01, 2014, 03:11:36 PM by PAL-18 »

Offline Avoid

  • Full Member
  • ***
  • Posts: 142
  • Karma: 42
Re: Setting Engine Cvars?
« Reply #3 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)

Offline PAL-18

  • Full Member
  • ***
  • Posts: 142
  • Karma: 1
Re: Setting Engine Cvars?
« Reply #4 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.

Offline Avoid

  • Full Member
  • ***
  • Posts: 142
  • Karma: 42
Re: Setting Engine Cvars?
« Reply #5 on: November 02, 2014, 02:59:07 AM »
As I've written in my post earlier, simply put this into your Initialize hook.

You can either overwrite the hook or simply add to it. :)

Offline PAL-18

  • Full Member
  • ***
  • Posts: 142
  • Karma: 1
Re: Setting Engine Cvars?
« Reply #6 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)
« Last Edit: November 04, 2014, 03:00:34 AM by PAL-18 »

Offline PAL-18

  • Full Member
  • ***
  • Posts: 142
  • Karma: 1
Re: Setting Engine Cvars?
« Reply #7 on: November 09, 2014, 02:28:55 PM »
Sooo ... any idea why it doesnt work?

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Setting Engine Cvars?
« Reply #8 on: November 09, 2014, 02:32:51 PM »
Does it give an error?

Offline PAL-18

  • Full Member
  • ***
  • Posts: 142
  • Karma: 1
Re: Setting Engine Cvars?
« Reply #9 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.

Offline PAL-18

  • Full Member
  • ***
  • Posts: 142
  • Karma: 1
Re: Setting Engine Cvars?
« Reply #10 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