Generating A Resources File for a SWEP or SENT (Linux)

From GMod Wiki

Jump to: navigation, search

Contents

Generating Resource Lua Files

Generating resource Lua files for SWEPS or ENTS you find on garrysmod.com[1] that are to be used in a gamemode can take a long, long time. It usually adds many, many files to the resource object, requiring many lines of Lua, ultimately requiring sometimes hours of searching/listing/typing.

However, there's an easier way in the Linux CLI to search for files and create a full resource file out of it that will execute in seconds using the following stringed commands. First, you should find the extensions you want included into this file. After that, you can edit the code to your liking and run it.

NOTE: This *may* work using a working cygwin installation or something like a Git Bash on Windows. The commands you need to run it are:


Find desired extensions (Optional)

Depending on the placement of the files to be analyzed, you may need to be root (or have sudo access) to list or write files!


Most of these commands should be part of the basic BASH collection, so make sure you're using an up-to-date Linux installation (I'm using Ubuntu 10.04 Server Edition)!

The following command uses the default file-types I've compiled from a SWEP package, and will return all file-types that are not going to be written to the resource file.

find . -name "*.*" | egrep -v --color=NEVER "*.vtf|*.vmt|*.mdl|*.vtx|*.wav|*.mp3|*.vvd|*.phy|*.wd" | awk -F . '{print $NF}' | sort | uniq

Run this command from the command line, appending to everything between the double quotes for the egrep command (where it says "*.vtf|*.vmt|...") using pipe (|) characters in order to prune the files and include only the extensions you want to be added to the resource file. When completed, this command will return all of the file extensions in the folder you're working with (recursively) that will not be added to the resource file.

Common extensions that are shown with this command are .txt and .lua files. You should never include .lua files in your resources file!

When you've included all of the extensions you want to be included into your Lua file, keep the file extensions on hand for the next section.

Compile your resource file

DO NOT perform this command on your entire garrysmod folder! Run this only on the SWEP/SENT pack that you want to create a resource file for! This is to prevent extremely huge resource files.


The first thing you need to do in order to be able to run this command is to go to the root folder of the SWEP/SENT, where, normally, the folders "lua", "materials", "models", etc. reside. This is so the command gets the entire directory tree of the SWEP/SENT you want to make a resource file for.

ls /path/to/the/swep/or/sent/directory

To compile the file, replace the file extensions you chose earlier with the ones in the following command (or, if you want, you may keep the defaults -- it will still work), and run it via the CLI.

find . -name "*.*" | egrep --color=NEVER "*.vtf|*.vmt|*.mdl|*.vtx|*.wav|*.mp3|*.vvd|*.phy|*.wd" | tr '\n' % | sed -e 's/^/\^/1' | sed 's/%/\*%\^/g' | rev | cut -c 2- | rev | sed 's/\.\///g' | sed 's/\.%//g' | sed 's/\*/\")/g' | sed 's/\^/resource.AddFile(\"/g' | tr % '\n' > resource.lua

Make sure to copy the entire line -- it is long, so the likelihood that you miss a part is very high.

After this command runs, it should return directly to the command line. If so, your compiled resource file will be the newly created "resource.lua" file!

Assumptions

Something to make sure about before using this code is that the filenames do not contain the characters '*', '%', or '^'. If they do, you may need to edit either the command or the files; however, the chance of them having any of these is extremely low, usually because they're not generally allowed when making files in the first place.

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox