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
Copy file name to clipboardExpand all lines: docs/guides/development/developing_plugins.md
+9-6Lines changed: 9 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ There are 2 ways to create a plugin in NutScript:
20
20
21
21
In your plugin/```sh_plugin.lua``` file, include the following:
22
22
23
-
```lua
23
+
```lua linenums="1"
24
24
PLUGIN.name="Plugin Name"
25
25
PLUGIN.author="You, the Creator"
26
26
PLUGIN.desc="A simple plugin that does something."
@@ -31,15 +31,15 @@ Here you'll need to set your plugin's name, the author, and a short description
31
31
## **Hooking**
32
32
33
33
Normally, to hook a function, you'll need to use the following syntax:
34
-
```lua
34
+
```lua linenums="1"
35
35
hook.Add("Think", "myUniqueFunction", function()
36
36
-- Do stuff
37
37
end)
38
38
```
39
39
40
40
However, NutScript has a special syntax for hooking functions within plugins.
41
41
42
-
```lua
42
+
```lua linenums="1"
43
43
functionPLUGIN:Think()
44
44
-- Do stuff
45
45
end
@@ -54,7 +54,9 @@ Advantages of using PLUGIN:
54
54
1. It gives the hooked code priority when executed. Meaning that code added via PLUGIN will run before most code added by addons.
55
55
56
56
2. It allows you to use code defined by PLUGIN to be run elsewhere in the gamemode.
57
-
- For example, if you have a plugin ```permadeath.lua``` that defines a function called ```PLUGIN:PlayerDeath(client, inflictor, attacker)```, and another plugin called ```medical```, you can have a function in the ```medical``` plugin call the ```permadeath``` PlayerDeath hook without running any other code that has been hooked to PlayerDeath, via ```nut.plugin.list.permadeath:PlayerDeath(client, inflictor, attacker)```.
57
+
58
+
!!! example
59
+
If you have a plugin ```permadeath.lua``` that defines a function called ```PLUGIN:PlayerDeath(client, inflictor, attacker)```, and another plugin called ```medical```, you can have a function in the ```medical``` plugin call the ```permadeath``` PlayerDeath hook without running any other code that has been hooked to PlayerDeath, via ```nut.plugin.list.permadeath:PlayerDeath(client, inflictor, attacker)```.
58
60
59
61
3. It allows to store variables specific to the plugin.
Copy file name to clipboardExpand all lines: docs/guides/development/developing_schema.md
+35-21Lines changed: 35 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
5
5
Make sure that you have the [Nutscript framework](https://github.com/NutScript/NutScript) already installed in the gamemodes folder (rename it to ```nutscript```).
6
6
In the same gamemodes plugin, place/create your schema folder, and name it as the name of your schema (hl2rp/cityrp/scprp)
7
-

7
+

8
8
9
9
## **The Main Schema Folder**
10
10
@@ -16,7 +16,9 @@ Within the Schema folder, you must have 3 additional folders:
16
16
17
17
and one .txt file named identically to your schema name (that is, if your schema is called hl2rp, the txt must also be called hl2rp.txt)
18
18
19
-
_**As a Rule of Thumb, you should not modify the gamemode folder at any point. Please look at [pre-existing schemas](installation/Getting_Started.md#Schemas) and copy the gamemode folder from there.**_
19
+
!!! warning
20
+
21
+
_**As a Rule of Thumb, you should not modify the gamemode folder at any point. Please look at [pre-existing schemas](installation/Getting_Started.md#Schemas) and copy the gamemode folder from there.**_
20
22
21
23
* The ```plugins``` folder is used to install additional plugins to the schema.
22
24
@@ -30,17 +32,19 @@ Within the ```schema``` folder, you must have 2 crucial folders: ```items``` and
30
32
31
33
The ```factions``` folder is used to create new factions playable on your gamemode. Each faction is represented by their individual file.
32
34
33
-
For example, if you want to have 3 factions called "Citizen", "Police" and "Insurgents", you would have 3 files within the factions folder
34
35
35
-
```
36
-
sh_citizen.lua
37
-
sh_police.lua
38
-
sh_insurgents.lua
39
-
```
36
+
!!! example
37
+
38
+
For example, if you want to have 3 factions called "Citizen", "Police" and "Insurgents", you would have 3 files within the factions folder
39
+
```
40
+
sh_citizen.lua
41
+
sh_police.lua
42
+
sh_insurgents.lua
43
+
```
40
44
41
45
Each file must contain the following code:
42
46
43
-
```lua
47
+
```lua linenums="1"
44
48
FACTION.name="Custom Faction" -- the name of your faction as it appears in-game
45
49
FACTION.desc="Custom faction for only some people to use." -- the faction's description, as seen in the character creation screen
46
50
FACTION.color=Color(255, 0, 0) -- the faction's color, as it appears in the scoreboard
@@ -61,7 +65,9 @@ FACTION.models = { -- default models available to the faction. The larger the li
61
65
FACTION_CUSTOM=FACTION.index-- mandatory, this allows the faction to be indexed in code elsewhere. Replace FACTION_CUSTOM with FACTION_#### where #### is a unique string for your faction.
62
66
```
63
67
64
-
[More information and options available for factions is available here.](development/Factions.md)
68
+
!!! note
69
+
70
+
[More information and options available for factions is available here.](factions.md)
65
71
66
72
## **The Items Folder**
67
73
@@ -73,9 +79,9 @@ There are 2 methods to adding items to your schema: single file items or via a b
73
79
74
80
You can add an item as a single file by creating one in the ```items``` folder directly. For example, if you want to create a potato item, you would create a new file called ```sh_potato.lua```
75
81
76
-
Inside the file, you must have this code
82
+
Inside the file, you must have this code:
77
83
78
-
```lua
84
+
```lua linenums="1"
79
85
ITEM.name="A Potato" -- item name
80
86
ITEM.desc="Boil em, Mash em, Stick em in a stew." -- item description
81
87
ITEM.price=0-- the default price, used by vendors and business tabs, for instance
@@ -86,9 +92,9 @@ ITEM.uniqueID = "potato" -- optional field, used for ease of reference in code
86
92
ITEM.health=10
87
93
```
88
94
89
-
If you want your items to have functionality, you may add functions via ```ITEM.functions.<name>```. For example
95
+
If you want your items to have functionality, you may add functions via ```ITEM.functions.<name>```. For example:
90
96
91
-
```lua
97
+
```lua linenums="1"
92
98
ITEM.functions.use= {
93
99
name="Consume", --Name of the function, if this doesn't exist it'll use "use"
94
100
tip="Consume the item.", --Tip when hovering over the function
@@ -113,13 +119,17 @@ base
113
119
food
114
120
```
115
121
116
-
Inside the base folder, create a lua file called the same as the target base folder (for instance if I am creating a food item base, I would create a file called ```sh_food.lua```)
122
+
Inside the base folder, create a lua file called the same as the target base folder
123
+
124
+
!!! example
125
+
126
+
For instance, if I am creating a food item base, I would create a file called ```sh_food.lua```
117
127
118
128
Inside this new file goes the default information of the item. Items defined within the target base folder will inherit all the values and functions from this base file.
119
129
120
130
Let's create a food base
121
131
122
-
```lua
132
+
```lua linenums="1"
123
133
ITEM.name="Food Base"
124
134
ITEM.model="models/Gibs/HGIBS.mdl"
125
135
ITEM.desc="Tasty food, or tasy drink."
@@ -149,7 +159,7 @@ Now, in the food folder, we can create as many different food items as we please
149
159
150
160
In the food folder, I will create a milk item. Call it ```sh_milk.lua```
151
161
152
-
```lua
162
+
```lua linenums="1"
153
163
ITEM.name="Milk"
154
164
ITEM.model="models/Gibs/HGIBS.mdl"
155
165
ITEM.desc="Full fat cow's milk."
@@ -167,7 +177,7 @@ If you want multiple bases, create individual files in the base folder, and a ne
167
177
168
178
The sh_schema.lua file is a crucial part of the schema. Upon creating it, enter the following code:
169
179
170
-
```lua
180
+
```lua linenums="1"
171
181
SCHEMA.name="Cool Schema" -- the Name of your Schema, as it appears in-game
172
182
SCHEMA.author="You" -- the Author of the schema
173
183
SCHEMA.desc="A schema for the people to learn from." -- A brief description of what the gamemode is about
@@ -183,10 +193,14 @@ nut.util.include("sh_commands.lua") -- this allows code within the sh_commands.l
183
193
nut.util.includeDir("hooks") -- this allows all files within the hooks folder in the schema folder to be readable by the schema
184
194
```
185
195
186
-
**Keep in mind that if you try to use functions or variables defined in these external files before they are included in the schema, they will not be available.**
196
+
!!! warning
197
+
198
+
Keep in mind that if you try to use functions or variables defined in these external files before they are included in the schema, they will not be available.
199
+
200
+
!!! note
187
201
188
-
Keep in mind that if you want to add folders that are default to nutscript, such as ```classes, meta``` or ```libs```, it is not necessary to include them.
202
+
Keep in mind that if you want to add folders that are default to nutscript, such as ```classes, meta``` or ```libs```, it is not necessary to include them.
189
203
190
204
## **Developing Plugins**
191
205
192
-
If you wish to create your own plugins, in order to keep the schema modular and organized, head over to [Developing Plugins](Developing%20Plugins.md).
206
+
If you wish to create your own plugins, in order to keep the schema modular and organized, head over to [Developing Plugins](developing_plugins.md).
- Legacy, original version of NutScript. It is not recommended to use this version.
15
15
16
-
There also exists the [NutScript 1.1-beta](https://github.com/rebel1324/NutScript/tree/1.1-beta) version, however, it is simply Version 1.2 in early stages of development. As such, any plugin that is made for 1.1-beta is fully compatible with 1.2 (but not 1.1 or 1.0).
16
+
17
+
??? note "NutScript 1.2 vs NutScript 1.1-beta"
18
+
There also exists the [NutScript 1.1-beta](https://github.com/rebel1324/NutScript/tree/1.1-beta) version, however, it is simply Version 1.2 in early stages of development. As such, any plugin that is made for 1.1-beta is fully compatible with 1.2 (but not 1.1 or 1.0).
0 commit comments