Call of Duty 4: Custom Dvars: Difference between revisions

From COD Modding & Mapping Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
[[Category:Call of Duty 4]]
[[Category:Modding]]
''By Drofder2004''
''By Drofder2004''


[[Image:Nutshell.png]] Someone mentioned they did not know how to do custom dvars, instead of answering in a post, here is a quick scripting tutorial...
{{Note|Someone mentioned they did not know how to do custom dvars, instead of answering in a post, here is a quick scripting tutorial}}
 


<pre>
<pre>
if(getdvar("<dvar>") == "")
if(getdvar("<dvar>") == "")
   setdvar("<dvar>", "<default>");</pre>
   setdvar("<dvar>", "<default>");
</pre>


(Code above in pseudocode)


Code above in pseudocode...
"If dvar <dvar> is equal to nothing (if it doesn't exist)...<br>
"If dvar <dvar> is equal to nothing (if it doesn't exist)...
...create dvar with default value"
...create dvar with default value"


Thats the bare basics.
Thats the bare basics.


Next you can create minimum and maximum values (if the dvar is numeric...
Next you can create minimum and maximum values (if the dvar is numeric)




Line 26: Line 24:
   setDvar("<dvar>", 10);
   setDvar("<dvar>", 10);
else if(getDvarInt("<dvar>") < 0)
else if(getDvarInt("<dvar>") < 0)
   setDvar("<dvar>", 0);</pre>
   setDvar("<dvar>", 0);
</pre>




Again, pseudocode, starting at line 3 (continued from above).
Again, pseudocode, starting at line 3 (continued from above).


...else, if the dvar is greater than 10, set the dvar to 10, or
...else, if the dvar is greater than 10, set the dvar to 10, or<br>
...if the dvar is less than 0, set it to 0.
...if the dvar is less than 0, set it to 0.


Make sure you get you note the usage of getDvar and getDvarInt (also, you can use getDvarFloat, to retrieve decimal values).
Make sure you get you note the usage of getDvar and getDvarInt (also, you can use getDvarFloat, to retrieve decimal values).


And finally, using the dvar in your script...
And finally, using the dvar in your script.
Now, there are many ways to use the dvar, but the main way is to use it as a variable...
Now, there are many ways to use the dvar, but the main way is to use it as a variable.




Line 52: Line 51:
Remeber, use the correct 'getDvar', use...
Remeber, use the correct 'getDvar', use...


*getDvar for TEXT based dvars (example: getDvar("g_gametype"); )
*getDvar for TEXT based dvars (example: <code>getDvar("g_gametype");</code> )
*getDvarInt for INTEGERS (whole number, example: getDvarInt("scr_forcerespawn"); )
*getDvarInt for INTEGERS (whole number, example: <code>getDvarInt("scr_forcerespawn");</code> )
*getDvarInt for FLOATS (decimals, example: getDvarFloat("scr_hq_timelimit"); )
*getDvarFloat for FLOATS (decimals, example: <code>getDvarFloat("scr_hq_timelimit");</code> )


Another good use, is to use the dvar as a wait command...
 
{{Info|Another good use, is to use the dvar as a wait command}}


For example,  
For example,  
Line 72: Line 72:




The "while()" in the above script will keep waiting 1 second, until the dvar is changed to 0, once changed, the main function will continue.  
The <code>while()</code> in the above script will keep waiting 1 second, until the dvar is changed to 0, once changed, the main function will continue.  


Now you know dvars!
Now you know dvars!


==Sources==
==Sources==


[http://www.codjumper.com/forums/viewtopic.php?f=19&t=5388 CodJumper]
[http://www.codjumper.com/forums/viewtopic.php?f=19&t=5388 CodJumper]
[[Category:Call of Duty 4]]
[[Category:Modding]]

Revision as of 07:15, 30 April 2009

By Drofder2004

Someone mentioned they did not know how to do custom dvars, instead of answering in a post, here is a quick scripting tutorial
if(getdvar("<dvar>") == "")
   setdvar("<dvar>", "<default>");

(Code above in pseudocode)

"If dvar <dvar> is equal to nothing (if it doesn't exist)...
...create dvar with default value"

Thats the bare basics.

Next you can create minimum and maximum values (if the dvar is numeric)


if(getDvar("<dvar>") == "")
   setDvar("<dvar>", "<default>");
else if(getDvarInt("<dvar>") > 10)
   setDvar("<dvar>", 10);
else if(getDvarInt("<dvar>") < 0)
   setDvar("<dvar>", 0);


Again, pseudocode, starting at line 3 (continued from above).

...else, if the dvar is greater than 10, set the dvar to 10, or
...if the dvar is less than 0, set it to 0.

Make sure you get you note the usage of getDvar and getDvarInt (also, you can use getDvarFloat, to retrieve decimal values).

And finally, using the dvar in your script. Now, there are many ways to use the dvar, but the main way is to use it as a variable.


if(getDvar("<dvar>") == "")
   setDvar("<dvar>", "<default>");
else if(getDvarInt("<dvar>") > 10)
   setDvar("<dvar>", 10);
else if(getDvarInt("<dvar>") < 0)
   setDvar("<dvar>", 0);
<variable> = getDvarInt("<dvar>");


Remeber, use the correct 'getDvar', use...

  • getDvar for TEXT based dvars (example: getDvar("g_gametype"); )
  • getDvarInt for INTEGERS (whole number, example: getDvarInt("scr_forcerespawn"); )
  • getDvarFloat for FLOATS (decimals, example: getDvarFloat("scr_hq_timelimit"); )


Another good use, is to use the dvar as a wait command

For example,

main()
{
   while(getDvar("wait") != 0)
   {
      wait 1;
   }

   iprintln("Wait dvar is equal to 0");
}


The while() in the above script will keep waiting 1 second, until the dvar is changed to 0, once changed, the main function will continue.

Now you know dvars!


Sources

CodJumper