In the previous tutorial, I talked about starting your script in the yourmapname.gsc file, because it will be run when you map is run. However, we don't want to have to put everything we script inside that one .gsc file.
Though it is personal preference, the only things I keep inside the yourmapname.gsc file are very small scripts that are map-specific. Everything else I have in a separate .gsc file.
CREATING A GSC FILE
The easiest way to create a .gsc file is to copy an existing one and rename it. Though we can have .gsc files in other directories than (Bo3Root\usermaps\yourmapname\scripts\zm) to keep things simple we'll stay inside that directory.
Copy any .gsc there, such as yourmapname.gsc, and rename it to anything you like. In this example, I will call it my_external_script :
Next thing we will have to do is parse it in the yourmapname.zone. This will let launcher know that we'd like to use this file at some point when our map is run.
Let's open our yourmapname.zone (located in Bo3Root\usermaps\yourmapname\zone_source). It should look something like this:
To parse our script, we add the line:
to the bottom.
CALLING AN EXTERNAL FUNCTION
Now we have our script recognized by launcher, however this does not mean it will be run. We still need to call it from a script that will already be run, such yourmapname.gsc.
Before we get to that however, let's give this script something to do. Delete everything inside the .gsc (you can select all with ctrl + a) so we can start from scratch.
Let's add another simple print function like in the last tutorial.
this can be it for our external script. Now let's find a way to call it.
Go back to yourmapname.gsc and back into the function main(). It should look something like this, after the last tutorial:
Since we also want this function to be called after all players have connected, and then 10 seconds after that, we should call it below the wait(10); line.
the way you call an external function is basically the same as a normal function:
notice:
the name of the .gsc file is first
followed by two colons ::
followed by the name of the specific function within the .gsc file we want to call.
We can also thread it like we did with normal functions:
So, let's show it all in place:
#USING A SCRIPT
This is almost complete, however if we try to link now, launcher will throw an error like this:
this is because anytime you call a function from an external .gsc file, you must include that file in the #using's at the stop of the script that's calling it.
A #using looks like this:
notice:
the #using
the filepath (automatically assumes we are starting from the folder Bo3Root\usermaps\yourmapname OR Bo3Root\Share\Raw)
a #using does not include the .gsc at the end of the filename
uses a ;
Let's slap that bad boy in the preamble of yourmapname.gsc and we should be good to go!
Now in-game you should notice both the print function inside yourmapname.gsc and the print function in the my_external_script.gsc being called, at pretty much the same exact time.
#NAMESPACE'S
You may see in some scripts a #namespace. These basically designates a different name for the script than its actual filename. A #namespace goes in the preamble and looks like this:
it's as simple as putting #namespace followed by the name you want to give the script.
Note that:
You can only use one #namespace per script. (that wouldn't make sense anyway)
the #namespace only changes the name you use when calling the external function. When parsing the script in the mapname.zone or when putting the script as a #using, you must still use the actual filename.
Treyarch uses these all the time
USING TREYARCH'S CODE
There are a lot of great things you can do with the list of Engine Functions, however now that we know how to use external functions, we have access to so much more.
Treyarch has tons of scripts that we can look through and use the functions of in (Bo3Root\share\raw\scripts). For example, one function that I like to use often for EE's and such is the spawn_zombie function, located in (Bo3Root\share\raw\scripts\shared\ai\zombie_utility.gsc)
This lets me spawn a zombie at a specific struct, and I can use it from any .gsc like this:
I just have to remember to have the #using for the script at the top of my script:
and remember to make sure I'm calling the function by whatever #namespace Treyarch gave that script, not necessarily the filename (though in this case they are the same)