Creating our First Script - KimonoBoy/SHVDNTutorial-NucleiLite GitHub Wiki
Welcome to the exciting world of Grand Theft Auto V scripting! In this section, we will dive into creating our very first script using ScriptHookVDotNet. We will keep it simple, with no code breakdown, and focus solely on how to create a new script and add it to the game. This will be a great starting point for those who are completely new to scripting and want to see how it's done in a straightforward and easy-to-follow manner. So buckle up, and let's get started on our first script!
Creating a new Script File (VSCode)
- Open your Visual Studio Code
Note: Feel free to follow the Getting Started section introduced in VSCode and return to this guide afterwards, else just close the page.
- Goto File -> New File... (or hit CTRL + ALT + Windows + N)
- In the new Window that appears type the following HelloGTAV.cs
- This will open up a Browse Window
- Locate your scripts folder inside your Grand Theft Auto V folder
Note: If a scripts folder does not already exist, create one.
- Hit Create File
You should now be taken to the newly created file inside your VSCode editor.
Creating a Hello GTA V Notification Script
Before you continue - please do not let the below code throw you off, we will cover the code later, for now just follow the flow and if you fail, try again. You can do it.
- In your new file, add the following:
using System;
using System.Windows.Forms;
using GTA;
using GTA.UI;
public class HelloGTAV : Script
{
public HelloGTAV()
{
KeyDown += OnKeyDown;
}
public void OnKeyDown(object sender, KeyEventArgs keyEventArgs)
{
if (keyEventArgs.KeyCode == Keys.L)
{
Notification.Show("Hello GTA V!");
}
}
}
-
Save the file and tab back in to GTA V
-
Once in GTA V hit the F4 key and wait for the ScriptHookVDotNet Console to appear
- Type out exactly the following: Reload() and hit Enter
- Press the L key, and you should see the following Notification in game
Congratulations, you've made your first Script for GTA V!
Reloading Scripts
- In GTA V hit the F4 key and wait for the ScriptHookVDotNet Console to appear
- Type out exactly the following: Reload() and hit Enter
Setting a HotKey for Reloading Scripts
In your Grand Theft Auto V-folder where your ScriptHookVDotNet.dll is located, there is also another file - this is a ScriptHookVDotNet.ini file which is a configuration-file.
-
Open the ScriptHookVDotNet.ini file
-
Copy and Paste the following to the file
ReloadKey=Insert
ConsoleKey=F4
Your file should look like the following
Note: You can replace the Insert key with any other key you'd like - you can see the list of keys at Keys Enum
- Save the file and the next time you want to Reload() you can simply press the key provided in the .ini
Previous - Text Editor
Next - Learning C# and ScriptHookVDotNet