Installation

4 min readUpdated 2 weeks ago

Overview

ML Random Cloth is a companion resource for ml_clothing. It adds "pack" items that, when used, give a random clothing piece with a random drawable and texture written to the item metadata. It has no custom interface and no database of its own.

Quick Start

Add the resources to your server.cfg in this order. ml_random_cloth starts after ml_clothing because it hands the random clothing item to ml_clothing through the Bridge.

server.cfg
1ensure oxmysql
2ensure ox_lib
3ensure ox_inventory
4ensure ml_bridge
5ensure ml_clothing
6ensure ml_random_cloth
ml_clothing must be running

The pack items give real clothing items such as hat, jacket and pants. Those items are defined and handled by ml_clothing. If ml_clothing is not started, the pack removes itself but the player receives nothing usable. Start ml_clothing before ml_random_cloth.

Database

No database

ML Random Cloth does not create or use any SQL table. There is nothing to import. All randomness happens at runtime and the result is stored in the given item's metadata by ml_clothing.

Item Registration

The 15 standard pack items must be registered in ox_inventory. Copy the block below into your ox_inventory/data/items.lua. Each item declares client.export = 'ml_random_cloth.usePack', which is how using the item triggers the random-clothing logic.

ox_inventory/data/items.lua
1['pack_mask'] = {
2    label = "Mask Pack",
3    weight = 100,
4    stack = false,
5    client = { export = 'ml_random_cloth.usePack' }
6},
7['pack_hat'] = {
8    label = "Hat Pack",
9    weight = 100,
10    stack = false,
11    client = { export = 'ml_random_cloth.usePack' }
12},
13['pack_earrings'] = {
14    label = "Earrings Pack",
15    weight = 100,
16    stack = false,
17    client = { export = 'ml_random_cloth.usePack' }
18},
19['pack_glasses'] = {
20    label = "Glasses Pack",
21    weight = 100,
22    stack = false,
23    client = { export = 'ml_random_cloth.usePack' }
24},
25['pack_chain'] = {
26    label = "Chain Pack",
27    weight = 100,
28    stack = false,
29    client = { export = 'ml_random_cloth.usePack' }
30},
31['pack_undershirt'] = {
32    label = "Undershirt Pack",
33    weight = 100,
34    stack = false,
35    client = { export = 'ml_random_cloth.usePack' }
36},
37['pack_jacket'] = {
38    label = "Jacket Pack",
39    weight = 100,
40    stack = false,
41    client = { export = 'ml_random_cloth.usePack' }
42},
43['pack_pants'] = {
44    label = "Pants Pack",
45    weight = 100,
46    stack = false,
47    client = { export = 'ml_random_cloth.usePack' }
48},
49['pack_bodyarmor'] = {
50    label = "Body Armor Pack",
51    weight = 100,
52    stack = false,
53    client = { export = 'ml_random_cloth.usePack' }
54},
55['pack_bracelet'] = {
56    label = "Bracelet Pack",
57    weight = 100,
58    stack = false,
59    client = { export = 'ml_random_cloth.usePack' }
60},
61['pack_watch'] = {
62    label = "Watch Pack",
63    weight = 100,
64    stack = false,
65    client = { export = 'ml_random_cloth.usePack' }
66},
67['pack_bag'] = {
68    label = "Bag Pack",
69    weight = 100,
70    stack = false,
71    client = { export = 'ml_random_cloth.usePack' }
72},
73['pack_shoes'] = {
74    label = "Shoes Pack",
75    weight = 100,
76    stack = false,
77    client = { export = 'ml_random_cloth.usePack' }
78},
79['pack_gloves'] = {
80    label = "Gloves Pack",
81    weight = 100,
82    stack = false,
83    client = { export = 'ml_random_cloth.usePack' }
84},
85['pack_decals'] = {
86    label = "Decals Pack",
87    weight = 100,
88    stack = false,
89    client = { export = 'ml_random_cloth.usePack' }
90},

The same block ships in _INSTALL/ox_items.lua with the client.export line already on every item, so you can paste it straight into ox_inventory/data/items.lua.

Custom packs need an export too

Custom packs are registered in ox_inventory exactly like the standard packs, but each custom pack item uses client = { export = 'ml_random_cloth.useCustomPack' } while standard pack_* items use client = { export = 'ml_random_cloth.usePack' }.

Verify

Start the server and confirm the resource loaded without errors. With Config.Debug = true you will see a line like this in the server console:

lua
1[ml_random_clothing] ml_random_cloth initialized (Framework: qbx)

Give yourself a pack and use it in-game:

lua
1/giveitem [id] pack_jacket 1

Using the item plays a 2.5 second progress bar labeled "Opening clothes...", then removes the pack and gives one jacket item with a random drawable and texture.

  • Using a pack does nothing: confirm the item exists in ox_inventory with client = { export = 'ml_random_cloth.usePack' }. Without the export, ox_inventory has no code to run on use.
  • The pack is consumed but no clothing item appears: confirm ml_clothing is started and the target clothing item (for example jacket) is registered. The server calls Bridge.CanCarry before removing the pack, so a full inventory also stops the give.
  • Nothing happens and no progress bar shows: the resource found no valid drawable for that type on the current ped, or you are on cooldown. There is a 3 second server-side cooldown between pack opens per player.
  • Wrong language in the progress bar: set Config.Language in shared/config.lua. Supported values are en and it.