### For Loop Example Source: https://wiki.modme.co/wiki/black_ops_3/guides/Scripting-guide.html This example demonstrates a for loop that iterates 10 times, printing the value of 'i' and waiting for 2 seconds between iterations. ```gsc for( i=0; i<10; i++ ) // this is not an infinite loop (it has a condition that is not always true) { iprintlnbold(i); // show i on screen wait(2); // wait 2 seconds so the player can actually read the printed statement } ``` -------------------------------- ### String Indexed Array Example Source: https://wiki.modme.co/wiki/black_ops_3/guides/Scripting-guide.html An example demonstrating how to create and assign values to a string-indexed array. ```gsc powerups = []; // anytime we are "forcing" an array we need to initialize the variable as an array powerups[ "full_ammo" ] = "Max ammo"; powerups[ "nuke" ] = "Nuke"; ``` -------------------------------- ### Foreach Loop Example (Players) Source: https://wiki.modme.co/wiki/black_ops_3/guides/Scripting-guide.html This example uses a foreach loop to iterate through all players and deal damage to each one. ```gsc foreach (player in GetPlayers()) // GetPlayers() returns an array of the players, so it is the array that is input and "player" is used to reference each "item" (player) in the array { player DoDamage(10, player.origin); // this loop deals 10 damage to each player } ``` -------------------------------- ### Infinite While Loop Example Source: https://wiki.modme.co/wiki/black_ops_3/guides/Scripting-guide.html This example shows an infinite while loop that continuously prints the loop counter 'i' and increments it, with a short wait time. ```gsc i = 0; while(1) // this is an infinite loop { iprintlnbold(i); i++; wait(0.05); // this is the fastest you can possibly execute a loop in GSC } ``` -------------------------------- ### Base Attachment Unique Asset Example Source: https://wiki.modme.co/wiki/black_ops_3/guides/Setting-Up-Weapon-Attachments.html An example of a base Attachment Unique asset structure. ```plaintext attachmentUnique au_weaponname_none { } ``` -------------------------------- ### Attachment Assets - GDT Example Source: https://wiki.modme.co/wiki/black_ops_3/guides/Setting-Up-Weapon-Attachments.html Example of the 'weaponattachments' GDT structure. ```plaintext {F23840} ``` -------------------------------- ### Attachment Assets - KVK 99m Extended Mags Example Source: https://wiki.modme.co/wiki/black_ops_3/guides/Setting-Up-Weapon-Attachments.html Example of deriving the Extended Mags attachment for the KVK 99m. ```plaintext extclip_an94 ``` -------------------------------- ### Setting up the hud Source: https://wiki.modme.co/wiki/black_ops_3/lua_%28lui%29/Your-First-Menu-%28Hud%29.html Configuring the hud to cover the screen and play an opening sound. ```lua function LUI.createMenu.T7Hud_zm_factory(Instance) local Hud = CoD.Menu.NewForUIEditor("T7Hud_zm_factory") -- Set the current sound profile Hud.soundSet = "HUD" -- Set the owner of our hud to the root 'instance' Hud:setOwner(Instance) -- Set the anchors (Left: True, Right: True, LeftMargin: 0, RightMargin: 0) Hud:setLeftRight(true, true, 0, 0) -- Set the anchors (Top: True, Bottom: True, TopMargin: 0, BottomMargin: 0) Hud:setTopBottom(true, true, 0, 0) -- Play the opening sound (From 'HUD' profile) Hud:playSound("menu_open", Instance) return Hud end ``` -------------------------------- ### Multiple Attachments in One File Example Source: https://wiki.modme.co/wiki/black_ops_3/guides/Setting-Up-Weapon-Attachments.html Example demonstrating how multiple attachments can be defined within a single file, deriving from the first attachment. ```plaintext attachmentUnique au_kvk99m_extclip { // ... other properties } ``` -------------------------------- ### Example Function Definition Source: https://wiki.modme.co/wiki/black_ops_3/guides/Scripting-guide.html A simple example function that prints text and uses a local variable. ```gsc function example_function() { iprintlnbold("This is an example function"); teddys_to_shoot = 3; iprintlnbold( "You have " + teddys_to_shoot + " Teddy Bears to Shoot" ); } ``` -------------------------------- ### Setting up the control Source: https://wiki.modme.co/wiki/black_ops_3/lua_%28lui%29/Your-First-Custom-Control-%28Widget%29.html This code snippet shows how to set up a custom control by inheriting from the base UIElement. ```lua CoD.TestControl = InheritFrom(LUI.UIElement) ``` -------------------------------- ### Conditional While Loop Example Source: https://wiki.modme.co/wiki/black_ops_3/guides/Scripting-guide.html This example demonstrates a while loop that checks if a player is currently sliding and prints a message if they are. ```gsc players = GetPlayers(); player = players[0]; while( player isOnSlide() ) { iprintlnbold( "The player is sliding" ); wait(0.05); } ``` -------------------------------- ### Integer Indexed Array Example Source: https://wiki.modme.co/wiki/black_ops_3/guides/Scripting-guide.html An example of how to access elements in an integer-indexed array using the GetEntArray function. ```gsc teddys_to_shoot = GetEntArray( "shootable_teddy", "targetname" ); teddys_to_shoot[0]; // This is the first element in the array teddys_to_shoot teddys_to_shoot[1]; // This is the second teddy in the array ``` -------------------------------- ### Alias Line Example Source: https://wiki.modme.co/wiki/black_ops_3/intermediate/Setting-Up-Loadscreen-Videos.html Example alias line for adding the required line for the video. It is recommended to copy this into an Excel Sheet for easier editing. ```csv Name,FileSpec,Template,Loadspec,Secondary,VolumeGroup,VolMin,VolMax,DistMin,DistMaxDry,DistMaxWet,DryMaxCurve,WetMaxCurve,DryMinCurve,WetMinCurve,LimitCount,LimitType,EntityLimitCount,EntityLimitType,PitchMin,PitchMax,PriorityMin,PriorityMax,PriorityThresholdMin,PriorityThresholdMax,PanType,Storage,Looping,RandomizeType,Probability,StartDelay,ReverbSend,Duck,Pan,CenterSend,EnvelopMin,EnvelopMax,EnvelopPercent,OcclusionLevel,IsBig,DistanceLpf,FluxType,FluxTime,Subtitle,Doppler,dopplerscale,Futz,ContextType,ContextValue,contexttype1,contextvalue1,contexttype2,contextvalue2,Compression,Timescale,IsMusic,FadeIn,FadeOut,Pauseable,StopOnEntDeath,Bus,DuckGroup,iscinematic bik_zm_testmap_load,tst\testsound.wav,CIN_C_MOD,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0,,,,,,,,,,,,,,,,,,,,,,,,,,,yes,,,, ``` -------------------------------- ### Example GSC function for zone initialization Source: https://wiki.modme.co/wiki/black_ops_3/basics/Setting-up-zones.html This is an example of how the usermap gsc function might look before and after adding zone initialization. ```gsc function usermap_test_zone_init() { level flag::init( "always_on" ); level flag::set( "always_on" ); } ``` ```gsc function usermap_test_zone_init() { zm_zonemgr::add_adjacent_zone( "start_zone", "zone_1", "open_zone_1" ); } ``` -------------------------------- ### Instantiating the control Source: https://wiki.modme.co/wiki/black_ops_3/lua_%28lui%29/Your-First-Custom-Control-%28Widget%29.html This code snippet shows how to create an instance of the custom control. ```lua local Control = CoD.TestControl.new(HudRef, InstanceRef) ``` -------------------------------- ### Creating the hud itself Source: https://wiki.modme.co/wiki/black_ops_3/lua_%28lui%29/Your-First-Menu-%28Hud%29.html Allocating a new menu instance for the hud. ```lua function LUI.createMenu.T7Hud_zm_factory(Instance) local Hud = CoD.Menu.NewForUIEditor("T7Hud_zm_factory") return Hud end ``` -------------------------------- ### Custom Notify Example Source: https://wiki.modme.co/wiki/black_ops_3/guides/Scripting-guide.html An example of how to send a custom notify to a player entity to trigger an event, such as showing blood splatter on screen. ```gsc player notify( "splatter_blood_onscreen" ); ``` -------------------------------- ### The starting function Source: https://wiki.modme.co/wiki/black_ops_3/lua_%28lui%29/Your-First-Menu-%28Hud%29.html The base function to register a menu under the LUI.createMenu namespace. ```lua function LUI.createMenu.T7Hud_zm_factory(Instance) end ``` -------------------------------- ### Foreach Loop Example (Teddies) Source: https://wiki.modme.co/wiki/black_ops_3/guides/Scripting-guide.html This example uses a foreach loop to iterate through an array of entities with the targetname 'shootable_teddy' and hide each one. ```gsc teddies = GetEntArray("shootable_teddy", "targetname"); foreach (teddy in teddies) // teddies is the input array and teddy is used to reference each item in the array { teddy Hide(); // hides each teddy in the array } ``` -------------------------------- ### Sound Configuration Source: https://wiki.modme.co/wiki/black_ops_3/intermediate/Setting-Up-Loadscreen-Videos.html Add this line to the zm_mod config file at the bottom. ```plaintext sound,zm_mod ``` -------------------------------- ### Do While Loop Example Source: https://wiki.modme.co/wiki/black_ops_3/guides/Scripting-guide.html This example demonstrates a do while loop that damages a player as long as they have more than 30 health and are touching a specific trigger. The code block executes at least once. ```gsc players = GetPlayers(); player = players[0]; do { player DoDamage(10, player.origin); } while(player.health > 30 && player IsTouching(damage_trig)); // damages the player while they are above 30 health and touching the trigger, executes at least once ``` -------------------------------- ### Global Variable Declaration Source: https://wiki.modme.co/wiki/black_ops_3/guides/Scripting-guide.html Example of how to declare a global variable in GSC. ```gsc level.teddys_to_shoot = 3; ``` -------------------------------- ### Requiring a script in Standard Lua Source: https://wiki.modme.co/wiki/black_ops_3/lua_%28lui%29/Introduction.html Demonstrates how to require a Lua script using standard Lua syntax. ```lua -- Use the file in the folder 'a' named 'b.lua' require("a/b.lua") ``` -------------------------------- ### Local Variable Declaration Source: https://wiki.modme.co/wiki/black_ops_3/guides/Scripting-guide.html Example of how to declare a local variable in GSC. ```gsc teddys_to_shoot = 3; ``` -------------------------------- ### If Statement Example Source: https://wiki.modme.co/wiki/black_ops_3/guides/Scripting-guide.html Demonstrates the use of if, else if statements to check a player's average grade. ```gsc function main() { players = getplayers(); // getplayers is an engine function, see bo3_scriptapifunctions.htm host_player = players[0]; // players is an array, for now know that players[0] is the host host_player take_an_average_of_3( 80, 90, 100 ); iprintlnbold( "The Host's Average Exam Grade Is: "+host_player.average_of_nums ); if( host_player.average_of_nums >= 70 ) { iprintlnbold( "The host has a passing grade" ); } else if( host_player.average_of_nums < 70 ) { iprintlnbold( "The host has a failing grade." ); } } function take_an_average_of_3( num1, num2, num3 ) { sum_of_nums = num1 + num2 + num3; average_of_nums = sum_of_nums/3; self.average_of_nums = average_of_nums; } ``` -------------------------------- ### Example Perk Inclusions Source: https://wiki.modme.co/wiki/black_ops_3/basics/Setting-Up-The-Der-Wunderfizz.html Example of how to include all 13 official perks in the Der Wunderfizz rotation. ```gsc zm_perk_random::include_perk_in_random_rotation( "specialty_quickrevive" ); zm_perk_random::include_perk_in_random_rotation( "specialty_armorvest" ); zm_perk_random::include_perk_in_random_rotation( "specialty_doubletap2" ); zm_perk_random::include_perk_in_random_rotation( "specialty_fastreload" ); zm_perk_random::include_perk_in_random_rotation( "specialty_deadshot" ); zm_perk_random::include_perk_in_random_rotation( "specialty_phdflopper" ); zm_perk_random::include_perk_in_random_rotation( "specialty_staminup" ); zm_perk_random::include_perk_in_random_rotation( "specialty_additionalprimaryweapon" ); zm_perk_random::include_perk_in_random_rotation( "specialty_tombstone" ); zm_perk_random::include_perk_in_random_rotation( "specialty_whoswho" ); zm_perk_random::include_perk_in_random_rotation( "specialty_electriccherry" ); zm_perk_random::include_perk_in_random_rotation( "specialty_vultureaid" ); zm_perk_random::include_perk_in_random_rotation( "specialty_widowswine" ); ``` -------------------------------- ### Endon and Waittill Example Source: https://wiki.modme.co/wiki/black_ops_3/guides/Scripting-guide.html Demonstrates the use of 'endon' to stop a function when a specific notify is received and 'waittill' to wait for a notification before proceeding. This example shows how to handle blood splatter notifications while ensuring the function exits when the player dies. ```gsc function blood_splatter() { self endon( "death" ); while(1) { self waittill( "splatter_blood_on_screen" ); iprintlnbold( "splatter blood now" ); } } ``` -------------------------------- ### Treyarch/Nate's Style Source: https://wiki.modme.co/wiki/black_ops_3/guides/Scripting-guide.html An example of a coding style similar to Treyarch's, featuring specific indentation and brace placement. ```gsc function main() { grades = GetStudentGrades(); // This doesnt exist but lets pretend we got the array of grades somehow failed = did_a_student_fail( grades ); // lets call another function and return a true or false from it if( failed ) iprintlnbold( "At least one student failed" ); else iprintlnbold( "No students failed" ); } function did_a_student_fail( grades ) { for( i=0; i