Scripting Basics

Basic Scripting

Here are a few basic guidelines/tips for understanding simple scripting in COD WAW. I have tried to address frequently asked questions and some basic things I have learned.

- Where to thread an initial function, call a gsc, or include a gsc

- Calling a function vs threading a function

- Self

- Arrays

- Passing variables and level variables

Where to thread an initial function or call a gsc

The following will be done from your nazi_zombie_mapname.gsc, in your mods/nazi_zombie_mapname/maps/ folder

- Thread an intial function

- Call another gsc

- Include another gsc

___________________________________

Thread an initial function

- find, in your nazi_zombie_mapname.gsc, the following:

        /*--------------------   FUNCTION CALLS - PRE _Load  ----------------------*/ 

and add your function thread like this:

        /*--------------------   FUNCTION CALLS - PRE _Load  ----------------------*/         thread YourFunction(); //thread your function here 

___________________________________

Call a gsc

- You can call another gsc by finding the following

    maps\_zombiemode::main(); 

and put maps\name_of_your_gsc::name_of_function_to_call(); under it like this:

    maps\_zombiemode::main();     maps\name_of_your_gsc::name_of_function_to_call(); //make sure name_of_function_to_call(), thread other functions in that gsc or your script could get stuck here 

___________________________________

Include a gsc

Note: This will include all functions from your gsc as if they are in this gsc, threadable/callable without the path to it in each line.

- Add this at the top of your nazi_zombie_mapname.gsc:

#include maps\name_of_your_gsc; //replace name_of_your_gsc with the name of your gsc 

Calling a function vs threading a function:

- If you call a function it will wait until the function you call is finished before moving on.

- If you thread a function it will continue immediately to the next line in the function you threaded it from.

Note: All Examples can be tested by threading the first function of each, in your nazi_zombie_mapname.gsc

___________________________________

Calling the function:

CallingFunction(){  flag_wait("all_players_connected"); //wait for players to connect  iprintlnbold("Call the function");  TheFunction();  iprintlnbold("Done with the function"); } TheFunction(){  wait(5);  iprintlnbold("I just waited 5 seconds, I will wait 5 more");  wait(5); } 

The above code will print "Call the function", wait 5 seconds, then print "I just waited 5 seconds, I will wait 5 more", then wait 5 seconds, and print "Done with the function"

___________________________________

Threading the function:

ThreadingFunction(){  flag_wait("all_players_connected"); //wait for players to connect  iprintlnbold("Thread the function");  thread TheFunction();  iprintlnbold("I am not waiting, the function is running now"); } TheFunction(){  wait(5);  iprintlnbold("I just waited 5 seconds, I will wait 5 more");  wait(5); } 

The above code will print "Call the function", then print "I am not waiting, the function is running now", then wait 5 seconds, then print "I just waited 5 seconds, I will wait 5 more", then wait 5 more seconds.

Self - what is it and what does it mean?

- When you thread/call a function on an entity you are telling that function that self means me, the entity

Note: in the following code you must have a script_brushmodel or script_model with the kvp> targetname : ent, in radiant

___________________________________

Threading a function on an entity:

ThreadingFunctionOnEntity(){  flag_wait("all_players_connected"); //wait for players to connect  ent = getent("ent", "targetname"); //gets your script model entity in radiant  ent.attribute1 = "testing";  ent thread SelfFunction(); } SelfFunction(){  iprintlnbold(self.attribute1); //will print "testing"  self MoveTo(self.origin + (0,0,100),3); //will move the ent up 100 in 3 seconds } 

Read the notes in the functions above to see what the code will do

Arrays- How can I use them with things that have a lot in common?

- Arrays are very useful when you have sets of entities with the same action, like doors, and shootable EE's

Note: the following example assumes you have sets of a trigger_damage and a script entity in radiant. Each trigger will have kvps> targetname : shoot, and target : "this will be different for each one". Each script entity will have it's triggers target as it's targetname: "this will be different for each one"

___________________________________

Collecting an array and threading a single function on each

ArrayFunction(){  myArray = getentarray("shoot","targetname"); //collects all the triggers with targetname shoot  for(i=0;i<myArray.size;i++){ //loops through the collection of triggers   myArray[i] thread SingleFunction(); //threads SingleFunction on each trigger  } } SingleFunction(){  self waittill("trigger", "targetname"); //Each trigger will wait to be shot  myEntity = getent(self.target, "targetname"); //self.target is used to get it's specific script entity  myEntity delete(); //deletes the script entity  self delete(); //deletes itself } 

Read the notes in the functions above to see what the code will do

Passing variables and level variables

- Passing variables can be useful in many situations. The example below simply passes the size of the array (the number of entities with that targetname). You can also pass entities (not shown). Passing variables and entities is a great way to make one function serve the purpose, where many would be used/needed otherwise. Level variables are a way to keep track of things between functions, even after a function has ran.

Note - Use the entities and triggers from the Array example above.

___________________________________

Passing variables and level variables

PassAndLevelFunction(){  level.totalThings = 0; //initialize the level variable once  myArray = getentarray("shoot","targetname");  for(i=0;i<myArray.size;i++){   myArray[i] thread VariablesFunction(myArray.size); //pass the total variable  } } VariablesFunction(size){  self waittill("trigger", "targetname"); //Each trigger will wait to be shot  myEntity = getent(self.target, "targetname");  level.totalThings++; //increments totalThings by 1  iprintlnbold("You found " + level.totalThings + " out of " + size + " things"); //You found 1 out of 3 things, numbers based on how many you found so far and how many you put in radiant  myEntity delete();  self delete(); } 

Read the notes in the functions above to see what the code will do