cvar question

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
User avatar
ViPER
General
Posts: 1058
Joined: Fri Jan 14, 2005 5:48 pm
Location: California
Contact:

cvar question

Post by ViPER »

I use this code in my map rotation to call up different mods of the same map and it works when i use console to set dm2vers.

Instead of using console to select the version however, i would like it to rotate automatically through the different versions (each map rotation cycles to next version) by changing the value at the end.

Code: Select all

main:
 
setcvar "g_scoreboardpic" "mohdm2"

	if(int(getcvar "dm2vers") == 1)  //mod version1
        		{
	                exec maps/dm/mohdm2_m1.scr
	                level.dm2vers = 2
                                }
	else if(int(getcvar "dm2vers") == 2)  //mod version2
        		{
		exec maps/dm/mohdm2_m2.scr
		level.dm2vers = 0
                                }
	else // stock version
        		{
		level.dm2vers = 1
		}
	
	level waittill prespawn

	level waittill spawn

end
Though the script runs, these lines -

level.dm2vers = 0
level.dm2vers = 1
level.dm2vers = 2

do not appear to change the values! allways stuck with same version unless i enter new value into console then it works.

i tried this too

set dm2vers 1

Any Suggestions?
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

Some thing like this maybe ?

Code: Select all

	local.dm2vers = (int(getcvar dm2vers))

	if(local.dm2vers == 0 || local.dm2vers == NIL)
		local.dm2vers = 1

	switch(local.dm2vers)  
	{ 
		case 1:
			exec maps/dm/mohdm2_m1.scr;break //mod version1 
		case 2:
			exec maps/dm/mohdm2_m2.scr;break //mod version2
		case 3:
			exec maps/dm/mohdm2_m3.scr;break //mod version3
	}

	local.dm2vers++

	if(local.dm2vers > 3)
		local.dm2vers = 1

	setcvar dm2vers local.dm2vers
Image
User avatar
ViPER
General
Posts: 1058
Joined: Fri Jan 14, 2005 5:48 pm
Location: California
Contact:

Post by ViPER »

Thank You bdbodger,

that code works in my script, However the dm2vers is reset to 1 every rotation. So we never get to 2. :(
User avatar
ViPER
General
Posts: 1058
Joined: Fri Jan 14, 2005 5:48 pm
Location: California
Contact:

Post by ViPER »

NM it is working TY!

I had changed the names of the exec scrs....

Can someone explain how the first if works and what NIL does?

and how does ++ work? i know it adds 1 every time around but what if i wanted to add a different value every time like 5?
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

if

Post by tltrude »

The (||) means "or", so it is just checking to see if "local.dm2vers" has a value of 0 or NIL (NIL = no value) and sets the value to 1 if it does.

++ = add 1
+5 = add 5
Tom Trude,

Image
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

Just a little clarification.

Code: Select all

local.variable + 5 // this will return an error because the script interpreter won't find the left side (you know, from maths point of view ;) )
local.variable += 5 // this will add 5 to the variable's value
As to NIL & NULL, Mefy and I provided a good explanation of them recently, search the scripting forum.
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
User avatar
ViPER
General
Posts: 1058
Joined: Fri Jan 14, 2005 5:48 pm
Location: California
Contact:

Post by ViPER »

Cool, thanks everybody! :)
User avatar
ViPER
General
Posts: 1058
Joined: Fri Jan 14, 2005 5:48 pm
Location: California
Contact:

Post by ViPER »

ok next part to this - is it possible to make a condition or case statement based on number of clients on the server? How could i do something Like this -


if total_clients is = or < 6 then
play version 1
if total_clients is > 6 and < 15 then
play version 2
if total_clients is > 14 then
play version 3
User avatar
ViPER
General
Posts: 1058
Joined: Fri Jan 14, 2005 5:48 pm
Location: California
Contact:

Post by ViPER »

I want to be able to turn on and off the mod rotation switch that bdbodger wrote ^ when off stock map will run when on the switch rotates through the different mod versions.

Why doesnt this work??? crashes the script

Code: Select all

   local.modrotation = (int(getcvar modrotation)) 

   if(local.modrotation == 0 || local.modrotation == NIL) 
	{
	exec maps/dm/mohdm2_stock.scr;break //stock vers
	}
   else(local.modrotation == 1 )
	{
   //bdbodger switch here
	}
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

