Getting Started - scripthookvdotnet/scripthookvdotnet GitHub Wiki
Before you can start playing with ScriptHookVDotNet you need some prerequisites:
How to install ScriptHookVDotNet
- Download the latest GitHub revision and compile it using Microsoft Visual Studio
- Copy
ScriptHookVDotNet.asi
andScriptHookVDotNet2/3.dll
to your GTA V directory - Create a
scripts
folder in your GTA V directory
Hint: ScriptHookVDotNet supports compiled assemblies as well as C# or VB source files placed in the scripts
folder in your GTA V directory. If you plan to create new source scripts, you should specify the latest scripting API version by naming the file like script.3.cs
as more features are available in the v3 API and it can have better performance. If the source file name is like script.cs
or script.2.cs
, the script will be executed using the v2 API.
Basic Knowledge
Every mod/script you write must inherit from the GTA.Script
class. This class provides 3 events:
Tick
KeyUp
KeyDown
Those 3 events provides the basic work area you can then work with.
Speeding up Development
To avoid needing to constantly exit and launch GTA V, you can reload scripts within ScriptHookVDotNet.
- Start GTA
- Test out your scripts
- Alt-tab back to your development environment (Visual Studio)
- Make some changes
- Build the script again
- Copy the DLL file into the
scripts
folder in your GTA V directory - Alt-tab back into the game
- Open the console by pressing
F4
, enterReload()
and hitEnter
Note: This also works with .cs or .vb source files
You may also want to set up a post build event in Visual Studio to copy the compiled DLL to your scripts
folder automatically.
Code Example
Below you can find a basic example mod that creates a vehicle in front of the own character with a 90° heading to the character when pressing Numpad1.
Note: This script is using the SHVDN v3 API.
using System;
using System.Drawing;
using System.Windows.Forms;
using GTA;
public class CreateVehicle : Script
{
public CreateVehicle()
{
Tick += OnTick;
KeyUp += OnKeyUp;
KeyDown += OnKeyDown;
}
private void OnTick(object sender, EventArgs e)
{
}
private void OnKeyDown(object sender, KeyEventArgs e)
{
}
private void OnKeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.NumPad1)
{
Vehicle vehicle = World.CreateVehicle(VehicleHash.Zentorno, Game.Player.Character.Position + Game.Player.Character.ForwardVector * 3.0f, Game.Player.Character.Heading + 90);
vehicle.CanTiresBurst = false;
vehicle.Mods.CustomPrimaryColor = Color.FromArgb(38, 38, 38);
vehicle.Mods.CustomSecondaryColor = Color.DarkOrange;
vehicle.PlaceOnGround();
vehicle.Mods.LicensePlate = "SHVDN";
}
}
}
Further Reading
Calling Native C++ Hash Functions
Now feel free to try out new things. There is so much powerful stuff to play with.