Tips and Tricks
Tips[edit]
- Nutscript supports good lua refresh. But, you can't just rely on that. It has some flaws, and you don't want to players wait 40-50 seconds everytime you save your script.
- Modifying the NutScript framework core files is not recommended, use Plugins instead, or modify the Schema you are using.
- It is always recommended to make your plugins open-ended for other developers. This can be achieved using
hook.Run
to check if a certain condition is met in anif
statement.
There is some good way to develop some stuff without the need for gamemode refresh. This page will teach you how to develop Nutscript stuff with small lua snippets.
How to make stuffs without Lua Refresh[edit]
EPOE + LuaDev Combination[edit]
EPOE and LuaDev is powerful tools for developers that make your life with server development more easier. But, You need to know this, This tools are granted for all Superadmins in your server. So if you decided to use this tool, Be sure that you're giving Superadmin rank to right person.
EPOE Github: https://github.com/Metastruct/EPOE
Luadev Github: https://github.com/Metastruct/luadev
Pros
You can run and send any lua files from your garrysmod/lua folder. Has Internal Developer Helper Functions
Cons
All Superadmins has access to the Lua Execute Executed Shared/Clientside script will not remain in your server that means the script that you uploaded will not applied to new joined player.
EPOE + Dummy Addon[edit]
Pros
Executed Shared/Clientside script will remain in your server and the script will applied to new joined player. Easy to setup.
Cons
Requires FTP/Remote Connection to modify your stuff (If you're running External Dedicated Server) Does not have any developer helper function.
Character Fiddles[edit]
Character is one of the most important component of the Nutscript Framework.
Inventory Fiddles[edit]
Starting with Inventory[edit]
Items and Inventories are cool, but the Item/Inventory Structure of NS 1.1 is something a novice coder can't understand. If you follow these simple instructions, You'll able to make simple plugins related with Inventory/Items.
This will make your server freak out[edit]
If you're trying to make some kind of Weapon Drop or some kind of Item To World System, Beware of Inventory ID misallocation. The misallocation of the Inventory ID will cause the item verification fail, which can be lead of not-removable items/ghost item in the inventory.
If you're experiencing some weird stuff related with items in your server, You need to take a look at the code in your schema. Especially, You need to search near around the Inventory Allocation Part. That is the part that causing most Inventory fuckups.
The Logical Inventory[edit]
In Nutscript 1.1, there is a place that is the Zero Inventory ID, which is called Logical Inventory. Logical Inventory is very useful. If you're holding items from the player/character, The Logical Inventory temporarily holds the items in Virtual Space. When the Server/Character needs the specific item, The Server/Character withdraws the item from the Logical Inventory. This is how it works.
The best and well-known example of use of Virtual/Logical Inventory of Nutscript 1.1 is Stash. Stash is Permanent Item Storing Solution in Nutscript 1.1. To make this, I need to make Logical Inventory for this plugin.
Hook Examples[edit]
Removing Default Plugin without Editing Framework[edit]
You can always get rid of default plugins with Nutscript's fancy hooks. Don't bother to touch the nutscript framework and don't get hard time with updating it.
local begone = {
chatbox = false,
wepselect = false,
thirdperson = false,
spawnsaver = false,
saveitems = false,
recognition = false,
}
function SCHEMA:PluginShouldLoad(uniqueID)
return begone[uniqueID]
end
Removing Default Information without Editing Framework[edit]
If your schema doesn't need some of nutscript's default information, you can just hide it.
function SCHEMA:CanCreateCharInfo()
return {
faction = true,
}
end