Skip to content

Commit bd9cad9

Browse files
committed
xd
1 parent 9251e46 commit bd9cad9

File tree

5 files changed

+1224
-7
lines changed

5 files changed

+1224
-7
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
steps:
2626
- uses: actions/checkout@v3
2727
with:
28-
path: optional_modules
28+
path: modules
2929
- uses: leafo/gh-actions-lua@v8.0.0
3030
with:
3131
luaVersion: 5.2
@@ -42,7 +42,7 @@ jobs:
4242
--no-global --no-self \
4343
--no-max-line-length --no-max-code-line-length \
4444
--no-max-string-line-length --no-max-comment-line-length
45-
working-directory: optional_modules
45+
working-directory: modules
4646
4747
bump-version:
4848
needs: linter
@@ -224,7 +224,7 @@ jobs:
224224
mod=${d#extracted_}
225225
doc_dir=$(find "$d" -type d -iname docs -maxdepth 2 -print -quit || true)
226226
[ -z "$doc_dir" ] && continue
227-
dest="documentation/docs/optional_modules/${mod}"
227+
dest="documentation/docs/modules/${mod}"
228228
mkdir -p "$dest"
229229
find "$doc_dir" -maxdepth 1 -type f -name '*.md' -exec cp {} "$dest/" \;
230230
done
@@ -238,7 +238,7 @@ jobs:
238238
if [ -f documentation/modules.json ]; then
239239
jq -c '.[]' documentation/modules.json | while read -r mod; do
240240
id=$(echo "$mod" | jq -r '.public_uniqueID')
241-
dest="documentation/docs/optional_modules/${id}"
241+
dest="documentation/docs/modules/${id}"
242242
mkdir -p "$dest"
243243
{
244244
echo "# $(echo "$mod" | jq -r '.name')"
@@ -268,8 +268,8 @@ jobs:
268268
fi
269269
- name: clean-obsolete-docs
270270
run: |
271-
rm -rf documentation/docs/hooks/optional_modules
272-
rm -rf documentation/docs/libraries/optional_modules
271+
rm -rf documentation/docs/hooks/modules
272+
rm -rf documentation/docs/libraries/modules
273273
- uses: actions/setup-node@v3
274274
with:
275275
node-version: 16

generate_about_md.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if (!Array.isArray(modules)) {
2525
for (const mod of modules) {
2626
const id = mod.public_uniqueID || '';
2727
if (!id) continue;
28-
const dest = path.join(__dirname, 'documentation', 'docs', 'optional_modules', id);
28+
const dest = path.join(__dirname, 'documentation', 'docs', 'modules', id);
2929
fs.mkdirSync(dest, { recursive: true });
3030

3131
const lines = [];

sampledocs/hooks.md

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
# Class Hooks
2+
3+
Classes can implement lifecycle hooks to control access, initialize settings, and respond to events such as joining, leaving, spawning, or being transferred.
4+
5+
Define these functions inside your class definition files (`schema/classes/*.lua`).
6+
7+
All hooks are optional; unspecified hooks fall back to default behaviour.
8+
9+
---
10+
11+
### OnCanBe
12+
13+
**Purpose**
14+
15+
Determines whether a player is allowed to switch to this class.
16+
17+
**Parameters**
18+
19+
* `client` (`Player`): The player attempting to switch.
20+
21+
**Realm**
22+
23+
`Server`
24+
25+
**Returns**
26+
27+
* `boolean?`: Return `false` to deny the change.
28+
29+
**Example Usage**
30+
31+
```lua
32+
function CLASS:OnCanBe(client)
33+
-- Only allow admins or players that own the "V" flag.
34+
if client:IsAdmin() then
35+
return true
36+
end
37+
38+
local char = client:getChar()
39+
if char and char:hasFlags("V") then
40+
return true
41+
end
42+
43+
-- Returning false prevents the switch.
44+
return false
45+
end
46+
```
47+
48+
---
49+
50+
### OnLeave
51+
52+
**Purpose**
53+
54+
Runs on the previous class after a player successfully changes classes.
55+
56+
**Parameters**
57+
58+
* `client` (`Player`): The player who has left the class.
59+
60+
**Realm**
61+
62+
`Server`
63+
64+
**Returns**
65+
66+
* `nil`: This function does not return a value.
67+
68+
**Example Usage**
69+
70+
```lua
71+
function CLASS:OnLeave(client)
72+
-- Strip any class-specific weapons.
73+
client:StripWeapon("weapon_pistol")
74+
75+
-- Restore the player's previous model before the class change.
76+
local char = client:getChar()
77+
if char and self.model then
78+
char:setModel(char:getData("model", char:getModel()))
79+
end
80+
81+
-- Reset movement speeds back to the config defaults.
82+
client:SetWalkSpeed(lia.config.get("WalkSpeed"))
83+
client:SetRunSpeed(lia.config.get("RunSpeed"))
84+
end
85+
```
86+
87+
---
88+
89+
### OnSet
90+
91+
**Purpose**
92+
93+
Executes immediately after a player joins this class.
94+
95+
**Parameters**
96+
97+
* `client` (`Player`): The player who has joined the class.
98+
99+
**Realm**
100+
101+
`Server`
102+
103+
**Returns**
104+
105+
* `nil`: This function does not return a value.
106+
107+
**Example Usage**
108+
109+
```lua
110+
function CLASS:OnSet(client)
111+
local char = client:getChar()
112+
113+
-- Apply the class model and give a starter pistol.
114+
if char and self.model then
115+
char:setModel(self.model)
116+
end
117+
client:Give("weapon_pistol")
118+
119+
-- Initialize base stats from the class definition.
120+
if self.health then
121+
client:SetHealth(self.health)
122+
client:SetMaxHealth(self.health)
123+
end
124+
if self.armor then
125+
client:SetArmor(self.armor)
126+
end
127+
end
128+
```
129+
130+
---
131+
132+
### OnSpawn
133+
134+
**Purpose**
135+
136+
Runs each time a member of this class respawns.
137+
138+
**Parameters**
139+
140+
* `client` (`Player`): The player who has just spawned.
141+
142+
**Realm**
143+
144+
`Server`
145+
146+
**Returns**
147+
148+
* `nil`: This function does not return a value.
149+
150+
**Example Usage**
151+
152+
```lua
153+
function CLASS:OnSpawn(client)
154+
-- Apply the class load-out and stats every respawn.
155+
client:SetMaxHealth(self.health or 150)
156+
client:SetHealth(client:GetMaxHealth())
157+
client:SetArmor(self.armor or 50)
158+
159+
for _, wep in ipairs(self.weapons or {}) do
160+
client:Give(wep)
161+
end
162+
163+
if self.runSpeed then
164+
client:SetRunSpeed(self.runSpeed)
165+
end
166+
if self.walkSpeed then
167+
client:SetWalkSpeed(self.walkSpeed)
168+
end
169+
end
170+
```
171+
172+
---
173+
174+
### OnTransferred
175+
176+
**Purpose**
177+
178+
Fires when a player is moved into this class from another.
179+
180+
**Parameters**
181+
182+
* `client` (`Player`): The player who was transferred.
183+
* `oldClass` (`number`): Index of the previous class.
184+
185+
**Realm**
186+
187+
`Server`
188+
189+
**Returns**
190+
191+
* `nil`: This function does not return a value.
192+
193+
**Example Usage**
194+
195+
```lua
196+
function CLASS:OnTransferred(client, oldClass)
197+
local char = client:getChar()
198+
if char and self.model then
199+
-- Swap the model to match the new class.
200+
char:setModel(self.model)
201+
end
202+
203+
-- Record the previous class so we can switch back later if needed.
204+
char:setData("previousClass", oldClass)
205+
end
206+
```
207+
208+
---

sampledocs/libraries.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Attributes Library
2+
3+
This page documents the functions for working with character attributes.
4+
5+
---
6+
7+
## Overview
8+
9+
The attributes library loads attribute definitions from Lua files, keeps track of character values, and provides helper methods for modifying them. Each attribute is defined on a global `ATTRIBUTE` table inside its own file. When `lia.attribs.loadFromDir` is called the file is included **shared**, default values are filled in, and the definition is stored in `lia.attribs.list` using the file name (without extension or the `sh_` prefix) as the key. The loader is invoked automatically when a module is initialized, so most schemas simply place their attribute files in `schema/attributes/`.
10+
11+
For details on each `ATTRIBUTE` field, see the [Attribute Fields documentation](../definitions/attribute.md).
12+
13+
14+
### lia.attribs.loadFromDir
15+
16+
**Purpose**
17+
18+
Loads attribute definitions from every Lua file in the given directory and registers them in `lia.attribs.list`.
19+
20+
**Parameters**
21+
22+
* `directory` (*string*): Path to the folder containing attribute Lua files.
23+
24+
**Realm**
25+
26+
`Shared`
27+
28+
**Returns**
29+
30+
* *nil*: This function does not return a value.
31+
32+
**Example Usage**
33+
34+
```lua
35+
-- schema/attributes/strength.lua
36+
ATTRIBUTE.name = "Strength"
37+
ATTRIBUTE.desc = "Determines melee damage."
38+
ATTRIBUTE.startingMax = 20
39+
ATTRIBUTE.maxValue = 50
40+
41+
function ATTRIBUTE:OnSetup(client, value)
42+
client:SetMaxHealth(100 + value)
43+
end
44+
45+
-- Load all attribute files once at startup
46+
lia.attribs.loadFromDir("schema/attributes")
47+
```
48+
49+
---
50+
51+
### lia.attribs.setup
52+
53+
**Purpose**
54+
55+
Initializes and refreshes attribute data for a player's character, invoking any `OnSetup` callbacks defined by individual attributes.
56+
57+
**Parameters**
58+
59+
* `client` (*Player*): The player whose character attributes should be set up.
60+
61+
**Realm**
62+
63+
`Server`
64+
65+
**Returns**
66+
67+
* *nil*: This function does not return a value.
68+
69+
**Example Usage**
70+
71+
```lua
72+
-- After modifying a character attribute, run setup again so any
73+
-- OnSetup hooks update the player's stats.
74+
local char = client:getChar()
75+
char:updateAttrib("strength", 5)
76+
lia.attribs.setup(client)
77+
```
78+
79+
---

0 commit comments

Comments
 (0)