You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hook callbacks are intended for validation only and should avoid side effects such as modifying data, writing to a database, or triggering additional operations.
15
+
16
+
Because actions may still be in progress or may fail, modifying item or inventory state before completion can lead to race conditions or inconsistent behavior.
17
+
18
+
To avoid issues, perform state changes or follow-up logic in post-hook events.
@@ -40,7 +50,8 @@ By returning `false`, you can cancel the action and revert the inventory state.
40
50
- toSlot?: `table` or `number`
41
51
- count: `number`
42
52
43
-
**Example**
53
+
<details>
54
+
<summary><b>Example</b></summary>
44
55
45
56
Blacklists "water" from being moved into or from gloveboxes and trunks.
46
57
@@ -60,6 +71,8 @@ end, {
60
71
})
61
72
```
62
73
74
+
</details>
75
+
63
76
### openInventory
64
77
65
78
- Payload: `table`
@@ -70,7 +83,8 @@ end, {
70
83
Triggered when a player tries to open a secondary inventory.
71
84
By returning `false`, you can cancel the action and keep the player's inventory closed.
72
85
73
-
**Example**
86
+
<details>
87
+
<summary><b>Example</b></summary>
74
88
75
89
Disables gloveboxes and trunks.
76
90
@@ -87,6 +101,8 @@ end, {
87
101
})
88
102
```
89
103
104
+
</summary>
105
+
90
106
### openShop
91
107
92
108
- Payload: `table`
@@ -103,7 +119,8 @@ end, {
103
119
Triggered when a player tries to open a shop inventory.
104
120
By returning `false`, you can cancel the action and keep the shop inventory closed.
105
121
106
-
**Example**
122
+
<details>
123
+
<summary><b>Example</b></summary>
107
124
108
125
Disable General stores.
109
126
@@ -119,6 +136,8 @@ end, {
119
136
})
120
137
```
121
138
139
+
</details>
140
+
122
141
### createItem
123
142
124
143
- Payload: `table`
@@ -130,7 +149,10 @@ end, {
130
149
Triggered when an item is created, either by buying it, using AddItem, or when converting inventory data.
131
150
By returning a table you can modify or replace the metadata given to an item.
132
151
133
-
**Example**
152
+
Post-hook events are not necessary for this event, but are still recommended
153
+
154
+
<details>
155
+
<summary><b>Example</b></summary>
134
156
135
157
Sets the label for "water" to "Mineral Water".
136
158
@@ -148,6 +170,8 @@ end, {
148
170
})
149
171
```
150
172
173
+
</details>
174
+
151
175
### buyItem
152
176
153
177
- Payload: `table`
@@ -165,7 +189,8 @@ end, {
165
189
166
190
Triggered when an item is about to be purchased and can return `false` to prevent the transaction.
167
191
168
-
**Example**
192
+
<details>
193
+
<summary><b>Example</b></summary>
169
194
170
195
Prevents players from purchasing items at General stores.
171
196
@@ -182,6 +207,8 @@ end, {
182
207
183
208
```
184
209
210
+
</details>
211
+
185
212
### craftItem
186
213
187
214
- Payload: `table`
@@ -198,7 +225,8 @@ end, {
198
225
- toInventory: `number`
199
226
- toSlot: `number`
200
227
201
-
**Example**
228
+
<details>
229
+
<summary><b>Example</b></summary>
202
230
203
231
Prevent lockpicks from being crafted by players.
204
232
@@ -215,6 +243,8 @@ end, {
215
243
216
244
```
217
245
246
+
</details>
247
+
218
248
### usingItem
219
249
220
250
Triggered when an item is about to be used.
@@ -234,7 +264,8 @@ By returning `false`, you can fully prevent it from being used.
234
264
- metadata: `table`
235
265
- consume: `number`
236
266
237
-
**Example**
267
+
<details>
268
+
<summary><b>Example</b></summary>
238
269
239
270
Prevent the player from using the "water" item.
240
271
@@ -250,6 +281,8 @@ end, {
250
281
})
251
282
```
252
283
284
+
</details>
285
+
253
286
## removeHooks
254
287
255
288
Removes a hook created by the invoking resource with the the specified id.
@@ -259,4 +292,27 @@ If no id is specified then all hooks registered by the resource are removed.
259
292
exports.ox_inventory:removeHooks(id)
260
293
```
261
294
262
-
- id?: `number`
295
+
- id?: `string`
296
+
297
+
## Post-hook events
298
+
299
+
Post-hook events let you register an event handler that runs after all hooks have finished and the action has either completed successfully or been rejected.
300
+
301
+
Use the `hookId` returned by registerHook with AddEventHandler to handle post-hook logic.
302
+
303
+
```lua
304
+
---Use filter logic so only relevant inventories trigger the post-hook event.
0 commit comments