UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

Simple Scripting Basics [6-5-15 fixed typos]

broken avatar :(
Created 10 years ago
by MakeCents
0 Members and 1 Guest are viewing this topic.
5,082 views
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 14 September 2013
Last active: 4 years ago
Posts
1,895
Respect
Forum Rank
Zombie Destroyer
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
Personal Quote
BE ORIGINAL
Signature
×
MakeCents's Groups
Community Mapper Has released one or more maps to the UGX-Mods community which have been added to the UGX Map Manager.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
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


DISCLAIMER at the bottom


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:
Code Snippet
Plaintext
        /*--------------------
FUNCTION CALLS - PRE _Load
----------------------*/
and add your function thread like this:
Code Snippet
Plaintext
        /*--------------------
FUNCTION CALLS - PRE _Load
----------------------*/
        thread YourFunction(); //thread your function here
___________________________________
Call a gsc
- You can call another gsc by finding the following
Code Snippet
Plaintext
    maps\_zombiemode::main();
and put maps\name_of_your_gsc::name_of_function_to_call(); under it like this:
Code Snippet
Plaintext
    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:
Code Snippet
Plaintext
#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:
Code Snippet
Plaintext
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:
Code Snippet
Plaintext
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:
Code Snippet
Plaintext
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
Code Snippet
Plaintext
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
Code Snippet
Plaintext
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


DISCLAIMER

I am not a programmer by profession. These are simple guidelines I follow from my experiences writing scripts for this game, for fun. There are no practical uses for the functions above other than examples. Corrections are welcome.
Last Edit: June 05, 2015, 03:51:21 pm by MakeCents
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 2 April 2014
Last active: 2 years ago
Posts
481
Respect
Forum Rank
Perk Hacker
Primary Group
Donator ♥
My Groups
More
My Contact & Social Links
More
Personal Quote
If it's not perfect, you'll never see it.
Signature
Learn by doing, not copy and pasting.

Enjoy my 2015 contest map, a simple map with bo1-bo2 features
http://ugx-mods.com/forum/index.php?topic=14968.msg149200#
×
Centric's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Centric's Contact & Social Linkscentricccentric_
Dang this saved me from a couple questions already, thanks for making it!
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 14 September 2013
Last active: 4 years ago
Posts
1,895
Respect
Forum Rank
Zombie Destroyer
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
Personal Quote
BE ORIGINAL
×
MakeCents's Groups
Community Mapper Has released one or more maps to the UGX-Mods community which have been added to the UGX Map Manager.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
Dang this saved me from a couple questions already, thanks for making it!

Cool, I'm glad it helped.

 
Loading ...