Skip to content

Commit 99154a1

Browse files
committed
Update docs for v0.1.2
1 parent 87874c5 commit 99154a1

12 files changed

Lines changed: 923 additions & 139 deletions

File tree

docs/.vitepress/config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ module.exports = {
5454
{ text: 'Limitations', link: '/guide/limitations' }
5555
]
5656
},
57+
{
58+
text: 'Mod System',
59+
collapsed: false,
60+
items: [
61+
{ text: 'Mod System Overview', link: '/guide/mod-system' },
62+
{ text: 'Mod Imports and Exports', link: '/guide/mod-functions' }
63+
]
64+
},
5765
{
5866
text: 'Contributing',
5967
collapsed: false,
@@ -74,6 +82,7 @@ module.exports = {
7482
{ text: 'Timing', link: '/api/core/timing' },
7583
{ text: 'GameObjects', link: '/api/core/gameobjects' },
7684
{ text: 'Globals', link: '/api/core/globals' },
85+
{ text: 'Mod System', link: '/api/mod/' },
7786
]
7887
},
7988
{
@@ -153,6 +162,7 @@ module.exports = {
153162
{ text: 'Registry Example', link: '/examples/registry' },
154163
{ text: 'Economy Example', link: '/examples/economy' },
155164
{ text: 'Curfew Example', link: '/examples/curfew' },
165+
{ text: 'Mod System Example', link: '/examples/mod-system' },
156166
]
157167
},
158168
{

docs/api/mod/index.md

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
# Mod System API
2+
3+
The Mod System API allows you to work with mods in ScheduleLua, including managing dependencies, and exporting/importing functionality between mods.
4+
5+
## Mod Management Functions
6+
7+
### GetMod
8+
9+
**Signature:** `table GetMod(string modName)`
10+
11+
**Description:** Gets information about a loaded mod by its folder name.
12+
13+
#### Parameters
14+
15+
- `modName` (string): The folder name of the mod to get information about
16+
17+
#### Returns
18+
19+
A table containing information about the mod, or nil if the mod is not loaded. The table has the following structure:
20+
21+
```lua
22+
{
23+
name = "My Mod", -- Display name from manifest
24+
folder = "my_mod", -- Folder name
25+
version = "1.0.0", -- Version from manifest
26+
description = "...", -- Description from manifest
27+
author = "Your Name", -- Author from manifest
28+
dependencies = {...}, -- Table of dependency folder names
29+
api_version = "0.1.2" -- API version from manifest
30+
}
31+
```
32+
33+
#### Example
34+
35+
```lua
36+
local mod = GetMod("economy_mod")
37+
if mod then
38+
Log("Mod name: " .. mod.name)
39+
Log("Mod version: " .. mod.version)
40+
Log("Mod author: " .. mod.author)
41+
end
42+
```
43+
44+
### GetAllMods
45+
46+
**Signature:** `table GetAllMods()`
47+
48+
**Description:** Gets information about all loaded mods.
49+
50+
#### Returns
51+
52+
An array of mod information tables, each with the same structure as returned by `GetMod()`.
53+
54+
#### Example
55+
56+
```lua
57+
local mods = GetAllMods()
58+
Log("Loaded mods: " .. #mods)
59+
for _, mod in ipairs(mods) do
60+
Log("- " .. mod.name .. " v" .. mod.version .. " by " .. mod.author)
61+
end
62+
```
63+
64+
### IsModLoaded
65+
66+
**Signature:** `boolean IsModLoaded(string modName)`
67+
68+
**Description:** Checks if a mod is loaded by its folder name.
69+
70+
#### Parameters
71+
72+
- `modName` (string): The folder name of the mod to check
73+
74+
#### Returns
75+
76+
`true` if the mod is loaded, `false` otherwise.
77+
78+
#### Example
79+
80+
```lua
81+
if IsModLoaded("required_mod") then
82+
Log("Required mod is loaded!")
83+
else
84+
LogError("Required mod is not loaded!")
85+
end
86+
```
87+
88+
## Function Import/Export
89+
90+
### ExportFunction
91+
92+
**Signature:** `void ExportFunction(string name, function func)`
93+
94+
**Description:** Exports a function from the current mod, making it available for other mods to import.
95+
96+
#### Parameters
97+
98+
- `name` (string): The name to export the function as
99+
- `func` (function): The function to export
100+
101+
#### Example
102+
103+
```lua
104+
ExportFunction("CalculateTax", function(amount, rate)
105+
rate = rate or 0.15
106+
return amount * rate
107+
end)
108+
```
109+
110+
### ImportFunction
111+
112+
**Signature:** `function ImportFunction(string modName, string functionName)`
113+
114+
**Description:** Imports a function exported by another mod.
115+
116+
#### Parameters
117+
118+
- `modName` (string): The folder name of the mod that exports the function
119+
- `functionName` (string): The name of the exported function to import
120+
121+
#### Returns
122+
123+
The exported function, or nil if the mod is not loaded or the function is not exported.
124+
125+
#### Example
126+
127+
```lua
128+
local CalculateTax = ImportFunction("economy_mod", "CalculateTax")
129+
if CalculateTax then
130+
local tax = CalculateTax(1000)
131+
Log("Tax amount: " .. tax)
132+
end
133+
```
134+
135+
### GetModExport
136+
137+
**Signature:** `any GetModExport(string modName, string exportName)`
138+
139+
**Description:** Gets an exported value (function or other value) from a mod.
140+
141+
#### Parameters
142+
143+
- `modName` (string): The folder name of the mod that exports the value
144+
- `exportName` (string): The name of the exported value to get
145+
146+
#### Returns
147+
148+
The exported value, or nil if the mod is not loaded or the value is not exported.
149+
150+
#### Example
151+
152+
```lua
153+
local TAX_RATE = GetModExport("economy_mod", "TAX_RATE")
154+
if TAX_RATE then
155+
Log("Current tax rate: " .. TAX_RATE)
156+
end
157+
```
158+
159+
## Best Practices
160+
161+
1. Always check if required mods are loaded before trying to use them:
162+
163+
```lua
164+
if not IsModLoaded("required_mod") then
165+
LogError("This mod requires 'required_mod' to be installed")
166+
return
167+
end
168+
```
169+
170+
2. Check if imported functions exist before using them:
171+
172+
```lua
173+
local func = ImportFunction("mod", "func")
174+
if func then
175+
func()
176+
else
177+
LogError("Failed to import function 'func' from 'mod'")
178+
end
179+
```
180+
181+
3. Use namespaces for your mod's global data to avoid conflicts:
182+
183+
```lua
184+
MY_MOD = {
185+
version = "1.0.0",
186+
settings = {}
187+
}
188+
```
189+
190+
4. Document your exported functions for other mod authors:

docs/api/npc/finding.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This section covers the functions used to find and get information about NPCs in
44

55
## GetNPC
66

7-
**Signature:** `NPC GetNPC(string npcId)`
7+
**Signature:** `NPCProxy GetNPC(string npcId)`
88

99
**Description:** Gets an NPC object by ID. This function is the primary way to locate a specific NPC in the game world.
1010

@@ -14,7 +14,7 @@ This section covers the functions used to find and get information about NPCs in
1414

1515
### Returns
1616

17-
An NPC object if found, or `nil` if no NPC with the given ID exists.
17+
An NPCProxy object if found, or `nil` if no NPC with the given ID exists.
1818

1919
### Example
2020

@@ -24,6 +24,8 @@ function SayHelloToNPC(npcId)
2424

2525
if npc then
2626
Log("Found NPC with ID: " .. npcId)
27+
Log("NPC full name: " .. npc.FullName)
28+
2729
-- You can now use this NPC object with other functions
2830
local position = GetNPCPosition(npc)
2931
Log("NPC is at position: " .. position.x .. ", " .. position.y .. ", " .. position.z)
@@ -38,9 +40,10 @@ SayHelloToNPC("doris_lubbin")
3840

3941
### Notes
4042

41-
- The NPC object returned can be used with other NPC functions like `GetNPCPosition`
43+
- The NPCProxy object returned can be used with other NPC functions like `GetNPCPosition`
4244
- NPC IDs are case-sensitive
4345
- Performance tip: Cache the NPC object if you need to use it repeatedly
46+
- The returned object is an NPCProxy, which provides controlled access to NPC properties
4447

4548
## GetNPCState
4649

@@ -111,18 +114,19 @@ DisplayNPCInfo("bob_001")
111114

112115
- This function is useful for getting detailed information without needing to use multiple separate function calls
113116
- The table structure may be expanded in future updates with additional NPC properties
117+
- As an alternative, you can access these properties directly from the NPCProxy returned by GetNPC, for example: `npc.FullName` or `npc.IsConscious`
114118

115119
## GetNPCPosition
116120

117121
**Status:** 🔄 Partial
118122

119-
**Signature:** `Vector3Proxy GetNPCPosition(NPC npc)`
123+
**Signature:** `Vector3Proxy GetNPCPosition(NPCProxy npc)`
120124

121125
**Description:** Gets the position of an NPC in the game world.
122126

123127
### Parameters
124128

125-
- `npc` (NPC): An NPC object reference (from `GetNPC`)
129+
- `npc` (NPCProxy): An NPCProxy object reference (from `GetNPC`)
126130

127131
### Returns
128132

@@ -204,6 +208,7 @@ CheckNPCLocation("bob_001")
204208

205209
- Regions are designated areas in the game world with specific names
206210
- This is more efficient than getting the NPC's position and then checking what region that position is in
211+
- Alternatively, you can access the region directly from an NPCProxy: `local region = npc.Region`
207212

208213
## GetNPCsInRegion
209214

docs/api/npc/index.md

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ The NPC API provides functions for finding, managing, and interacting with non-p
2323
- [`GetNPCsInRegion(region)`](./managing.md#getnpcsinregion) - Gets all NPCs in a specific region
2424
- [`GetAllNPCRegions()`](./managing.md#getallnpcregions) - Gets a list of all regions that contain NPCs
2525

26+
## NPCProxy Type
27+
28+
To improve compatibility with the Lua scripting system, NPCs are now wrapped in an `NPCProxy` type that exposes only the necessary properties and functions while hiding complex internal implementation details. This provides better stability, especially on IL2CPP/AOT platforms once ScheduleLua supports it.
29+
30+
The `NPCProxy` type provides these properties:
31+
- `ID` - The unique identifier of the NPC
32+
- `FullName` - The NPC's full name
33+
- `IsConscious` - Whether the NPC is currently conscious
34+
- `Region` - The region the NPC is currently in
35+
- `IsMoving` - Whether the NPC is currently moving
36+
2637
## Example Usage
2738

2839
### Basic NPC Lookup and Information
@@ -100,7 +111,7 @@ function MoveNPCToPlayer(npcId)
100111
local npc = GetNPC(npcId)
101112
if not npc then
102113
LogError("NPC not found: " .. npcId)
103-
return
114+
return false
104115
end
105116

106117
local playerPos = GetPlayerPosition()
@@ -113,17 +124,30 @@ function MoveNPCToPlayer(npcId)
113124

114125
Log("Attempted to move NPC with ID " .. npcId .. " to player's location")
115126
Log("Note: NPC position setting is still in development and may not work correctly")
127+
return true
116128
end
117129

118-
-- Usage example
119-
RegisterCommand("summon", "Attempts to summon an NPC to your location", "summon [npcId]", function(args)
120-
if not args[2] then
121-
LogError("Please specify an NPC ID")
122-
return
123-
end
130+
-- Properly register command after console is ready
131+
function OnConsoleReady()
132+
RegisterCommand(
133+
"npc_summon",
134+
"Attempts to summon an NPC to your location",
135+
"npc_summon <npcId>",
136+
function(args)
137+
if not args[2] then
138+
LogError("Please specify an NPC ID")
139+
return
140+
end
141+
142+
local success = MoveNPCToPlayer(args[2])
143+
if not success then
144+
LogError("Failed to summon NPC")
145+
end
146+
end
147+
)
124148

125-
MoveNPCToPlayer(args[2])
126-
end)
149+
Log("NPC summon command registered successfully")
150+
end
127151
```
128152

129153
### Tracking NPC Movements
@@ -176,6 +200,18 @@ In future updates, we plan to expand the API to include:
176200

177201
Note that some commonly requested features, such as making NPCs follow players or complex NPC behavior control, are not currently planned for implementation.
178202

203+
## Command Registration Best Practices
204+
205+
When creating commands that utilize the NPC API, follow these best practices:
206+
207+
1. **Always register commands in `OnConsoleReady()`** to ensure the console system is fully initialized
208+
2. **Use prefixes like `npc_`** for your commands to avoid conflicts with built-in game commands
209+
3. **Provide clear descriptions and usage examples** to make your commands user-friendly
210+
4. **Include proper error handling** for cases when NPCs don't exist or parameters are invalid
211+
5. **Return success/failure status** to provide feedback to the user
212+
213+
See the [Command API documentation](../registry/commands.md) for more details on registering and managing console commands.
214+
179215
Stay tuned for updates to the API as development progresses.
180216

181217
Explore the sections in the sidebar for detailed documentation of each function.

0 commit comments

Comments
 (0)