Garry's Mod Starfall Guide/Tutorial
Starfall Guide Order Tutorial
This tutorial provides an introduction to Starfall and covers important concepts and features.
Getting Started with Starfall
- Starfall is a tool that allows you to create scripts for Garry's Mod.
- The Starfall processor is the main component you'll be working with. It functions similarly to E2 (Expression 2).
- You can assign a name to your chip, which will appear as the author of the script.
- There are directives in the Starfall documentation that allow you to specify whether a file should run on the server, client, or both.
Server vs Client
- The server handles everything happening in the game environment, such as physics and prop interactions.
- The client is responsible for certain actions that can only be performed on the client side.
- Different colors in the code indicate whether it can be executed on the server, client, or both.
Basic Functions
- The
printfunction is used to display messages. Its color changes depending on where it is executed (server or client).
- The Starfall documentation serves as a library of functions and contains all the necessary information for scripting.
Data Types
Vectors
- Vectors represent world coordinates and consist of x, y, and z values.
Angles
- Angles are used to represent yaw, pitch, and roll values.
Strings
- Strings are used for text-based data.
Colors
- Colors are represented by red, green, and blue values.
Booleans
- Booleans represent true or false statements.
Nil
- Nil represents non-existent or empty values.
Variables
- Variables can be assigned using the equals sign (=).
- Proper capitalization is important when referencing variables.
Conclusion
This tutorial provides an introduction to Starfall and covers important concepts such as the Starfall processor, server vs client execution, basic functions, data types, and variables. It serves as a starting point for those interested in learning how to script with Starfall in Garry's Mod.
Variables and Scope
This section discusses the concept of variables and scope in Lua scripting.
Local Variables
- Local variables are generally faster to access than global variables.
- It is good practice to make all variables local, even in simple scripts.
- Making variables local helps improve performance and maintain code organization.
Global Variables
- Global variables can be accessed from anywhere in the script.
- If a variable needs to be used across different parts of the script, it can be declared as a global variable.
Creating Holograms
This section explains how to create holograms using the Starfall scripting language.
Using the Holograms Helper
- The
holograms.createfunction is used to create holograms.
- Parameters for creating a hologram include vectors, angles, strings, and models.
Setting Position and Angle
- The position of an entity can be obtained using
entity.getPosition().
- Angles can be set according to requirements.
- Models can be selected for the hologram.
Scaling Holograms
- Holograms can be scaled using vector values.
- Scaling allows for creative manipulation of hologram appearance.
If Statements
This section covers if statements and boolean logic in Lua scripting.
If Statements
- If statements are used for conditional execution of code blocks.
- An if statement checks whether a condition is true or false before executing the associated code block.
- Example:
if a == true then ... end
Boolean Logic
- Boolean operators such as
==(equal),~=`` (not equal),<(less than),>` (greater than), etc., are used in if statements.
- Boolean expressions can be combined using logical operators like
and,or, andnot.
String Manipulation
This section explores string manipulation techniques in Lua scripting.
Concatenating Strings
- Strings can be concatenated using the
..operator.
- Example:
"Hello" .. "World"results in the string "HelloWorld".
Tables
This section introduces tables, which are used to store collections of data in Lua scripting.
Table Basics
- Tables are denoted by square brackets
[ ].
- Each value in a table is associated with a key.
- Keys and values are separated by an equal sign (
=).
- Values within a table are separated by commas.
Accessing Table Values
- Individual values within a table can be accessed using their respective keys.
These notes provide a summary of the main topics covered in the transcript, focusing on variables and scope, creating holograms, if statements, string manipulation, and tables.
New Section
In this section, the speaker discusses the importance of understanding a specific function and introduces the concept of looping over a table using for loops.
Understanding Functions and Looping Over Tables
- The speaker emphasizes the importance of understanding functions.
- For loops can be used to loop over a table's keys and values.
- The pairs function returns an iterator function for a for loop that retrieves values from a specified table in an arbitrary order.
- A demonstration is given on how to use pairs to iterate through all players in a game.
- For loops are useful for iterating over keys, values, or both in a table.
- An example is provided where the owner of each player is checked, and if it matches the current player (me), it prints "me".
- If the owner does not match the current player, it prints "friend" or any other desired output.
- Another way to use for loops is demonstrated by initializing a variable "i" and looping until it reaches a certain value.
New Section
This section focuses on explaining how to determine the length of tables and strings using Lua.
Determining Length with Tables and Strings
- The
#operator can be used to determine the length of tables or strings.
- Examples are given to illustrate how
#works with tables and strings.
- The speaker demonstrates how to use
#to create multiple objects based on the length of a table or string.
New Section
This section explores creating and accessing individual elements within a table using numerical indices.
Creating and Accessing Elements in Tables
- The speaker explains how to create individual elements within a table using numerical indices.
- A demonstration is given where each number creates its own "hollow" element in the table.
- By accessing specific indices, individual elements can be modified or accessed.
- Examples are provided to showcase different ways of accessing specific elements within the table.
New Section
This section introduces working with tables in Wiremod and demonstrates some possibilities.
Working with Tables in Wiremod
- The speaker mentions that Wiremod users can utilize tables for various purposes.
- Examples are given on adjusting inputs, outputs, and calling direct values within Wiremod.
- A demonstration is planned but not executed due to Wiremod not being enabled.
New Section
This section discusses while loops and their continuous execution until a condition is met.
Understanding While Loops
- While loops continuously run as long as a specified condition remains true.
- A demonstration is given where "e" is printed continuously while the loop condition is true.
Understanding While Loops
In this section, the speaker explains the concept of while loops and their behavior.
While Loops
- While loops are used to create a loop that runs indefinitely until a certain condition is met.
- The loop will continue running as long as the specified condition remains true.
- It is important to be cautious when using while loops, as they can lead to infinite loops if not properly controlled.
Using Break Statement in While Loops
This section discusses how to use the break statement to stop a while loop before its natural termination.
Breaking out of a While Loop
- The break statement can be used within a while loop to prematurely exit the loop.
- When encountering the break statement, the program will immediately exit the loop and continue with the next line of code outside of the loop.
- This can be useful when you want to stop a while loop based on a specific condition.
Introduction to Hooks
The speaker introduces hooks and explains their purpose in programming.
What are Hooks?
- Hooks are events that occur during program execution.
- They allow developers to respond or perform actions based on specific events or triggers.
- Hooks provide flexibility and customization options in programming.
Exploring Available Hooks
This section explores different hooks available for use in programming.
Available Hooks
- There are various hooks provided by libraries for developers to utilize.
- Each hook serves a specific purpose and can be used for different functionalities within a program.
Implementing Hooks
This section explains how to implement hooks in a program.
Using Hooks
- To use a hook, you need to call the corresponding function provided by the library.
- The hook function takes parameters and allows customization based on specific requirements.
- Hooks can be used to add, remove, or modify certain effects or behaviors within a program.
Returning Values with Hooks
This section discusses how hooks can return values in programming.
Returning Values with Hooks
- Some hooks allow developers to return values as part of their functionality.
- These returned values can be utilized for further processing or decision-making within the program.
- Returning values with hooks provides additional flexibility and control over program execution.
The transcript is already in English.
New Section
In this section, the speaker discusses creating a table and modifying its properties.
Creating a Table
- To return a table containing specific information, the speaker suggests creating a table.
- The speaker mentions using names such as "origin" and "c far far clip plane" for the table's properties.
- Modifying the value of "c far far clip plane" to 1000 changes the distance of the secret plane.
Custom Functions
- The speaker introduces custom functions that can be created in Lua scripting.
- Functions can be defined as local or global.
- Parameters can be added to functions, allowing for customization based on input values.
- Custom functions can be used to create libraries or simplify script development.
Including Libraries
- Libraries can be included in scripts to provide additional functionality.
- The
includedirective is used to include a file containing library code.
New Section
This section focuses on running client-side code and utilizing various features available on the client.
Running Code on the Client
- On the server, code executed by an individual player only affects that player.
- The
playerkeyword refers to the local player when used on the client.
- Using conditional statements with
playerallows for executing code exclusively for oneself.
Client-Side Features
- The speaker mentions several client-side features like loading sounds from URLs and rendering custom HUD elements.
- Rendering capabilities include both 2D and 3D elements, providing creative possibilities.
New Section
This section covers loading sounds from URLs and understanding flags associated with sound loading.
Loading Sounds from URLs
- The
base.load_url()function is used to load sounds from specified URLs.
- Example:
base.load_url("path/to/sound", flags)
- Flags can be used to customize sound loading behavior.
Timestamps were not provided for the remaining part of the transcript.
Understanding Sound and Error Handling
In this section, the speaker discusses how to work with sound objects and handle errors in a script.
Working with Sound Objects
- The
soundobject is used to play sounds in the script.
- To play a sound, use the
sound.play()function.
- Example:
sound.play()
Error Handling
- When an error occurs, three arguments are passed: the sound object, error number, and name.
- To handle errors related to sound, focus on retrieving the sound object only.
- Example:
sound = args
Playing a Specified Music
- Use the
types[Music]function to start playing a specified music.
- Example:
sound.play(types[Music])
Verifying Sound Playback
- After implementing the code for playing music, verify if it plays correctly.
- Adjust the position of the sound using the
get_position()function if needed.
Drawing on Screen Using Draw HUD
This section covers drawing elements on the screen using Draw HUD.
Implementing Draw HUD Functionality
- Use the
draw_hudhook to draw elements on the screen.
- Search for "draw_hud" or "frame requested to be drawn on hud" in hooks library.
- The
draw_hudfunction does not require any parameters.
Rendering Elements on Screen
- To render elements on screen, utilize functions from the render library.
Drawing Rectangles
- Use the
render.draw_rect()function to draw rectangles on screen.
- Specify coordinates (x,y), width, height, and color for each rectangle.
- Color values need to be defined above their usage due to limitations in variable usage.
- Example:
render.draw_rect(30, 20, 100, 100, color)
Exploring Client-Side Capabilities
This section explores the capabilities of the client-side scripting.
Client-Side Scripting
- The client-side scripting allows bringing various elements into reality.
- Import models using mesh functions and create materials and lights.
- Create screen visualizers or holo visualizers purely on the client-side.
Understanding Net Messages for Server-Client Communication
This section explains net messages and their role in server-client communication.
Introduction to Net Messages
- Net messages are used for communication between the server and the client.
- They allow both the server and client to send data to each other.
Sending Data from Server to Client
- Use
net.start()function to start a net message.
- Specify a name for the net message (e.g., "holo") and include any necessary entities or data.
- Example:
net.start("holo", entity)
Receiving Data on Client Side
- Use
net.receivefunction on the client side to receive net messages sent by the server.
New Section
In this section, the speaker discusses the usage of light in a program and demonstrates how to create and draw a light using a library.
Creating and Drawing a Light
- The need for using light depends on the specific requirements of the program .
- To create a light, the speaker navigates to the light library .
- The size, brightness, and color of the light can be adjusted .
- The light is drawn using a hook function .
New Section
In this section, the speaker explains the concept of "tick" and provides additional information about drawing lights.
Understanding Tick Function
- The "tick" function is called on each game tick and is commonly used on the client side .
- It is important to include necessary hooks or functions within the "tick" function .
- Capitalization does not affect the functionality of "tick" .
Drawing Lights
- The speaker names the created light object .
- By selecting "light draw" from available options, it allows drawing of lights on dark areas .
- A delay may be required when sending net messages related to spawning objects to avoid errors .
New Section
This section focuses on communication between clients and servers in order to send data back and forth.
Communication Between Client and Server
- Establishing communication between client and server enables various possibilities for data exchange .
- This opens up opportunities for creating interactive elements within programs .
New Section
The speaker concludes the video by encouraging experimentation and starting with simple projects.
Final Thoughts and Advice
- The speaker emphasizes the importance of starting small and gradually increasing complexity .
- Practice is key to improving coding skills, which can be achieved by creating scripts and exploring different functionalities .
Timestamps are approximate and may vary slightly.