Difference between revisions of "ScriptHook: Script"

From Nomad DB
(Created page with "A Script is a collection of Lua scripts that are loaded by WD2 ScriptHook. Scripts are loaded upon starting the game with ScriptHook installed. This guide will give you an...")
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
A Script is a collection of Lua scripts that are loaded by [[WD2 ScriptHook]]. Scripts are loaded upon starting the game with ScriptHook installed. This guide will give you an overview of the structure behind those Scripts.
+
A Script is a collection of Lua scripts that are loaded by [[WD2 ScriptHook]]. Scripts are loaded upon starting the game with ScriptHook installed.
  
== Directory Structure ==
+
'''This guide will give you an overview of the structure behind those Scripts.'''
 +
 
 +
==Guides==
 +
 
 +
*[[WD2 ScriptHook: Key Binds]]
 +
*[[WD2 ScriptHook: Console Commands]]
 +
*[[WD2 ScriptHook: Script Table]]
 +
*[[WD2 ScriptHook: UI]]
 +
*[[WD2 ScriptHook: Rendering]]
 +
*[[WD2 ScriptHook: Events]]
 +
 
 +
==Directory Structure==
 
<pre>
 
<pre>
 
data/scripts
 
data/scripts
Line 9: Line 20:
 
</pre>
 
</pre>
  
=== manifest.json ===
+
===manifest.json===
The manifest holds information about a Script. Name, Author & Version can be specified here. The "entrypoint" is the Lua script that is loaded. For the ''keyBinds'' section, check out [[WD2 ScriptHook: Key Binds]].
+
The manifest holds information about a Script. Name, Author & Version can be specified here. The "entrypoint" is the Lua script that is loaded. The example below shows the ''manifest.json'' for the [[WD2 ScriptHook: Trainer|ScriptHook Trainer]].
  
 
<syntaxhighlight lang="json">
 
<syntaxhighlight lang="json">
Line 24: Line 35:
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
==Concepts==
 +
===Script Table===
 +
{{:WD2 ScriptHook: Script Table}}
 +
 +
'''For more information, check out [[WD2 ScriptHook: Script Table]].'''
 +
 +
===Key Bindings===
 +
You can bind Keys to Lua functions. Key Bindings are configured within the ''manifest.json'' section.
 +
 +
'''Check out [[WD2 ScriptHook: Key Binds]].'''
 +
 +
===Console Commands===
 +
Scripts can register custom Console Commands. These commands are registered directly within Lua.
 +
 +
'''Read more about [[WD2 ScriptHook: Console Commands]].'''
 +
 +
===ScriptHook Lua Functions===
 +
In addition to the [[WD2 Lua Functions|built-in Lua functions]], ScriptHook registers custom Lua functions that you can use. Those functions are used for Menus, Console Commands, and some alter the Game's world.
 +
 +
'''You can find a [[WD2 ScriptHook: Lua Functions|list of ScriptHook Lua functions here]]'''.
 +
 +
[[Category:WD2 ScriptHook]]

Revision as of 21:24, 2 August 2020

A Script is a collection of Lua scripts that are loaded by WD2 ScriptHook. Scripts are loaded upon starting the game with ScriptHook installed.

This guide will give you an overview of the structure behind those Scripts.

Guides

Directory Structure

data/scripts
data/scripts/[name]
data/scripts/[name]/manifest.json
data/scripts/[name]/[...].lua

manifest.json

The manifest holds information about a Script. Name, Author & Version can be specified here. The "entrypoint" is the Lua script that is loaded. The example below shows the manifest.json for the ScriptHook Trainer.

{
	"name": "Simple Trainer",
	"author": "Nomad Group",
	"version": "1.0",
	
	"entrypoint": "main.lua",
	"keyBinds": {
		"menu": "F4"
	}
}

Concepts

Script Table

Every Script has its own Script Table. It returns a Lua table that can be used for two things:

  1. Storing variables for the Script
  2. Callback / Event Handlers

Using the Event Handlers is also the only way to properly unregister event listeners from the Game's event system.

For more information, check out WD2 ScriptHook: Script Table.

Key Bindings

You can bind Keys to Lua functions. Key Bindings are configured within the manifest.json section.

Check out WD2 ScriptHook: Key Binds.

Console Commands

Scripts can register custom Console Commands. These commands are registered directly within Lua.

Read more about WD2 ScriptHook: Console Commands.

ScriptHook Lua Functions

In addition to the built-in Lua functions, ScriptHook registers custom Lua functions that you can use. Those functions are used for Menus, Console Commands, and some alter the Game's world.

You can find a list of ScriptHook Lua functions here.