

<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.zeroy.com/index.php?action=history&amp;feed=atom&amp;title=Call_of_Duty_4%3A_CoD_Script_Handbook</id>
	<title>Call of Duty 4: CoD Script Handbook - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.zeroy.com/index.php?action=history&amp;feed=atom&amp;title=Call_of_Duty_4%3A_CoD_Script_Handbook"/>
	<link rel="alternate" type="text/html" href="https://wiki.zeroy.com/index.php?title=Call_of_Duty_4:_CoD_Script_Handbook&amp;action=history"/>
	<updated>2026-05-03T20:58:22Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://wiki.zeroy.com/index.php?title=Call_of_Duty_4:_CoD_Script_Handbook&amp;diff=16480&amp;oldid=prev</id>
		<title>Zeroy: Protected &quot;Call of Duty 4: CoD Script Handbook&quot; ([edit=autoconfirmed] (indefinite) [move=autoconfirmed] (indefinite))</title>
		<link rel="alternate" type="text/html" href="https://wiki.zeroy.com/index.php?title=Call_of_Duty_4:_CoD_Script_Handbook&amp;diff=16480&amp;oldid=prev"/>
		<updated>2012-01-26T09:41:01Z</updated>

		<summary type="html">&lt;p&gt;Protected &amp;quot;&lt;a href=&quot;/index.php?title=Call_of_Duty_4:_CoD_Script_Handbook&quot; title=&quot;Call of Duty 4: CoD Script Handbook&quot;&gt;Call of Duty 4: CoD Script Handbook&lt;/a&gt;&amp;quot; ([edit=autoconfirmed] (indefinite) [move=autoconfirmed] (indefinite))&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 09:41, 26 January 2012&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Zeroy</name></author>
	</entry>
	<entry>
		<id>https://wiki.zeroy.com/index.php?title=Call_of_Duty_4:_CoD_Script_Handbook&amp;diff=16479&amp;oldid=prev</id>
		<title>Zeroy: /* Arrays */</title>
		<link rel="alternate" type="text/html" href="https://wiki.zeroy.com/index.php?title=Call_of_Duty_4:_CoD_Script_Handbook&amp;diff=16479&amp;oldid=prev"/>
		<updated>2012-01-26T09:40:19Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Arrays&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=Preface=&lt;br /&gt;
