Garry's Mod

Garry's Mod

Not enough ratings
How To Make Custom STCuffs
By SweptThr.one
This guide will walk you through the process of creating your own type of handcuffs for my cuffs addon, STCuffs.
Get STCuffs here: https://steamhost.cn/steamcommunity_com/sharedfiles/filedetails/?id=3244480000
   
Award
Favorite
Favorited
Unfavorite
Creating Custom Cuffs
This section will walk you through the basics of creating your own cuffs

1. Create a new weapon file
Create a new Lua file in the weapon directory of your choice. This will be either within an addon folder, a gamemode folder, or just your root garrysmod folder. In case you don't know, this folder exists at lua/weapons/. An example file for our purposes is lua/weapons/st_custom_cuffs.lua

2. Fill out the file with the template
Fill your new file with the following template. These values are used for the police restraints.
AddCSLuaFile() SWEP.Base = "st_rope_cuffs" -- do not change this SWEP.Category = "STCuffs" SWEP.PrintName = "Custom Restraints" SWEP.Spawnable = true SWEP.CuffMat = "models/props_combine/metal_combinebridge001" SWEP.RopeMat = "blue" SWEP.TimeToCuff = 1 SWEP.RopeColor = Color( 255, 255, 255 ) SWEP.BreakoutRate = 1 SWEP.RecoverRate = 0.1 SWEP.ReleaseRate = 0.5 SWEP.CanBlindfold = false SWEP.CanGag = false

3. Modify the values to your heart's content
Most of the values in this template should be self-explanatory, but there are some exceptions.
You might notice that "RopeMat" is a short string instead of a full file path. STCuffs uses a handful of predefined materials for ropes. The following materials are predefined:
  • rope
  • cable
  • red
  • green
  • blue
  • white
  • laser
  • electric
  • plasma
  • physics
  • hydra
Most of these are taken from the game's list of materials for the Rope tool.
If you want to use a custom material, read the next section.

CuffMat can be any material, just supply a path.

BreakoutRate is added to the cuff's "breakout value" every time a cuffed player clicks.
RecoverRate is subtracted from the cuff's breakout value ten times per second.
ReleaseRate is added to the cuff's breakout value every tick a player is releasing the cuffed player.

These are the values used for the default set of cuffs included in STCuffs:
-- rope cuffs SWEP.BreakoutRate = 5 SWEP.RecoverRate = 0.1 SWEP.ReleaseRate = 1
-- elastic cuffs SWEP.BreakoutRate = 2.5 SWEP.RecoverRate = 0.1 SWEP.ReleaseRate = 1
-- police cuffs SWEP.BreakoutRate = 1 SWEP.RecoverRate = 0.1 SWEP.ReleaseRate = 0.5
Using Custom Rope Materials
This section will help you add another rope material to use

As discussed in the previous section, STCuffs uses predefined materials for ropes. This is because these materials are used so often. Doing it this way helps improve performance but makes it slightly harder to use custom materials. You are expected to have this custom material ready.

That being said, it's still very simple.

Create a new shared autorun Lua file. Once again, this can be either in an addon folder, gamemode folder, or in your root garrysmod folder. For the sake of demonstration, let's make a new file at lua/autorun/mycustomcuffmaterials.lua and put the following in it:

STCuffs_Materials = STCuffs_Materials or {} -- very important, do not modify STCuffs_Materials.customRope = Material( "custom/rope/material" ) STCuffs_Materials.secondCustom = Material( "custom/rope/second" )

That's it! You can now use "customRope" and "secondCustom" as your RopeMat for any custom handcuffs weapon.
Useful Functions for Developers
This section simply states some custom functions developers can use

As mentioned in the description of STCuffs, it's relatively barebones. You are encouraged to extend it to your needs, and this guide assumes you know how to do that and are looking for custom functions.

Functions
STCuffs creates some custom functions on the player metatable. These functions are all shared but may only do anything when called on the server.

Player:StartDragging( Player playerToDrag, Weapon _ )
Forces Player to start dragging playerToDrag. The Weapon argument is not actually used at all.

Player:StopDragging( Player playerToStopDragging )
Forces Player to stop dragging playerToStopDragging.

Player:BreakOutOfCuffs()
Forces Player to break out of their cuffs.

Player:CuffGag()
Gags the player.

Player:CuffUnGag()
Ungags the player.

Player:CuffBlindfold()
Blindfolds the player.

Player:CuffUnBlind()
Unblinds the player.

NWVars
STCuffs uses NWVars for various reasons. I know these are generally frowned-upon, but it's what I used. You are expected to know how to access NWVars.

Bool STCDragged
Whether the player is being dragged.

Entity STCDragger
The player this player is being dragged by.

Bool STCGagged
Whether the player is gagged.

Bool STCBlind
Whether the player is blindfolded.

Miscellaneous
Sometimes I use neither of the above techniques.

Weapon.IsRestraints - Boolean, Shared
Whether the weapon is restraints, which restrict the player who has them. This is only set on st_cuffed. This is provided for extensibility in case you want to create a custom Restrained weapon or something.

Player.Captives - Table, Server
A list of players the Player is dragging, stored as a series of Player = Boolean pairs where the boolean is always true. Setting it to false doesn't actually change anything, but it's provided like this to improve performance if you want to search for a player in the table.
1 Comments
Nate 11 May, 2024 @ 11:51am 
wow! very detailed guide! so cool!!