else(local.modrotation == 1 )
{
//bdbodger switch here
}
what is done in the else part of the if statement goes between the { and the }

else
{

local.modrotation == 1

//bdbodger switch here

}
Image
User avatar
ViPER
General
Posts: 1058
Joined: Fri Jan 14, 2005 5:48 pm
Location: California
Contact:

Post by ViPER »

couldn't get If else to work, but another switch did! :D

Here is the working script -

Code: Select all

/* 
    "Modrotation" 
   mohdm2 (used in this script as an example)
   SCRIPTING: bdBodger
   cut/paste: ViPER

RUN MULTIPLE MODDED VERSIONS IN YOUR MAP ROTATION

instructions -

set modrotation 0(off) or 1(on) in your server.cfg
Rename your stock mohdm2.scr and modded versions of that map! Give them unique names like 

mohdm2_v1
mohdm2_v2
mohdm2_v3  etc.....

Name this script mohdm2.scr

In this example I included the stock script in the mod rotation!

If you apply this script to other maps besure to change your var "dm2vers" , the max case # in the last if statement and map names! 
Put in as many or as few as you like!
modrotation will turn them all on or off.

*/

   local.modrotation = (int(getcvar modrotation)) 

   switch(local.modrotation)  // THIS TURNS MODROTATION ON/OFF
   { 
      case 0: 
         exec maps/dm/mohdm2_v1.scr;break //stock
      case 1: 

   local.dm2vers = (int(getcvar dm2vers)) 

   if(local.dm2vers == 0 || local.dm2vers == NIL) 
	local.dm2vers = 1 

   switch(local.dm2vers)   // THIS IS YOUR MODROTATION
   { 
      case 1: 
         exec maps/dm/mohdm2_v2.scr;break //mod version2
      case 2: 
         exec maps/dm/mohdm2_v3.scr;break //mod version3 
      case 3: 
         exec maps/dm/mohdm2_v4.scr;break //mod version4 
      case 4: 
         exec maps/dm/mohdm2_v1.scr;break //stock 
   } 

   local.dm2vers++ 

   if(local.dm2vers > 4) 
      local.dm2vers = 1 

   setcvar dm2vers local.dm2vers 
   } 
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

Why not just put

exec maps/dm/mohdm2_v1.scr //stock
before the second switch statement and forget about a second cvar
local.dm2vers = (int(getcvar dm2vers))

if(local.dm2vers == 0 || local.dm2vers == NIL)
exec maps/dm/mohdm2_v1.scr //stock

else
{
switch(local.dm2vers) // THIS IS YOUR MODROTATION
{
case 1:
exec maps/dm/mohdm2_v2.scr;break //mod version2
case 2:
exec maps/dm/mohdm2_v3.scr;break //mod version3
case 3:
exec maps/dm/mohdm2_v4.scr;break //mod version4
case 4:
exec maps/dm/mohdm2_v1.scr;break //stock
}

local.dm2vers++

if(local.dm2vers > 4)
local.dm2vers = 1

setcvar dm2vers local.dm2vers
}
Image
User avatar
ViPER
General
Posts: 1058
Joined: Fri Jan 14, 2005 5:48 pm
Location: California
Contact:

Post by ViPER »

The modrotation cvar is an on off switch! If you had 12 different maps running with 4 different mods each you may want to shut off the advancement of dmXvers!

each map rotation or map restart will advance the dm2vers !

You can turn them all off with "modrotation"

or set up different configs with modrotation cvar!

:D
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

You can rcon dm2vers and make it 0 for no mods or rcon and set it at 1 to 4 to keep advanceing mods but your way works too .
Image
User avatar
ViPER
General
Posts: 1058
Joined: Fri Jan 14, 2005 5:48 pm
Location: California
Contact:

Post by ViPER »

hmmm - I'm not explaining very well ! Let me try this - Imagine a map rotation of mohdm 1-7 (for each, 1 is stock and 2 or more are variations with modding)

modrotation 0

dm1vers 1
dm2vers 1
dm3vers 1
dm4vers 1
dm5vers 1
dm6vers 1
dm7vers 1

modrotation 1

dm1vers 2-6
dm2vers 1-4
dm3vers 2-8
dm4vers 1-3
dm5vers 2-5
dm6vers 2-8
dm7vers 1-12
Post Reply