&lt;br /&gt;
Hi, I am Tristan. I am the creator of www.InfinityTutorials.com. I love programming, modding,&lt;br /&gt;
gaming and best of all teaching others. That’s why I strive to create a trusted modding &amp;amp;&lt;br /&gt;
mapping community for everyone to join, gain experience &amp;amp; knowledge from.&lt;br /&gt;
&lt;br /&gt;
This book should help you to understand the fundamentals of CoD Script programming for Call of&lt;br /&gt;
Duty. By the end of it, you should feel comfortable with CoD Script, its layout, and how it works.&lt;br /&gt;
I hope you take away as much as you can from this book, and if you need help on any topic, or&lt;br /&gt;
more advanced topics, please visit the website, and we’ll be more than happy to help you.&lt;br /&gt;
&lt;br /&gt;
So get ready, get modding and enjoy!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Chapter 1 – Variables &amp;amp; Operators=&lt;br /&gt;
&lt;br /&gt;
==Welcome==&lt;br /&gt;
Welcome to the InfinityTutorials CoD Script Handbook. By reading this book from start to&lt;br /&gt;
finish, you’ll expect to be up and running making mod’s for CoD in no time! Scripting isn’t very&lt;br /&gt;
hard, and as long as you’re patient and you read closely, you’ll be a CoD Script master in a few&lt;br /&gt;
days with a little practice.&lt;br /&gt;
&lt;br /&gt;
Alright, to start your programming adventure, you’ll need a few tools. Even though these are&lt;br /&gt;
optional, they will make your programming experience a better &amp;amp; more organized one. The first&lt;br /&gt;
is a syntax highlighting text editor. I recommend [http://www.pnotepad.org/ Programmer&amp;#039;s Notepad].&lt;br /&gt;
Using a program like this, you can create &amp;amp; organize&lt;br /&gt;
projects, edit &amp;amp; create your scripts, and the best of all, it include syntax highlighting.&lt;br /&gt;
Syntax highlighting helps you to distinguish between variables, operators,&lt;br /&gt;
strings and keywords, which we will cover later in the book.&lt;br /&gt;
&lt;br /&gt;
The second tool, is a Zip compressor &amp;amp; extractor. Now, tools like Win-Zip and RAR will work,&lt;br /&gt;
but what happens if you don’t have them, and don’t want to spend the money buying them?&lt;br /&gt;
Well there is a great free alternative called [http://7-zip.org/ 7-Zip].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
Variables are your best friend. They can hold numbers, strings or even simple things such as&lt;br /&gt;
True and False. I don’t know of a single script that doesn’t contain at least 1 variable in it. This&lt;br /&gt;
is how important they are. Variables are much simpler in CoD Script than in similar languages like&lt;br /&gt;
C or C++. This also makes them a little less error prone, and easier to use. Here’s some&lt;br /&gt;
examples of variables and their properties:&lt;br /&gt;
&lt;br /&gt;
 my_number = 1;&lt;br /&gt;
&lt;br /&gt;
The variable my_number now holds the digit value 1. A practical use for this type of variable&lt;br /&gt;
would be, for example, number_of_lives which would hold the number of lives a player has.&lt;br /&gt;
&lt;br /&gt;
 my_double = 2.0;&lt;br /&gt;
&lt;br /&gt;
The variable my_double now holds the double digit value 2.0. You could use this to store a&lt;br /&gt;
players points for example.&lt;br /&gt;
&lt;br /&gt;
 my_message = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
The variable my_message now holds the string &amp;quot;Hello World&amp;quot;. You could use this type of&lt;br /&gt;
variable to hold a custom HUD element message, or a welcome message.&lt;br /&gt;
As you can see, the general format of a variable is:&lt;br /&gt;
&lt;br /&gt;
 name = value;&lt;br /&gt;
&lt;br /&gt;
Remember to always end your lines &amp;amp; declarations with semi colons &amp;quot;;&amp;quot; or you will receive weird&lt;br /&gt;
looking console error messages. In CoD Script the semi colon lets the compiler know that you’re&lt;br /&gt;
finished with one line and that you’re about to start another. However, there are cases where&lt;br /&gt;
you don’t end a line with a semi colon, this is with loops, if/else statements etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Operators==&lt;br /&gt;
&lt;br /&gt;
Operators are the little things that manipulate variables. You can use operators to add,&lt;br /&gt;
subtract, divide &amp;amp; multiply variables. They are extremely useful, and you’re bound to use them&lt;br /&gt;
in tons of scripts. Here are some examples of operators in use:&lt;br /&gt;
&lt;br /&gt;
 number_one = 1;&lt;br /&gt;
 number_two = 2;&lt;br /&gt;
 the_result = number_one + number_two;&lt;br /&gt;
&lt;br /&gt;
In this example, number_one and number_two are added together, and the result is placed in&lt;br /&gt;
the variable the_result. Thus, the variable the_result now holds the value 3.&lt;br /&gt;
&lt;br /&gt;
 number_one = 1;&lt;br /&gt;
 number_two = 2;&lt;br /&gt;
 the_result = number_two - number_one;&lt;br /&gt;
&lt;br /&gt;
In this example, number_one is subtracted from number_two, and the result is placed in the&lt;br /&gt;
variable the_result. Thus, the variable the_result now holds the value 1.&lt;br /&gt;
&lt;br /&gt;
 number_one = 1;&lt;br /&gt;
 number_two = 2;&lt;br /&gt;
 the_result = number_one * number_two;&lt;br /&gt;
&lt;br /&gt;
In this example, number_one and number_two are multiplied, and the result is placed in the&lt;br /&gt;
variable the_result. Thus, the variable the_result now holds the value 2.&lt;br /&gt;
&lt;br /&gt;
 number_one = 4;&lt;br /&gt;
 number_two = 2;&lt;br /&gt;
 the_result = number_one / number_two;&lt;br /&gt;
&lt;br /&gt;
In this example, number_one and number_two are divided, and the result is placed in the&lt;br /&gt;
variable the_result. Thus, the variable the_result now holds the value 2.&lt;br /&gt;
&lt;br /&gt;
 number_one = 4;&lt;br /&gt;
 number_one++;&lt;br /&gt;
&lt;br /&gt;
In this example, the ‘++’ simply means, increase the value by 1. You can also decrease a value&lt;br /&gt;
by 1 using ‘--‘, an example: number_one--;&lt;br /&gt;
&lt;br /&gt;
Now, what happens if you want to add 2, 3, 4 etc to a variable? Or want to multiply the&lt;br /&gt;
variable’s value by a certain number? Well, you can do it like this:&lt;br /&gt;
&lt;br /&gt;
 number = 1;&lt;br /&gt;
 number = number + 2;&lt;br /&gt;
&lt;br /&gt;
In the above example, number is given the value 1, then, it’s set to equal itself, plus 2. Which&lt;br /&gt;
simply means, that in the end, number now equals 3.&lt;br /&gt;
A shorter way of doing this is:&lt;br /&gt;
&lt;br /&gt;
number = 1;&lt;br /&gt;
number += 2;&lt;br /&gt;
&lt;br /&gt;
This shorter version above achieves the same result as the previous example. This shortcut&lt;br /&gt;
works with all the operators. So for example, if you wanted to divide a variable by 2, then&lt;br /&gt;
multiply it by 5, this is how it would be set-up:&lt;br /&gt;
&lt;br /&gt;
 number = 10;&lt;br /&gt;
 number /= 2;&lt;br /&gt;
 number *= 5;&lt;br /&gt;
&lt;br /&gt;
At the end of this, number would now hold the value 25.&lt;br /&gt;
&lt;br /&gt;
=Chapter 2 – Functions &amp;amp; Loops=&lt;br /&gt;
&lt;br /&gt;
==Functions==&lt;br /&gt;
Functions are a vital part of any programming language, and CoD Script is no different. Functions&lt;br /&gt;
help organize your code and allow you to perform more advanced tasks.&lt;br /&gt;
So lets dive right in, here is an example of a small function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
my_function()&lt;br /&gt;
{&lt;br /&gt;
	return 5;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, functions start with a name to uniquely identify them. Their names cannot&lt;br /&gt;
contain anything except letters, numbers and underscores. Their names cannot start with a&lt;br /&gt;
number or contain spaces. They then continue with a left bracket &amp;amp; a right bracket. Then they&lt;br /&gt;
continue with a left open curly brace. After this brace you type the code you want executed&lt;br /&gt;
when your function is called. You then end the function with a right closed curly brace. One&lt;br /&gt;
thing to note is that CoD Script isn’t picky about how your code is laid out, so the following is&lt;br /&gt;
completely acceptable:&lt;br /&gt;
&lt;br /&gt;
 my_function(){ return 5; }&lt;br /&gt;
&lt;br /&gt;
Now, you may be asking, what does return do? Well, it’s a CoD Script keyword, and in this&lt;br /&gt;
example it returns the value 5. This value is sent to what ever function called it. So, a working&lt;br /&gt;
example would be:&lt;br /&gt;
&lt;br /&gt;
 the_number_five = my_function();&lt;br /&gt;
&lt;br /&gt;
In this example, the_number_five now contains the value 5 since my_function returned the&lt;br /&gt;
value 5 to it through the return keyword.&lt;br /&gt;
&lt;br /&gt;
An important thing to note is that not all functions need to return a value, these functions are&lt;br /&gt;
usually called Void functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Functions can perform a wide verity of operations when called. One very special feature of&lt;br /&gt;
functions are Parameters. Parameters allow you to pass data into the function to work with.&lt;br /&gt;
&lt;br /&gt;
So lets take a look:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
add_five( my_arguement )&lt;br /&gt;
{&lt;br /&gt;
	temp = my_argument;&lt;br /&gt;
	temp += 5;&lt;br /&gt;
	return temp;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, you can place parameters between the two brackets next to the function&lt;br /&gt;
name. The parameter names follow the same rules of the function names. Lets see an example&lt;br /&gt;
of this function in use:&lt;br /&gt;
&lt;br /&gt;
 not_yet_ten = 5;&lt;br /&gt;
 this_is_ten = add_five( not_yet_ten );&lt;br /&gt;
&lt;br /&gt;
In this example, not_yet_ten is initialized to 5. Then we declare the variable this_is_ten and&lt;br /&gt;
make it equal the function add_five, and we pass not_yet_ten as an argument. Looking into&lt;br /&gt;
the function, we see it takes not_yet_ten and places it into the variable my_argument. Then,&lt;br /&gt;
a new variable temp is created, and it’s set to equal my_argument.. 5 is then added to temp&lt;br /&gt;
and then the function returns temp which in this case is now equals to 10 since the argument&lt;br /&gt;
passed into the function was equal to 5. At the end of this whole procedure, the variable&lt;br /&gt;
this_is_ten, equals, you guessed it, 10!&lt;br /&gt;
&lt;br /&gt;
Ok, after that long winded example, you should have a clear understanding of how parameters&lt;br /&gt;
&amp;amp; arguments work. Now, another point to note is that you can have more than one parameter&lt;br /&gt;
like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
add_numbers( number_one, number_two, number_three )&lt;br /&gt;
{&lt;br /&gt;
	return number_one + number_two + number_three;&lt;br /&gt;
}&lt;br /&gt;
the_result = add_numbers( 1, 2, 3 );&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All that’s needed to use more parameters is that you separate them with comma’s… simple. In&lt;br /&gt;
that example the final variable the_result would equal 6.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There’s one mistake a lot of people make though, and that’s using variables out side of their&lt;br /&gt;
scope. A scope is any section between the opening brace &amp;quot;{&amp;quot; and the closing brace &amp;quot;}&amp;quot;. Any&lt;br /&gt;
variables declared inside this scope can only be used inside this scope, and not anywhere&lt;br /&gt;
outside it. However, you can declare global variables which can be used out side of their&lt;br /&gt;
scopes. Here’s an example of a classic mistake:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function()&lt;br /&gt;
{&lt;br /&gt;
	local_var = 1;&lt;br /&gt;
}&lt;br /&gt;
result = local_var;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The example above would cause a compile error. This is because the variable local_var is&lt;br /&gt;
declared in the functions scope, and then used outside of it’s scope when assigning it to&lt;br /&gt;
another variable. However, if you do want to perform an action like this, you can declare a&lt;br /&gt;
global variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function()&lt;br /&gt;
{&lt;br /&gt;
	self.global_var = 5;&lt;br /&gt;
}&lt;br /&gt;
result = self.global_var;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In CoD Script the above is perfect code and will not generate any errors. In that example,&lt;br /&gt;
we used the keyword self which will be explained later.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Loops==&lt;br /&gt;
Ahh, loops, my favourite little function ?. Loops allow you to repeat a process a set amount of&lt;br /&gt;
times, or a limited amount of times. Loops can be used to monitor variables, print messages,&lt;br /&gt;
check players etc, anything that needs constant attention or repeating.&lt;br /&gt;
&lt;br /&gt;
There are two types of loops. The first we’ll look at is the while loop. Lets take a look at an&lt;br /&gt;
example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
number = 1;&lt;br /&gt;
while( number &amp;lt; 10 )&lt;br /&gt;
{&lt;br /&gt;
	number += 1;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, number is given the value 1. A while loop works by checking the argument,&lt;br /&gt;
which in this case is &amp;quot;number &amp;lt; 10&amp;quot; to see if its true or false. In this statement, it’s basically&lt;br /&gt;
saying, &amp;quot;Loop While Number Is Less, But Does Not Equal 10&amp;quot;. If your argument is true then the&lt;br /&gt;
loop performs the actions between the braces. When it gets to the last brace, it jumps back to&lt;br /&gt;
the top, and checks your statement again. If the statement is still true, then it will perform the&lt;br /&gt;
actions between the braces again. This process will continue until the statement is false which&lt;br /&gt;
is this example would be when the variable number equals ten.&lt;br /&gt;
&lt;br /&gt;
At the end of that loop, if we were to check the value of number we would see that it’s now&lt;br /&gt;
equal to 9.&lt;br /&gt;
&lt;br /&gt;
While loops can also be set to loop forever. This is done by simply by adding an argument that&lt;br /&gt;
will never return false, like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while( 1 )&lt;br /&gt;
{&lt;br /&gt;
	something here…&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
OR&lt;br /&gt;
&amp;lt;pre&amp;gt;while( true )&lt;br /&gt;
{&lt;br /&gt;
	something here…&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since 1 is 1, there is nothing to check, it will always be true. Even better, just put true in there.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here’s an example of an infinite while loop in use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while( true )&lt;br /&gt;
{&lt;br /&gt;
	IprintLnBold( &amp;quot;This is a looping message&amp;quot; );&lt;br /&gt;
	wait 5;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, the message &amp;quot;This is a looping message&amp;quot; will be displayed every 5 seconds&lt;br /&gt;
and will never end. If you’re unsure what some of those commands are, don’t worry, they will&lt;br /&gt;
be covered later.&lt;br /&gt;
&lt;br /&gt;
The second loop we will cover is the for loop. Here is a example of one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
result = 0;&lt;br /&gt;
for( number = 0; number &amp;lt; 10; number++ )&lt;br /&gt;
{&lt;br /&gt;
	result += number;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you may have noticed, the for loop takes 3 arguments, the first is a declaration of a variable&lt;br /&gt;
or counter variable, the second is what to check for (same as the true/false for the while loop),&lt;br /&gt;
the third is what to do to the counter variable when 1 loop is finished. You must separate the&lt;br /&gt;
arguments with semi-colons.&lt;br /&gt;
&lt;br /&gt;
In the example above, when the loop finishes (number = 10) the variable result will equal 45.&lt;br /&gt;
You can also make infinite for(;;) loops, but it’s a better choice to use a while(true) loop in that&lt;br /&gt;
case.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Chapter 3 – Arrays &amp;amp; Keywords=&lt;br /&gt;
&lt;br /&gt;
==Arrays==&lt;br /&gt;
Arrays are possibly the greatest type of variable alive in my eyes. Arrays are a special type of&lt;br /&gt;
variable that can hold multiple entries of data, like a list of names, maps, scores etc.&lt;br /&gt;
Alright, lets look at how to make an array:&lt;br /&gt;
&lt;br /&gt;
 my_array = [];&lt;br /&gt;
 my_array[0] = &amp;quot;Data 1&amp;quot;;&lt;br /&gt;
 my_array[1] = &amp;quot;Data 2&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
We start arrays with the variable name, but then, instead of assigning a value to it, we assign []&lt;br /&gt;
to it (Two opening &amp;amp; closing square brackets). This declaration tells the compiler that the&lt;br /&gt;
variable my_array is now an array. We then add data to the array by typing the variable name,&lt;br /&gt;
followed by a subscript. A subscript tells the compiler which part of the array to use/assign.&lt;br /&gt;
Array subscripts ALWAYS start with zero. This is one thing you must learn, as it’s the case in&lt;br /&gt;
many programming languages. Learn it now, and it will save you grief later on. When you add&lt;br /&gt;
more data to the array, you must increase the subscript by 1, and not 2 or a fraction etc. Here&lt;br /&gt;
is an example of an error:&lt;br /&gt;
&lt;br /&gt;
 my_broken_array = [];&lt;br /&gt;
 my_broken_array[1] = &amp;quot;Eeek&amp;quot;;&lt;br /&gt;
 my_broken_array[3] = &amp;quot;Yuck&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
In this example error, you see that we started the array subscript with 1, and then incremented&lt;br /&gt;
it with 2 instead of 1. This is bad, don’t try this at home.&lt;br /&gt;
Now, arrays work great with for loops. Here’s an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awesome_array = [];&lt;br /&gt;
for( int = 0; int &amp;lt; 10; int++ )&lt;br /&gt;
{&lt;br /&gt;
	awesome_array[int] = int + 5;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, awesome_array is initialized, then we step into a for loop, where it sets the&lt;br /&gt;
first 9 subscripts of awesome_array to the value of int plus 5. So, if we had to check the value&lt;br /&gt;
of awesome_array[0] it would equal 5, awesome_array[1] would equal 6, awesome_array[2]&lt;br /&gt;
would equal 7 etc. This array would only go up to awesome_array[9], so trying to access any&lt;br /&gt;
subscript like 10 or higher would cause an error, or no error would be produced, but you’ll be&lt;br /&gt;
wondering why you’re script is acting funny.&lt;br /&gt;
&lt;br /&gt;
==Keywords==&lt;br /&gt;
&lt;br /&gt;
Alright, now that you know the essential basics of CoD Script, lets move on to some CoD&lt;br /&gt;
specific keywords.&lt;br /&gt;
&lt;br /&gt;
#wait = the time to wait in seconds&lt;br /&gt;
#self = an alias to the entity that called the script&lt;br /&gt;
#level = an alias to the level (the main script)&lt;br /&gt;
#waittill = wait until another script notify’s a keyword&lt;br /&gt;
#notify = used to trigger waittill&lt;br /&gt;
#endon = used to kill a function on a notify&lt;br /&gt;
#delete = delete an entity&lt;br /&gt;
#destroy = used to destroy structs &amp;amp; hud elements&lt;br /&gt;
&lt;br /&gt;
These are just some of the few keywords available. Below I will give you examples of each.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;wait&amp;#039;&amp;#039;&amp;#039; | this will loop every 5 seconds&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while( 1 )&lt;br /&gt;
{&lt;br /&gt;
	wait 5;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;self&amp;#039;&amp;#039;&amp;#039; | the player who called this script will be killed after 5 seconds&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wait 5;&lt;br /&gt;
self suicide();&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;level&amp;#039;&amp;#039;&amp;#039; | grab an array of all the players&lt;br /&gt;
 players = level.players;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;waittill&amp;#039;&amp;#039;&amp;#039; | this script will wait until &amp;quot;start_me&amp;quot; is notified&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
self waittill( &amp;quot;start_me&amp;quot; );&lt;br /&gt;
self suicide();&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;notify&amp;#039;&amp;#039;&amp;#039; | this will trigger any waittill’s with the same keyword, like the one above&lt;br /&gt;
 self notify( &amp;quot;start_me&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;endon&amp;#039;&amp;#039;&amp;#039; | this functions dies when &amp;quot;Kill_Me&amp;quot; is notified&lt;br /&gt;
 self endon( &amp;quot;Kill_Me&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;delete&amp;#039;&amp;#039;&amp;#039; | this will delete an entity&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
model = spawn( &amp;quot;script_model&amp;quot;, level.mapCenter );&lt;br /&gt;
model delete();&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;destroy&amp;#039;&amp;#039;&amp;#039; | this will destroy a hud elem&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hud_elem = newHudElem();&lt;br /&gt;
hud_elem destroy();&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a full list of all the available functions &amp;amp; keywords, you can go to [[Call_of_Duty_4:_Scripting_Reference|Scripting Reference (Wiki)]] or [http://www.zeroy.com/script/ InfinityWard Scripting index]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Chapter 4 – If/Else &amp;amp; Switch=&lt;br /&gt;
&lt;br /&gt;
==If/Else Statements==&lt;br /&gt;
&lt;br /&gt;
If/Else statements are conditional statements that are very, very useful. They can check the&lt;br /&gt;
state of a variable, make decisions based on data and many other cool things.&lt;br /&gt;
&lt;br /&gt;
If/Else statements are actually very easy to learn. So lets dive right in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
my_num = 5;&lt;br /&gt;
if( my_num == 5 )&lt;br /&gt;
{&lt;br /&gt;
	self IprintLnBold( &amp;quot;The number is five!&amp;quot; );&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
	self IprintLnBold( &amp;quot;The number is NOT five!&amp;quot; );&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, we initialize a variable called my_num to 5. Then we use an IF()&lt;br /&gt;
statement to check if the number is equal to 5. If it is, we print the message &amp;quot;The number is&lt;br /&gt;
five!&amp;quot;, and if the number is not 5, we then display the message &amp;quot;The number is NOT five!&amp;quot;. If we&lt;br /&gt;
run the script like it is, we would see the first message, however, if we changed the variable&lt;br /&gt;
my_num at the top, to another number, the second message would be displayed because the&lt;br /&gt;
IF() check would see that my_num does not equal 5, and so it wall fall back to the else&lt;br /&gt;
statement.&lt;br /&gt;
&lt;br /&gt;
You can also do multiple levels of If/Else statements. These are If/Else If/Else statements. They&lt;br /&gt;
look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
num = 20;&lt;br /&gt;
if( num == 20 )&lt;br /&gt;
	self IprintLnBold( &amp;quot;Num equals 20&amp;quot; );&lt;br /&gt;
else if( num &amp;gt; 20 )&lt;br /&gt;
	self IprintLnBold( &amp;quot;Num is greater than 20&amp;quot; );&lt;br /&gt;
else&lt;br /&gt;
	self IprintLnBold( &amp;quot;Num is less than 20&amp;quot; );&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Firstly, if you are wondering why the Curly Brackets have all disappeared, its because there’s a&lt;br /&gt;
neat trick with If, Else If, Else, For Loops and While Loops, and that is… if your statement will&lt;br /&gt;
only contain 1 line of code to execute, you don’t need to put curly brackets in. However, if it is&lt;br /&gt;
more than one line of code to be executed, then you have to put the curly brackets in.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We see in the above example that the code will now check to see if num is equal, higher or&lt;br /&gt;
lower than 20.&lt;br /&gt;
&lt;br /&gt;
Another neat trick with If, Else If, Else, For Loops and While Loops is that if you’re variable is a&lt;br /&gt;
Boolean variable, meaning it’s either true or false, you can just type in the variable name to&lt;br /&gt;
check if it’s true, or put the bang character &amp;quot;!&amp;quot; in-front of the name to check if it’s false. See&lt;br /&gt;
below for an example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
is_dead = false;&lt;br /&gt;
&lt;br /&gt;
if( is_dead )&lt;br /&gt;
	self IprintLnBold( &amp;quot;You are dead&amp;quot; );&lt;br /&gt;
else if( !is_dead )&lt;br /&gt;
	self IprintLnBold( &amp;quot;YAY! You’re not dead&amp;quot; );&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the if( is_dead ) is checking if is_dead equals true, and the else if(&lt;br /&gt;
!is_dead ) is checking whether is_dead is false, and in this case it is, so the player would&lt;br /&gt;
receive the message &amp;quot;YAY! You’re not dead&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In most programming languages, zero is considered false, and anything non-zero is true.&lt;br /&gt;
Some good operators for if/else statements are &amp;amp;&amp;amp; (Meaning AND), || (Meaning OR), ==&lt;br /&gt;
(Meaning EQUALS) and != (Meaning DOES NOT EQUAL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Switch Blocks==&lt;br /&gt;
&lt;br /&gt;
Switch blocks are usually used when you need to do multiple checks where and If/Else If&lt;br /&gt;
statement would be too long, or messy to type out.&lt;br /&gt;
Lets take a look at a switch statement:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
my_number = 5;&lt;br /&gt;
switch( my_number )&lt;br /&gt;
{&lt;br /&gt;
	case 5:&lt;br /&gt;
		self IprintLnBold( &amp;quot;The number is 5&amp;quot; );&lt;br /&gt;
		break;&lt;br /&gt;
	case 6:&lt;br /&gt;
		self IprintLnBold( &amp;quot;The number is 6&amp;quot; );&lt;br /&gt;
		break;&lt;br /&gt;
	case 7:&lt;br /&gt;
		self IprintLnBold( &amp;quot;The number is 7&amp;quot; );&lt;br /&gt;
		break;&lt;br /&gt;
	default:&lt;br /&gt;
		self IprintLnBold( &amp;quot;The number is not 5, 6, or 7&amp;quot; );&lt;br /&gt;
		break;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, don’t get too worried about it’s looks, yea, they look mean, but they can be a lot more&lt;br /&gt;
user friendly to use that huge blocks of If/Else statements.&lt;br /&gt;
&lt;br /&gt;
In the example, we start by declaring a variable my_number. We then start the switch block&lt;br /&gt;
with the keyword switch and then in brackets what variable we will be comparing. Then, inside&lt;br /&gt;
the curly brackets, we start the comparisons. We start one comparison with the keyword case&lt;br /&gt;
followed by what we want to compare it too, then end it with a colon. Under that, we place&lt;br /&gt;
the code we want executed if the variable equals the case, we then follow that with the&lt;br /&gt;
break; keyword to let the script know we’re done inside the switch block. At the very bottom,&lt;br /&gt;
we add a keyword called default followed by a colon. Under here we put the code that will be&lt;br /&gt;
executed if the variable doesn’t match any of the cases, again, followed by a break;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Chapter 5 – Lets start Scripting=&lt;br /&gt;
&lt;br /&gt;
==Let’s Start==&lt;br /&gt;
&lt;br /&gt;
All right, you feel like making a mod yet? Well I hope you do!&lt;br /&gt;
To follow along with this book, you need to install the mod tools for Call of Duty 4. These can&lt;br /&gt;
be found here [[Call_of_Duty_4:_needed|CoD4 Mod Tools]].&lt;br /&gt;
&lt;br /&gt;
With the mod tools installed, you’ll have access to all the raw files needed to start scripting a&lt;br /&gt;
mod for the game.&lt;br /&gt;
&lt;br /&gt;
If you’re mainly wanting to script for CoD4, you will only need to turn your attention to the&lt;br /&gt;
raw\maps folder. This is where all the raw scripts for Call of Duty 4 are located.&lt;br /&gt;
Whenever you see [root] below, its an alias for you Call of Duty 4 installation directory, which&lt;br /&gt;
is defaults too&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;C:\Program Files\Activision\Call of Duty 4 - Modern Warfare&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
OK, you’re ready to go!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example Anti Camp Script==&lt;br /&gt;
&lt;br /&gt;
For our first task, I’ll teach you how to script an anti camp function. From now on, I’ll refer to&lt;br /&gt;
the anti camp function as the ACF.&lt;br /&gt;
&lt;br /&gt;
So what is needed in an ACF? Well, we need to monitor the players to make sure they are not&lt;br /&gt;
sitting in one spot for too long. If they are sitting in one spot for too long, lets warn them that&lt;br /&gt;
they are camping &amp;amp; give them 10 seconds to move. If they don’t move within those 10 seconds,&lt;br /&gt;
we’ll punish them by killing them.&lt;br /&gt;
&lt;br /&gt;
So already we can see we need a couple of things:&lt;br /&gt;
&lt;br /&gt;
#A while loop that constantly monitors the player&lt;br /&gt;
#A function to somehow see how far a player has moved in a certain amount of time&lt;br /&gt;
#A function to punish the player&lt;br /&gt;
#A timer to check against.&lt;br /&gt;
&lt;br /&gt;
So, lets start with our variables:&lt;br /&gt;
&lt;br /&gt;
 my_camp_time = 0;&lt;br /&gt;
 have_i_been_warned = false;&lt;br /&gt;
 max_distance = 80;&lt;br /&gt;
 camp_time = 30;&lt;br /&gt;
&lt;br /&gt;
*my_camp_time will be the time in seconds the player has sat in one spot.&lt;br /&gt;
*have_i_been_warned will either be false if they haven’t been warned about camping, or true if they have been warned.&lt;br /&gt;
*max_distance is the distance the player needs to move within the camp_time limit to not be considered a camper.&lt;br /&gt;
&lt;br /&gt;
Now, we need to somehow check how far the player has moved on a constant basis. If they&lt;br /&gt;
haven’t moved further than the max_distance we need to increment the my_camp_time&lt;br /&gt;
variable. Then we need to check my_camp_time against camp_time, and if they are equal, we&lt;br /&gt;
need to warn the player &amp;amp; set the have_i_been_warned to true. We then give the player 10&lt;br /&gt;
seconds to move, and if he doesn’t. bam! We kill him.&lt;br /&gt;
&lt;br /&gt;
So, I head over to [[Call_of_Duty_4:_Scripting_Reference|Scripting Reference]] and look for a distance function, and what do&lt;br /&gt;
you know? They have one called distance() and distance2d(). The distance2d() looks like the&lt;br /&gt;
one we need. So lets set-up our while loop:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
level waittill( &amp;quot;prematch_over&amp;quot; );&lt;br /&gt;
self endon( &amp;quot;death&amp;quot; );&lt;br /&gt;
my_camp_time = 0;&lt;br /&gt;
have_i_been_warned = false;&lt;br /&gt;
max_distance = 80;&lt;br /&gt;
camp_time = 30;&lt;br /&gt;
&lt;br /&gt;
while( 1 )&lt;br /&gt;
{&lt;br /&gt;
	old_position = self.origin;&lt;br /&gt;
	wait 1;&lt;br /&gt;
&lt;br /&gt;
	new_position = self.origin;&lt;br /&gt;
	distance = distance2d( old_position, new_position );&lt;br /&gt;
&lt;br /&gt;
	if( distance &amp;lt; max_distance )&lt;br /&gt;
		my_camp_time++;&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		my_camp_time = 0;&lt;br /&gt;
		have_i_been_warned = false;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if( my_camp_time == camp_time &amp;amp;&amp;amp; !have_i_been_warned )&lt;br /&gt;
	{&lt;br /&gt;
		self IprintLnBold( &amp;quot;Please stop camping, 10 seconds to move&amp;quot; );&lt;br /&gt;
		have_i_been_warned = true;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if( my_camp_time == ( camp_time + 10 ) &amp;amp;&amp;amp; have_i_been_warned )&lt;br /&gt;
	{&lt;br /&gt;
		self IprintLnBold( &amp;quot;You will be killed for camping!&amp;quot;);&lt;br /&gt;
		wait 2;&lt;br /&gt;
		self suicide();&lt;br /&gt;
	}&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, that alone won’t do anything, so, lets throw it in a custom function called _AntiCamp().&lt;br /&gt;
&lt;br /&gt;
Path 1:&lt;br /&gt;
OK, if you have the mod tools installed, go to [root]\raw\maps\mp\gametypes.&lt;br /&gt;
&lt;br /&gt;
Path 2:&lt;br /&gt;
Now open a new window, and navigate to [root]\mods. Inside that folder, make a new&lt;br /&gt;
folder called MyModTest. Inside that folder, build a folder structure like this: maps\mp\gametypes.&lt;br /&gt;
&lt;br /&gt;
Now, take dm.gsc from Path 1, and place it in MyModTest\maps\mp\&lt;br /&gt;
gametypes. Now open it in Programmers Notepad.&lt;br /&gt;
&lt;br /&gt;
With it open, copy &amp;amp; paste your function to the bottom of the file, after all the other functions.&lt;br /&gt;
Then, find the function onPlayerSpawn(), and at the bottom of the function type:&lt;br /&gt;
&lt;br /&gt;
 self thread _AntiCamp();&lt;br /&gt;
&lt;br /&gt;
What this does is &amp;quot;threads&amp;quot; our function. Threading means the function will be called &amp;amp; the&lt;br /&gt;
code will carry on without it’s return happily. If we don’t place the &amp;quot;thread&amp;quot; keyword there, the&lt;br /&gt;
script would stop and wait until _AntiCamp() has finished, and then continue.&lt;br /&gt;
&lt;br /&gt;
You can find the working [http://wiki.modsrepository.com/images/c/c7/Dm.gsc source code here].&lt;br /&gt;
To run a mod, start up cod4, then go to mods, select your mod and hit&lt;br /&gt;
launch.&lt;br /&gt;
&lt;br /&gt;
To test this mod out, make a new Free-For-All server, sit still for 30 seconds and watch your&lt;br /&gt;
anti camp script in action!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Well I hope you enjoyed the Handbook, and that I have inspired you to start scripting!&lt;br /&gt;
Thank you for reading.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Copyright (C) 2008 Tristan S. Strathearn.&amp;lt;br /&amp;gt;&lt;br /&gt;
All Rights Reserved&lt;br /&gt;
&lt;br /&gt;
Original title: [http://wiki.modsrepository.com/index.php/File:Quake.C.CoD.Handbook.color.pdf Quake-C CoD Handbook]&lt;br /&gt;
&lt;br /&gt;
[[Category:Call of Duty 4]]&lt;br /&gt;
[[Category:Modding]]&lt;br /&gt;
[[Category:Scripting]]&lt;/div&gt;</summary>
		<author><name>Zeroy</name></author>
	</entry>
	<entry>
		<id>https://wiki.zeroy.com/index.php?title=Call_of_Duty_4:_CoD_Script_Handbook&amp;diff=16211&amp;oldid=prev</id>
		<title>Zeroy: /* Operators */</title>
		<link rel="alternate" type="text/html" href="https://wiki.zeroy.com/index.php?title=Call_of_Duty_4:_CoD_Script_Handbook&amp;diff=16211&amp;oldid=prev"/>
		<updated>2011-09-08T13:35:53Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Operators&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 13:35, 8 September 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l109&quot;&gt;Line 109:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 109:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  number = 1;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  number = 1;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;numer &lt;/del&gt;= number + 2;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;number &lt;/ins&gt;= number + 2;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;In the above example, number is given the value 1, then, it’s set to equal itself, plus 2. Which&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;In the above example, number is given the value 1, then, it’s set to equal itself, plus 2. Which&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l127&quot;&gt;Line 127:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 127:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;At the end of this, number would now hold the value 25.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;At the end of this, number would now hold the value 25.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Chapter 2 – Functions &amp;amp; Loops=&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=Chapter 2 – Functions &amp;amp; Loops=&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Zeroy</name></author>
	</entry>
	<entry>
		<id>https://wiki.zeroy.com/index.php?title=Call_of_Duty_4:_CoD_Script_Handbook&amp;diff=16202&amp;oldid=prev</id>
		<title>CoDEmanX: Created page with &quot;=Preface=  Hi, I am Tristan. I am the creator of www.InfinityTutorials.com. I love programming, modding, gaming and best of all teaching others. That’s why I strive to create a...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.zeroy.com/index.php?title=Call_of_Duty_4:_CoD_Script_Handbook&amp;diff=16202&amp;oldid=prev"/>
		<updated>2011-09-08T10:12:29Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;=Preface=  Hi, I am Tristan. I am the creator of www.InfinityTutorials.com. I love programming, modding, gaming and best of all teaching others. That’s why I strive to create a...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=Preface=&lt;br /&gt;
&lt;br /&gt;
Hi, I am Tristan. I am the creator of www.InfinityTutorials.com. I love programming, modding,&lt;br /&gt;
gaming and best of all teaching others. That’s why I strive to create a trusted modding &amp;amp;&lt;br /&gt;
mapping community for everyone to join, gain experience &amp;amp; knowledge from.&lt;br /&gt;
&lt;br /&gt;
This book should help you to understand the fundamentals of CoD Script programming for Call of&lt;br /&gt;
Duty. By the end of it, you should feel comfortable with CoD Script, its layout, and how it works.&lt;br /&gt;
I hope you take away as much as you can from this book, and if you need help on any topic, or&lt;br /&gt;
more advanced topics, please visit the website, and we’ll be more than happy to help you.&lt;br /&gt;
&lt;br /&gt;
So get ready, get modding and enjoy!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Chapter 1 – Variables &amp;amp; Operators=&lt;br /&gt;
&lt;br /&gt;
==Welcome==&lt;br /&gt;
Welcome to the InfinityTutorials CoD Script Handbook. By reading this book from start to&lt;br /&gt;
finish, you’ll expect to be up and running making mod’s for CoD in no time! Scripting isn’t very&lt;br /&gt;
hard, and as long as you’re patient and you read closely, you’ll be a CoD Script master in a few&lt;br /&gt;
days with a little practice.&lt;br /&gt;
&lt;br /&gt;
Alright, to start your programming adventure, you’ll need a few tools. Even though these are&lt;br /&gt;
optional, they will make your programming experience a better &amp;amp; more organized one. The first&lt;br /&gt;
is a syntax highlighting text editor. I recommend [http://www.pnotepad.org/ Programmer&amp;#039;s Notepad].&lt;br /&gt;
Using a program like this, you can create &amp;amp; organize&lt;br /&gt;
projects, edit &amp;amp; create your scripts, and the best of all, it include syntax highlighting.&lt;br /&gt;
Syntax highlighting helps you to distinguish between variables, operators,&lt;br /&gt;
strings and keywords, which we will cover later in the book.&lt;br /&gt;
&lt;br /&gt;
The second tool, is a Zip compressor &amp;amp; extractor. Now, tools like Win-Zip and RAR will work,&lt;br /&gt;
but what happens if you don’t have them, and don’t want to spend the money buying them?&lt;br /&gt;
Well there is a great free alternative called [http://7-zip.org/ 7-Zip].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Variables==&lt;br /&gt;
Variables are your best friend. They can hold numbers, strings or even simple things such as&lt;br /&gt;
True and False. I don’t know of a single script that doesn’t contain at least 1 variable in it. This&lt;br /&gt;
is how important they are. Variables are much simpler in CoD Script than in similar languages like&lt;br /&gt;
C or C++. This also makes them a little less error prone, and easier to use. Here’s some&lt;br /&gt;
examples of variables and their properties:&lt;br /&gt;
&lt;br /&gt;
 my_number = 1;&lt;br /&gt;
&lt;br /&gt;
The variable my_number now holds the digit value 1. A practical use for this type of variable&lt;br /&gt;
would be, for example, number_of_lives which would hold the number of lives a player has.&lt;br /&gt;
&lt;br /&gt;
 my_double = 2.0;&lt;br /&gt;
&lt;br /&gt;
The variable my_double now holds the double digit value 2.0. You could use this to store a&lt;br /&gt;
players points for example.&lt;br /&gt;
&lt;br /&gt;
 my_message = &amp;quot;Hello World&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
The variable my_message now holds the string &amp;quot;Hello World&amp;quot;. You could use this type of&lt;br /&gt;
variable to hold a custom HUD element message, or a welcome message.&lt;br /&gt;
As you can see, the general format of a variable is:&lt;br /&gt;
&lt;br /&gt;
 name = value;&lt;br /&gt;
&lt;br /&gt;
Remember to always end your lines &amp;amp; declarations with semi colons &amp;quot;;&amp;quot; or you will receive weird&lt;br /&gt;
looking console error messages. In CoD Script the semi colon lets the compiler know that you’re&lt;br /&gt;
finished with one line and that you’re about to start another. However, there are cases where&lt;br /&gt;
you don’t end a line with a semi colon, this is with loops, if/else statements etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Operators==&lt;br /&gt;
&lt;br /&gt;
Operators are the little things that manipulate variables. You can use operators to add,&lt;br /&gt;
subtract, divide &amp;amp; multiply variables. They are extremely useful, and you’re bound to use them&lt;br /&gt;
in tons of scripts. Here are some examples of operators in use:&lt;br /&gt;
&lt;br /&gt;
 number_one = 1;&lt;br /&gt;
 number_two = 2;&lt;br /&gt;
 the_result = number_one + number_two;&lt;br /&gt;
&lt;br /&gt;
In this example, number_one and number_two are added together, and the result is placed in&lt;br /&gt;
the variable the_result. Thus, the variable the_result now holds the value 3.&lt;br /&gt;
&lt;br /&gt;
 number_one = 1;&lt;br /&gt;
 number_two = 2;&lt;br /&gt;
 the_result = number_two - number_one;&lt;br /&gt;
&lt;br /&gt;
In this example, number_one is subtracted from number_two, and the result is placed in the&lt;br /&gt;
variable the_result. Thus, the variable the_result now holds the value 1.&lt;br /&gt;
&lt;br /&gt;
 number_one = 1;&lt;br /&gt;
 number_two = 2;&lt;br /&gt;
 the_result = number_one * number_two;&lt;br /&gt;
&lt;br /&gt;
In this example, number_one and number_two are multiplied, and the result is placed in the&lt;br /&gt;
variable the_result. Thus, the variable the_result now holds the value 2.&lt;br /&gt;
&lt;br /&gt;
 number_one = 4;&lt;br /&gt;
 number_two = 2;&lt;br /&gt;
 the_result = number_one / number_two;&lt;br /&gt;
&lt;br /&gt;
In this example, number_one and number_two are divided, and the result is placed in the&lt;br /&gt;
variable the_result. Thus, the variable the_result now holds the value 2.&lt;br /&gt;
&lt;br /&gt;
 number_one = 4;&lt;br /&gt;
 number_one++;&lt;br /&gt;
&lt;br /&gt;
In this example, the ‘++’ simply means, increase the value by 1. You can also decrease a value&lt;br /&gt;
by 1 using ‘--‘, an example: number_one--;&lt;br /&gt;
&lt;br /&gt;
Now, what happens if you want to add 2, 3, 4 etc to a variable? Or want to multiply the&lt;br /&gt;
variable’s value by a certain number? Well, you can do it like this:&lt;br /&gt;
&lt;br /&gt;
 number = 1;&lt;br /&gt;
 numer = number + 2;&lt;br /&gt;
&lt;br /&gt;
In the above example, number is given the value 1, then, it’s set to equal itself, plus 2. Which&lt;br /&gt;
simply means, that in the end, number now equals 3.&lt;br /&gt;
A shorter way of doing this is:&lt;br /&gt;
&lt;br /&gt;
number = 1;&lt;br /&gt;
number += 2;&lt;br /&gt;
&lt;br /&gt;
This shorter version above achieves the same result as the previous example. This shortcut&lt;br /&gt;
works with all the operators. So for example, if you wanted to divide a variable by 2, then&lt;br /&gt;
multiply it by 5, this is how it would be set-up:&lt;br /&gt;
&lt;br /&gt;
 number = 10;&lt;br /&gt;
 number /= 2;&lt;br /&gt;
 number *= 5;&lt;br /&gt;
&lt;br /&gt;
At the end of this, number would now hold the value 25.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Chapter 2 – Functions &amp;amp; Loops=&lt;br /&gt;
&lt;br /&gt;
==Functions==&lt;br /&gt;
Functions are a vital part of any programming language, and CoD Script is no different. Functions&lt;br /&gt;
help organize your code and allow you to perform more advanced tasks.&lt;br /&gt;
So lets dive right in, here is an example of a small function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
my_function()&lt;br /&gt;
{&lt;br /&gt;
	return 5;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, functions start with a name to uniquely identify them. Their names cannot&lt;br /&gt;
contain anything except letters, numbers and underscores. Their names cannot start with a&lt;br /&gt;
number or contain spaces. They then continue with a left bracket &amp;amp; a right bracket. Then they&lt;br /&gt;
continue with a left open curly brace. After this brace you type the code you want executed&lt;br /&gt;
when your function is called. You then end the function with a right closed curly brace. One&lt;br /&gt;
thing to note is that CoD Script isn’t picky about how your code is laid out, so the following is&lt;br /&gt;
completely acceptable:&lt;br /&gt;
&lt;br /&gt;
 my_function(){ return 5; }&lt;br /&gt;
&lt;br /&gt;
Now, you may be asking, what does return do? Well, it’s a CoD Script keyword, and in this&lt;br /&gt;
example it returns the value 5. This value is sent to what ever function called it. So, a working&lt;br /&gt;
example would be:&lt;br /&gt;
&lt;br /&gt;
 the_number_five = my_function();&lt;br /&gt;
&lt;br /&gt;
In this example, the_number_five now contains the value 5 since my_function returned the&lt;br /&gt;
value 5 to it through the return keyword.&lt;br /&gt;
&lt;br /&gt;
An important thing to note is that not all functions need to return a value, these functions are&lt;br /&gt;
usually called Void functions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Functions can perform a wide verity of operations when called. One very special feature of&lt;br /&gt;
functions are Parameters. Parameters allow you to pass data into the function to work with.&lt;br /&gt;
&lt;br /&gt;
So lets take a look:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
add_five( my_arguement )&lt;br /&gt;
{&lt;br /&gt;
	temp = my_argument;&lt;br /&gt;
	temp += 5;&lt;br /&gt;
	return temp;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, you can place parameters between the two brackets next to the function&lt;br /&gt;
name. The parameter names follow the same rules of the function names. Lets see an example&lt;br /&gt;
of this function in use:&lt;br /&gt;
&lt;br /&gt;
 not_yet_ten = 5;&lt;br /&gt;
 this_is_ten = add_five( not_yet_ten );&lt;br /&gt;
&lt;br /&gt;
In this example, not_yet_ten is initialized to 5. Then we declare the variable this_is_ten and&lt;br /&gt;
make it equal the function add_five, and we pass not_yet_ten as an argument. Looking into&lt;br /&gt;
the function, we see it takes not_yet_ten and places it into the variable my_argument. Then,&lt;br /&gt;
a new variable temp is created, and it’s set to equal my_argument.. 5 is then added to temp&lt;br /&gt;
and then the function returns temp which in this case is now equals to 10 since the argument&lt;br /&gt;
passed into the function was equal to 5. At the end of this whole procedure, the variable&lt;br /&gt;
this_is_ten, equals, you guessed it, 10!&lt;br /&gt;
&lt;br /&gt;
Ok, after that long winded example, you should have a clear understanding of how parameters&lt;br /&gt;
&amp;amp; arguments work. Now, another point to note is that you can have more than one parameter&lt;br /&gt;
like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
add_numbers( number_one, number_two, number_three )&lt;br /&gt;
{&lt;br /&gt;
	return number_one + number_two + number_three;&lt;br /&gt;
}&lt;br /&gt;
the_result = add_numbers( 1, 2, 3 );&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All that’s needed to use more parameters is that you separate them with comma’s… simple. In&lt;br /&gt;
that example the final variable the_result would equal 6.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There’s one mistake a lot of people make though, and that’s using variables out side of their&lt;br /&gt;
scope. A scope is any section between the opening brace &amp;quot;{&amp;quot; and the closing brace &amp;quot;}&amp;quot;. Any&lt;br /&gt;
variables declared inside this scope can only be used inside this scope, and not anywhere&lt;br /&gt;
outside it. However, you can declare global variables which can be used out side of their&lt;br /&gt;
scopes. Here’s an example of a classic mistake:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function()&lt;br /&gt;
{&lt;br /&gt;
	local_var = 1;&lt;br /&gt;
}&lt;br /&gt;
result = local_var;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The example above would cause a compile error. This is because the variable local_var is&lt;br /&gt;
declared in the functions scope, and then used outside of it’s scope when assigning it to&lt;br /&gt;
another variable. However, if you do want to perform an action like this, you can declare a&lt;br /&gt;
global variable:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function()&lt;br /&gt;
{&lt;br /&gt;
	self.global_var = 5;&lt;br /&gt;
}&lt;br /&gt;
result = self.global_var;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In CoD Script the above is perfect code and will not generate any errors. In that example,&lt;br /&gt;
we used the keyword self which will be explained later.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Loops==&lt;br /&gt;
Ahh, loops, my favourite little function ?. Loops allow you to repeat a process a set amount of&lt;br /&gt;
times, or a limited amount of times. Loops can be used to monitor variables, print messages,&lt;br /&gt;
check players etc, anything that needs constant attention or repeating.&lt;br /&gt;
&lt;br /&gt;
There are two types of loops. The first we’ll look at is the while loop. Lets take a look at an&lt;br /&gt;
example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
number = 1;&lt;br /&gt;
while( number &amp;lt; 10 )&lt;br /&gt;
{&lt;br /&gt;
	number += 1;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, number is given the value 1. A while loop works by checking the argument,&lt;br /&gt;
which in this case is &amp;quot;number &amp;lt; 10&amp;quot; to see if its true or false. In this statement, it’s basically&lt;br /&gt;
saying, &amp;quot;Loop While Number Is Less, But Does Not Equal 10&amp;quot;. If your argument is true then the&lt;br /&gt;
loop performs the actions between the braces. When it gets to the last brace, it jumps back to&lt;br /&gt;
the top, and checks your statement again. If the statement is still true, then it will perform the&lt;br /&gt;
actions between the braces again. This process will continue until the statement is false which&lt;br /&gt;
is this example would be when the variable number equals ten.&lt;br /&gt;
&lt;br /&gt;
At the end of that loop, if we were to check the value of number we would see that it’s now&lt;br /&gt;
equal to 9.&lt;br /&gt;
&lt;br /&gt;
While loops can also be set to loop forever. This is done by simply by adding an argument that&lt;br /&gt;
will never return false, like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while( 1 )&lt;br /&gt;
{&lt;br /&gt;
	something here…&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
OR&lt;br /&gt;
&amp;lt;pre&amp;gt;while( true )&lt;br /&gt;
{&lt;br /&gt;
	something here…&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since 1 is 1, there is nothing to check, it will always be true. Even better, just put true in there.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here’s an example of an infinite while loop in use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while( true )&lt;br /&gt;
{&lt;br /&gt;
	IprintLnBold( &amp;quot;This is a looping message&amp;quot; );&lt;br /&gt;
	wait 5;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, the message &amp;quot;This is a looping message&amp;quot; will be displayed every 5 seconds&lt;br /&gt;
and will never end. If you’re unsure what some of those commands are, don’t worry, they will&lt;br /&gt;
be covered later.&lt;br /&gt;
&lt;br /&gt;
The second loop we will cover is the for loop. Here is a example of one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
result = 0;&lt;br /&gt;
for( number = 0; number &amp;lt; 10; number++ )&lt;br /&gt;
{&lt;br /&gt;
	result += number;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you may have noticed, the for loop takes 3 arguments, the first is a declaration of a variable&lt;br /&gt;
or counter variable, the second is what to check for (same as the true/false for the while loop),&lt;br /&gt;
the third is what to do to the counter variable when 1 loop is finished. You must separate the&lt;br /&gt;
arguments with semi-colons.&lt;br /&gt;
&lt;br /&gt;
In the example above, when the loop finishes (number = 10) the variable result will equal 45.&lt;br /&gt;
You can also make infinite for(;;) loops, but it’s a better choice to use a while(true) loop in that&lt;br /&gt;
case.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Chapter 3 – Arrays &amp;amp; Keywords=&lt;br /&gt;
&lt;br /&gt;
==Arrays==&lt;br /&gt;
Arrays are possibly the greatest type of variable alive in my eyes. Arrays are a special type of&lt;br /&gt;
variable that can hold multiple entries of data, like a list of names, maps, scores etc.&lt;br /&gt;
Alright, lets look at how to make an array:&lt;br /&gt;
&lt;br /&gt;
 my_array = [];&lt;br /&gt;
 my_array[0] = &amp;quot;Data 1&amp;quot;;&lt;br /&gt;
 my_array[1] = &amp;quot;Data 2&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
We start arrays with the variable name, but then, instead of assigning a value to it, we assign []&lt;br /&gt;
to it (Two opening &amp;amp; closing square brackets). This declaration tells the compiler that the&lt;br /&gt;
variable my_array is now an array. We then add data to the array by typing the variable name,&lt;br /&gt;
followed by a subscript. A subscript tells the compiler which part of the array to use/assign.&lt;br /&gt;
Array subscripts ALWAYS start with zero. This is one thing you must learn, as it’s the case in&lt;br /&gt;
many programming languages. Learn it now, and it will save you grief later on. When you add&lt;br /&gt;
more data to the array, you must increase the subscript by 1, and not 2 or a fraction etc. Here&lt;br /&gt;
is an example of an error:&lt;br /&gt;
&lt;br /&gt;
 my_broken_array = [];&lt;br /&gt;
 my_broken_array[1] = &amp;quot;Eeek&amp;quot;;&lt;br /&gt;
 my_broken_array[3] = &amp;quot;Yuck&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
In this example error, you see that we started the array subscript with 1, and then incremented&lt;br /&gt;
it with 2 instead of 1. This is bad, don’t try this at home.&lt;br /&gt;
Now, arrays work great with for loops. Here’s an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
awesome_array = [];&lt;br /&gt;
for( int = 0; int &amp;lt; 10; int++ )&lt;br /&gt;
{&lt;br /&gt;
	awesome_array[int] = int + 5;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, awesome_array is initialized, then we step into a for loop, where it sets the&lt;br /&gt;
first 9 subscripts of awesome_array to the value of int plus 5. So, if we had to check the value&lt;br /&gt;
of awesome_array[0] it would equal 5, awesome_array[1] would equal 6, awesome_array[2]&lt;br /&gt;
would equal 7 etc. This array would only go up to awesome_array[9], so trying to access any&lt;br /&gt;
subscript like 10 or higher would cause an error, or no error would be produced, but you’ll be&lt;br /&gt;
wondering why you’re script is acting funny.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Keywords==&lt;br /&gt;
&lt;br /&gt;
Alright, now that you know the essential basics of CoD Script, lets move on to some CoD&lt;br /&gt;
specific keywords.&lt;br /&gt;
&lt;br /&gt;
#wait = the time to wait in seconds&lt;br /&gt;
#self = an alias to the entity that called the script&lt;br /&gt;
#level = an alias to the level (the main script)&lt;br /&gt;
#waittill = wait until another script notify’s a keyword&lt;br /&gt;
#notify = used to trigger waittill&lt;br /&gt;
#endon = used to kill a function on a notify&lt;br /&gt;
#delete = delete an entity&lt;br /&gt;
#destroy = used to destroy structs &amp;amp; hud elements&lt;br /&gt;
&lt;br /&gt;
These are just some of the few keywords available. Below I will give you examples of each.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;wait&amp;#039;&amp;#039;&amp;#039; | this will loop every 5 seconds&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
while( 1 )&lt;br /&gt;
{&lt;br /&gt;
	wait 5;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;self&amp;#039;&amp;#039;&amp;#039; | the player who called this script will be killed after 5 seconds&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
wait 5;&lt;br /&gt;
self suicide();&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;level&amp;#039;&amp;#039;&amp;#039; | grab an array of all the players&lt;br /&gt;
 players = level.players;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;waittill&amp;#039;&amp;#039;&amp;#039; | this script will wait until &amp;quot;start_me&amp;quot; is notified&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
self waittill( &amp;quot;start_me&amp;quot; );&lt;br /&gt;
self suicide();&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;notify&amp;#039;&amp;#039;&amp;#039; | this will trigger any waittill’s with the same keyword, like the one above&lt;br /&gt;
 self notify( &amp;quot;start_me&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;endon&amp;#039;&amp;#039;&amp;#039; | this functions dies when &amp;quot;Kill_Me&amp;quot; is notified&lt;br /&gt;
 self endon( &amp;quot;Kill_Me&amp;quot; );&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;delete&amp;#039;&amp;#039;&amp;#039; | this will delete an entity&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
model = spawn( &amp;quot;script_model&amp;quot;, level.mapCenter );&lt;br /&gt;
model delete();&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;destroy&amp;#039;&amp;#039;&amp;#039; | this will destroy a hud elem&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
hud_elem = newHudElem();&lt;br /&gt;
hud_elem destroy();&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For a full list of all the available functions &amp;amp; keywords, you can go to [[Call_of_Duty_4:_Scripting_Reference|Scripting Reference (Wiki)]] or [http://www.zeroy.com/script/ InfinityWard Scripting index]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Chapter 4 – If/Else &amp;amp; Switch=&lt;br /&gt;
&lt;br /&gt;
==If/Else Statements==&lt;br /&gt;
&lt;br /&gt;
If/Else statements are conditional statements that are very, very useful. They can check the&lt;br /&gt;
state of a variable, make decisions based on data and many other cool things.&lt;br /&gt;
&lt;br /&gt;
If/Else statements are actually very easy to learn. So lets dive right in:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
my_num = 5;&lt;br /&gt;
if( my_num == 5 )&lt;br /&gt;
{&lt;br /&gt;
	self IprintLnBold( &amp;quot;The number is five!&amp;quot; );&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
	self IprintLnBold( &amp;quot;The number is NOT five!&amp;quot; );&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, we initialize a variable called my_num to 5. Then we use an IF()&lt;br /&gt;
statement to check if the number is equal to 5. If it is, we print the message &amp;quot;The number is&lt;br /&gt;
five!&amp;quot;, and if the number is not 5, we then display the message &amp;quot;The number is NOT five!&amp;quot;. If we&lt;br /&gt;
run the script like it is, we would see the first message, however, if we changed the variable&lt;br /&gt;
my_num at the top, to another number, the second message would be displayed because the&lt;br /&gt;
IF() check would see that my_num does not equal 5, and so it wall fall back to the else&lt;br /&gt;
statement.&lt;br /&gt;
&lt;br /&gt;
You can also do multiple levels of If/Else statements. These are If/Else If/Else statements. They&lt;br /&gt;
look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
num = 20;&lt;br /&gt;
if( num == 20 )&lt;br /&gt;
	self IprintLnBold( &amp;quot;Num equals 20&amp;quot; );&lt;br /&gt;
else if( num &amp;gt; 20 )&lt;br /&gt;
	self IprintLnBold( &amp;quot;Num is greater than 20&amp;quot; );&lt;br /&gt;
else&lt;br /&gt;
	self IprintLnBold( &amp;quot;Num is less than 20&amp;quot; );&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Firstly, if you are wondering why the Curly Brackets have all disappeared, its because there’s a&lt;br /&gt;
neat trick with If, Else If, Else, For Loops and While Loops, and that is… if your statement will&lt;br /&gt;
only contain 1 line of code to execute, you don’t need to put curly brackets in. However, if it is&lt;br /&gt;
more than one line of code to be executed, then you have to put the curly brackets in.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We see in the above example that the code will now check to see if num is equal, higher or&lt;br /&gt;
lower than 20.&lt;br /&gt;
&lt;br /&gt;
Another neat trick with If, Else If, Else, For Loops and While Loops is that if you’re variable is a&lt;br /&gt;
Boolean variable, meaning it’s either true or false, you can just type in the variable name to&lt;br /&gt;
check if it’s true, or put the bang character &amp;quot;!&amp;quot; in-front of the name to check if it’s false. See&lt;br /&gt;
below for an example.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
is_dead = false;&lt;br /&gt;
&lt;br /&gt;
if( is_dead )&lt;br /&gt;
	self IprintLnBold( &amp;quot;You are dead&amp;quot; );&lt;br /&gt;
else if( !is_dead )&lt;br /&gt;
	self IprintLnBold( &amp;quot;YAY! You’re not dead&amp;quot; );&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above example, the if( is_dead ) is checking if is_dead equals true, and the else if(&lt;br /&gt;
!is_dead ) is checking whether is_dead is false, and in this case it is, so the player would&lt;br /&gt;
receive the message &amp;quot;YAY! You’re not dead&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
In most programming languages, zero is considered false, and anything non-zero is true.&lt;br /&gt;
Some good operators for if/else statements are &amp;amp;&amp;amp; (Meaning AND), || (Meaning OR), ==&lt;br /&gt;
(Meaning EQUALS) and != (Meaning DOES NOT EQUAL)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Switch Blocks==&lt;br /&gt;
&lt;br /&gt;
Switch blocks are usually used when you need to do multiple checks where and If/Else If&lt;br /&gt;
statement would be too long, or messy to type out.&lt;br /&gt;
Lets take a look at a switch statement:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
my_number = 5;&lt;br /&gt;
switch( my_number )&lt;br /&gt;
{&lt;br /&gt;
	case 5:&lt;br /&gt;
		self IprintLnBold( &amp;quot;The number is 5&amp;quot; );&lt;br /&gt;
		break;&lt;br /&gt;
	case 6:&lt;br /&gt;
		self IprintLnBold( &amp;quot;The number is 6&amp;quot; );&lt;br /&gt;
		break;&lt;br /&gt;
	case 7:&lt;br /&gt;
		self IprintLnBold( &amp;quot;The number is 7&amp;quot; );&lt;br /&gt;
		break;&lt;br /&gt;
	default:&lt;br /&gt;
		self IprintLnBold( &amp;quot;The number is not 5, 6, or 7&amp;quot; );&lt;br /&gt;
		break;&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, don’t get too worried about it’s looks, yea, they look mean, but they can be a lot more&lt;br /&gt;
user friendly to use that huge blocks of If/Else statements.&lt;br /&gt;
&lt;br /&gt;
In the example, we start by declaring a variable my_number. We then start the switch block&lt;br /&gt;
with the keyword switch and then in brackets what variable we will be comparing. Then, inside&lt;br /&gt;
the curly brackets, we start the comparisons. We start one comparison with the keyword case&lt;br /&gt;
followed by what we want to compare it too, then end it with a colon. Under that, we place&lt;br /&gt;
the code we want executed if the variable equals the case, we then follow that with the&lt;br /&gt;
break; keyword to let the script know we’re done inside the switch block. At the very bottom,&lt;br /&gt;
we add a keyword called default followed by a colon. Under here we put the code that will be&lt;br /&gt;
executed if the variable doesn’t match any of the cases, again, followed by a break;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Chapter 5 – Lets start Scripting=&lt;br /&gt;
&lt;br /&gt;
==Let’s Start==&lt;br /&gt;
&lt;br /&gt;
All right, you feel like making a mod yet? Well I hope you do!&lt;br /&gt;
To follow along with this book, you need to install the mod tools for Call of Duty 4. These can&lt;br /&gt;
be found here [[Call_of_Duty_4:_needed|CoD4 Mod Tools]].&lt;br /&gt;
&lt;br /&gt;
With the mod tools installed, you’ll have access to all the raw files needed to start scripting a&lt;br /&gt;
mod for the game.&lt;br /&gt;
&lt;br /&gt;
If you’re mainly wanting to script for CoD4, you will only need to turn your attention to the&lt;br /&gt;
raw\maps folder. This is where all the raw scripts for Call of Duty 4 are located.&lt;br /&gt;
Whenever you see [root] below, its an alias for you Call of Duty 4 installation directory, which&lt;br /&gt;
is defaults too&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;C:\Program Files\Activision\Call of Duty 4 - Modern Warfare&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
OK, you’re ready to go!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example Anti Camp Script==&lt;br /&gt;
&lt;br /&gt;
For our first task, I’ll teach you how to script an anti camp function. From now on, I’ll refer to&lt;br /&gt;
the anti camp function as the ACF.&lt;br /&gt;
&lt;br /&gt;
So what is needed in an ACF? Well, we need to monitor the players to make sure they are not&lt;br /&gt;
sitting in one spot for too long. If they are sitting in one spot for too long, lets warn them that&lt;br /&gt;
they are camping &amp;amp; give them 10 seconds to move. If they don’t move within those 10 seconds,&lt;br /&gt;
we’ll punish them by killing them.&lt;br /&gt;
&lt;br /&gt;
So already we can see we need a couple of things:&lt;br /&gt;
&lt;br /&gt;
#A while loop that constantly monitors the player&lt;br /&gt;
#A function to somehow see how far a player has moved in a certain amount of time&lt;br /&gt;
#A function to punish the player&lt;br /&gt;
#A timer to check against.&lt;br /&gt;
&lt;br /&gt;
So, lets start with our variables:&lt;br /&gt;
&lt;br /&gt;
 my_camp_time = 0;&lt;br /&gt;
 have_i_been_warned = false;&lt;br /&gt;
 max_distance = 80;&lt;br /&gt;
 camp_time = 30;&lt;br /&gt;
&lt;br /&gt;
*my_camp_time will be the time in seconds the player has sat in one spot.&lt;br /&gt;
*have_i_been_warned will either be false if they haven’t been warned about camping, or true if they have been warned.&lt;br /&gt;
*max_distance is the distance the player needs to move within the camp_time limit to not be considered a camper.&lt;br /&gt;
&lt;br /&gt;
Now, we need to somehow check how far the player has moved on a constant basis. If they&lt;br /&gt;
haven’t moved further than the max_distance we need to increment the my_camp_time&lt;br /&gt;
variable. Then we need to check my_camp_time against camp_time, and if they are equal, we&lt;br /&gt;
need to warn the player &amp;amp; set the have_i_been_warned to true. We then give the player 10&lt;br /&gt;
seconds to move, and if he doesn’t. bam! We kill him.&lt;br /&gt;
&lt;br /&gt;
So, I head over to [[Call_of_Duty_4:_Scripting_Reference|Scripting Reference]] and look for a distance function, and what do&lt;br /&gt;
you know? They have one called distance() and distance2d(). The distance2d() looks like the&lt;br /&gt;
one we need. So lets set-up our while loop:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
level waittill( &amp;quot;prematch_over&amp;quot; );&lt;br /&gt;
self endon( &amp;quot;death&amp;quot; );&lt;br /&gt;
my_camp_time = 0;&lt;br /&gt;
have_i_been_warned = false;&lt;br /&gt;
max_distance = 80;&lt;br /&gt;
camp_time = 30;&lt;br /&gt;
&lt;br /&gt;
while( 1 )&lt;br /&gt;
{&lt;br /&gt;
	old_position = self.origin;&lt;br /&gt;
	wait 1;&lt;br /&gt;
&lt;br /&gt;
	new_position = self.origin;&lt;br /&gt;
	distance = distance2d( old_position, new_position );&lt;br /&gt;
&lt;br /&gt;
	if( distance &amp;lt; max_distance )&lt;br /&gt;
		my_camp_time++;&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		my_camp_time = 0;&lt;br /&gt;
		have_i_been_warned = false;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if( my_camp_time == camp_time &amp;amp;&amp;amp; !have_i_been_warned )&lt;br /&gt;
	{&lt;br /&gt;
		self IprintLnBold( &amp;quot;Please stop camping, 10 seconds to move&amp;quot; );&lt;br /&gt;
		have_i_been_warned = true;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if( my_camp_time == ( camp_time + 10 ) &amp;amp;&amp;amp; have_i_been_warned )&lt;br /&gt;
	{&lt;br /&gt;
		self IprintLnBold( &amp;quot;You will be killed for camping!&amp;quot;);&lt;br /&gt;
		wait 2;&lt;br /&gt;
		self suicide();&lt;br /&gt;
	}&lt;br /&gt;
}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, that alone won’t do anything, so, lets throw it in a custom function called _AntiCamp().&lt;br /&gt;
&lt;br /&gt;
Path 1:&lt;br /&gt;
OK, if you have the mod tools installed, go to [root]\raw\maps\mp\gametypes.&lt;br /&gt;
&lt;br /&gt;
Path 2:&lt;br /&gt;
Now open a new window, and navigate to [root]\mods. Inside that folder, make a new&lt;br /&gt;
folder called MyModTest. Inside that folder, build a folder structure like this: maps\mp\gametypes.&lt;br /&gt;
&lt;br /&gt;
Now, take dm.gsc from Path 1, and place it in MyModTest\maps\mp\&lt;br /&gt;
gametypes. Now open it in Programmers Notepad.&lt;br /&gt;
&lt;br /&gt;
With it open, copy &amp;amp; paste your function to the bottom of the file, after all the other functions.&lt;br /&gt;
Then, find the function onPlayerSpawn(), and at the bottom of the function type:&lt;br /&gt;
&lt;br /&gt;
 self thread _AntiCamp();&lt;br /&gt;
&lt;br /&gt;
What this does is &amp;quot;threads&amp;quot; our function. Threading means the function will be called &amp;amp; the&lt;br /&gt;
code will carry on without it’s return happily. If we don’t place the &amp;quot;thread&amp;quot; keyword there, the&lt;br /&gt;
script would stop and wait until _AntiCamp() has finished, and then continue.&lt;br /&gt;
&lt;br /&gt;
You can find the working [http://wiki.modsrepository.com/images/c/c7/Dm.gsc source code here].&lt;br /&gt;
To run a mod, start up cod4, then go to mods, select your mod and hit&lt;br /&gt;
launch.&lt;br /&gt;
&lt;br /&gt;
To test this mod out, make a new Free-For-All server, sit still for 30 seconds and watch your&lt;br /&gt;
anti camp script in action!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Well I hope you enjoyed the Handbook, and that I have inspired you to start scripting!&lt;br /&gt;
Thank you for reading.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Copyright (C) 2008 Tristan S. Strathearn.&amp;lt;br /&amp;gt;&lt;br /&gt;
All Rights Reserved&lt;br /&gt;
&lt;br /&gt;
Original title: [http://wiki.modsrepository.com/index.php/File:Quake.C.CoD.Handbook.color.pdf Quake-C CoD Handbook]&lt;br /&gt;
&lt;br /&gt;
[[Category:Call of Duty 4]]&lt;br /&gt;
[[Category:Modding]]&lt;br /&gt;
[[Category:Scripting]]&lt;/div&gt;</summary>
		<author><name>CoDEmanX</name></author>
	</entry>
</feed>