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)

  1. 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.

  1. Goto File -> New File... (or hit CTRL + ALT + Windows + N)

image

  1. In the new Window that appears type the following HelloGTAV.cs

image

  1. This will open up a Browse Window

VSCode NewFile Browser

  1. Locate your scripts folder inside your Grand Theft Auto V folder

Note: If a scripts folder does not already exist, create one.

  1. Hit Create File

Create File - Browser

You should now be taken to the newly created file inside your VSCode editor.

image

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.

  1. 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!");
        }
    }
}
  1. Save the file and tab back in to GTA V

  2. Once in GTA V hit the F4 key and wait for the ScriptHookVDotNet Console to appear

image

  1. Type out exactly the following: Reload() and hit Enter

image

  1. Press the L key, and you should see the following Notification in game

image

Congratulations, you've made your first Script for GTA V!

Reloading Scripts

  1. In GTA V hit the F4 key and wait for the ScriptHookVDotNet Console to appear

image

  1. Type out exactly the following: Reload() and hit Enter

image

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.

  1. Open the ScriptHookVDotNet.ini file

  2. Copy and Paste the following to the file

ReloadKey=Insert 
ConsoleKey=F4 

Your file should look like the following

image

Note: You can replace the Insert key with any other key you'd like - you can see the list of keys at Keys Enum

  1. 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