ScriptHookV .NET
made by Crosire
You may remember the .NET ScriptHook back from GTAIV, it allowed using the easy to learn, but extremly powerful .NET languages to write scripts that can be executed ingame.
About
This ASI plugin for the just released ScriptHookV attempts to recreate this experience for GTAV. It's full source code is hosted on Github, contributions are warmly welcomed.
Right now it's able to load, compile and run .NET scripts and reload them while the game is running (press the "Insert" key). Scripts are executed in a separate AppDomain, any exceptions thrown thus shouldn't affect the game or ScriptHook.
The associated .NET scripting API is still in very early stages (I tried to keep it close to the one from the GTAIV .NET ScriptHook, to simplify conversion) though, so you currently have to call some native functions manually through "GTA.Native.Function.Call".
Requirements
ScriptHookV just copy scriptvhook and dsound
Microsoft .NET Framework 4.0 (or higher)
Microsoft Visual C++ Redistributable Package for Visual Studio 2013 (x64)
Installation
1. Make sure you have all requirements installed (or loading will fail).
2. Download and install ScriptHookV (including the ASI loader).
3. Download ScriptHookV .NET and copy the ASI into your game folder.
4. Create (or download) a C#/VisualBasic code file (.cs, .vb) or compiled .NET assembly (.dll) inside a "/scripts/" subfolder in your game directory and start scripting!
Todo
Add a console or something similar, to get rid of the reload key and to display error messages ingame.
Expand the .NET GTA scripting API and improve the already existing classes.
Add some proper logging (not the hacky solution I'm currently using).
...
Contributing
Any help on improving the API is much appreciated (it's obviously very basic currently and the performance could be much better, by using some form of caching).
Important files:
src/Main.cpp: The main script entry point
src/ScriptDomain.cpp: .NET script manager. Loads, compiles and executes the scripts.
src/Script.hpp: Class from which all scripts have to inherit.
src/Native.cpp: Managed to native function call conversion.
The remaining files implement the scripting API.
Writing Scripts
Either use notepad to edit source code scripts directly or use Visual Studio to compile them to assemblies. Going down the Visual Studio way has the advantage of syntax highlighting, code completion and Intellisense (since there is no API documentation yet). Just create a C# or VisualBasic class library project, add a reference to ScriptHookV .NET (rename the ASI to DLL) in the project properties and you are ready to go.
If something doesn't work, check the log file ScriptHookVDotNet creates. It catches exceptions and gives you all the information to get to the bottom of the problem.
Example script, which adds the option to toggle the vehicle indicator signals with "Q" and "E":
Code:
using GTA;
using System;
using System.Windows.Forms;
public class VehicleIndicatorDemo : Script // Every class inheriting from GTA.Script is considered a script and executed
{
public VehicleIndicatorDemo()
{
Tick += OnTick; // Main loop event, called every few milliseconds specified via the Interval property.
KeyUp += OnKeyUp; // Called when a key or mouse button is released.
KeyDown += OnKeyDown; // Called when a key or mouse button is pressed.
Interval = 10; // Tick interval in milliseconds. Set to zero to run as fast as possible.
}
bool mIndicatorLeft = false;
bool mIndicatorRight = false;
void OnTick(object sender, EventArgs e)
{
// Calling native functions:
// - No return type: GTA.Native.Function.Call("SET_MAX_WANTED_LEVEL", 0);
// - With return type: int id = GTA.Native.Function.Call<int>("PLAYER_PED_ID");
}
void OnKeyUp(object sender, KeyEventArgs e)
{
}
void OnKeyDown(object sender, KeyEventArgs e)
{
Ped player = Game.Player.Character;
if (player.IsInVehicle())
{
Vehicle vehicle = player.CurrentVehicle;
switch (e.KeyCode)
{
case Keys.Q:
vehicle.LeftIndicatorLightOn = this.mIndicatorLeft = !this.mIndicatorLeft;
break;
case Keys.E:
vehicle.RightIndicatorLightOn = this.mIndicatorRight = !this.mIndicatorRight;
break;
}
}
}
}
VirusTotal Results
Jotti Results