Skip to content

Instantly share code, notes, and snippets.

@ikt32
Last active October 10, 2023 17:48
Show Gist options
  • Save ikt32/0678311d913a348bc4fcae0751436a48 to your computer and use it in GitHub Desktop.
Save ikt32/0678311d913a348bc4fcae0751436a48 to your computer and use it in GitHub Desktop.

Getting up to speed with scripting for GTA V

Want to create your first GTA V script? There are a few things to think of and know beforehand, which will help you in creating a script mod. This document will briefly explain your options, things you need to prepare, and link some existing guides.

You don't need to be proficient at programming: scripting in games can be a fun way to learn a language and programming concepts.

Useful skills and tools to have

Scripting frameworks

There are different frameworks (libraries) that you can make scripts for. These manage loading scripts into the game for you, and provide functions to interact with the game.

Scripting framework Language Features/Notes
ScriptHookV C++ Barebones scripting interface, decently popular, standalone
ScriptHookVDotNet C#/.NET languages Powerful scripting interface, very popular, builds on ScriptHookV
RagePluginHook C#/.NET languages Powerful scripting interface, not as popular, standalone
Lua Plugin Lua New FiveM-style Lua for SP

There are other similar frameworks, standalone or requiring ScriptHookV, with their own advantages and disadvantages. I will not go into FiveM in this quick overview, but there's good support for popular scripting languages there too.

Generally, as a script developer, you want to choose something that allows you to develop in an easy way, or where the learning curve isn't as steep. Depending on your experience with software development and/or any performance requirements, you may choose your scripting framework. It's a good idea to give them all a quick spin.

Scripting

Scripting is basically programming. This chapter will discuss some GTA 5-specific details.

Structure

Scripts are generally run in an infinite loop. Each iteration here is called a "tick", in which it should have completed all its operations for that tick. If you've ever developed for an Arduino or something alike, you might already be familiar with the process.

Depending on your framework, you need to manually make that loop, or you can just use a provided function like OnTick(). All of your script logic is run in that loop, and at the end you instruct your script to wait until its turn happens again. If your framework offers a "Tick" mechanism, this manual wait is not needed, and you can set the tick rate elsewhere.

Before the loop starts, you can add some initialization code. For example: read your settings.

Natives

To interact with the game, you can use natives. These are essentially the functions Rockstar also uses in their game scripts to interact with the world. The scripting frameworks find these natives and provide them to you. Internally, these frequently change when the game is updated, but the scripting framework will also be updated to keep the natives the same to you, so your script does not need an update every time the game updates, if you don't manually do other things with the game memory.

Many natives exist for many different operations, ranging from player functions to various UI functions. These natives have a C-interface, meaning they are simply functions, sometimes with a return value, sometimes with arguments. You can make wrappers for these to interact with the game in an object-oriented manner, or use a framework that does this heavy lifting for you. ScriptHookV is very barebones and does not wrap any of these natives, ScriptHookVDotNet and RagePluginHook do abstract this away for you. The latter two still provide functions to directly call the natives, so you have full control regardless of which framework you pick.

Some natives can be run once and have a lasting effect, others need to be run every tick. Use one of the Native DBs or your framework documentation to find out which natives behave in which way.

In general, beware of the exact workings of these natives. As everything here is unofficial and has been discovered with reverse engineering and trial-and-error, documentation might not be completely accurate. Expect some trial-and-error when using less straightforward natives.

User interaction

Depending on your use case, there are different ways to get your user interacting with your mod. Some use cases do not require the user to do anything, and integrate right into the existing aspects of the game. Others might require some explicit user input, in form of settings, commands, or through some sort of UI or menu.

Again, how this is implemented depends on your chosen framework, but generally these methods can be put into a few categories. These are not exclusive, and depending on how complex you want to make your mod, mixing these is certainly possible.

No input can be used for things that should "run in the background", such as a god mode or vehicle auto-repair.

Keypresses can be used to activate a function, or combine game actions with additional mod enhancements. You have two options here.

  1. Detect key presses and controller input with Windows APIs. This does not use any game mapping but might be useful when trying to set consistent or inaccessible keys for the game.
  2. Respond to input by using a game native. This uses the same controls that the game sees. It's also the easier way to respond to both controller and keyboard input.

Commands

GTA V on PC comes with a cheat console. By pressing tilde (~) this opens, and text can be entered. With natives it's possible to respond to this input once the player has finished their input. It's also possible to launch new text entry windows.

Additionally, RagePluginHook and ScriptHookVDotNet v3 support consoles of their own, though these can generally be considered as tools to aid development.

Menus

The game does not offer any native-accessible menus, such as the interaction menu or tuning menus. You'll need to spin up your own, or use an existing library.

Making your own can take a lot of effort, so most scripts that use a menu stick with an existing base.

Further reading and Resources

AHK1221's tutorials. (Text & images, ScriptHookVDotNet)

Metiri Personal's tutorials (YouTube videos, ScriptHookVDotNet)

Alexander Blade's ScriptHookV SDK samples (Code)

General information/support channels:

Suggestions are welcome!

Changelog

2023-10-10

  • Add Dot.'s Native DB
  • Add Lua Plugin
  • Slight grammar/sentence updates

2020-05-21

  • Update native DB location to alloc8ors
  • Add animations resource
  • Add decompiled scripts resource

2020-05-22

  • Updated scaleforms website

2020-05-26

  • Add particles from Alt:V

2020-07-02

  • Add FiveM Native DB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment