Giter VIP home page Giter VIP logo

gmod_unstuck's Introduction

Unstuck

A gamemode agnostic solution to Garry's Mod players getting stuck, with Dark RP implementations included.

This unstuck addon is a heavily modified version of another that was posted on facepunch some time ago.

Installation

To install the addon, simply place add this to your addons folder on your server.

Configuration

Configuration is in the sh_unstuck.lua file. In this file, the command can be changed as well as it's prefix. The usergroups that should be treated as having moderator privileges by the addon may also be changed. This setting ensures that no ordinary players may gain access to information that may give them an advantage or an aid to exploit with this addon.

Other more in-depth configuration properties may also be found in this file, such as whether or not the addon should respawn a player if it fails in its attempts to find a suitable location to place the player if they are stuck, and the wait duration between the notification of this and the player being respawned.

A cooldown period may also be set, in seconds, for how often a player may call the command. by default this is set at 5 seconds. The last configurable property is called "Max Depth". This refers to how hard the addon should try to find a location for the player if they are stuck before returning no solution. Increasing this value will allow the addon to find more suitable places to put the player, however it will also increase the computational expense of doing so.

Usage

To notify the addon that a given player is stuck, said player must enter into the chatbox a prefix and a command both defined in the configuration file. By default, the prefixes allow are "!" and "/", and the commands allowed are "stuck" and "unstuck".

If this addon doesn't detect the chat commands used, it is possible that another addon, also listening for chat commands, could be interfering. If this is the case, attempt first to alter the prefix to one known not to be used by another addon. Please note that prefixes may as of currently only be 1 character long.

If the addon fails to locate a suitable place to put the player, as mentioned in the configuration section, the addon will respawn the player, if the configuration allows this.

gmod_unstuck's People

Contributors

heyter avatar jamesxx avatar mrgrim48 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gmod_unstuck's Issues

Missing addon.json file

As stated in the README.md, this addon can be installed by placing it in the server's addons folder, however this will not work if there is no addon.json file.

Client convar "unstuck_debug"

CreateClientConVar( "unstuck_debug", "0" )

The "unstuck_debug" convar should save across sessions, be accessible through Player:GetInfoNum(), and have a description provided through the 5th argument.

If possible the help text should be defined in a variable, as this will allow the future expansion of your addon through the addition of a locale library, allowing the translation of the help text and the chat commands (as described in #2 ).

Having the userdata argument (argument 4) set to true will allow the value of this convar to be networked to the server, allowing the server to discriminate amongst players to whom it should send the debug information, as opposed to having it sent to all players. By doing this, and moving the CreateClientConVar call to the server, you can then monitor who is using the debug feature. This may in the future allow moderation to prevent its exploitation.

In time, this should be replaced, so as to prevent players not needing the debug information to access it, with a concommand that acts like a convar.

Replace massive IF statements with dictionary.

if ( text == "!unstuck" or text == "!stuck" or text == "/stuck" or text == "/unstuck" ) then

This may be replaced with good use of the table.HasValue( table tbl, any value ) function. While not effecient for large tables, it will increase the readability of the code by replacing such an if station with a dictionary search. This would also allow server owners to customize the dictionary to their own language.

Consider the following:

Unstuck.Configuration = {
	Command = {
		Prefix = { "!", "/" },
		String = { "stuck", "unstuck"}
	}
}

The following can then be achieved:

hook.Add("PlayerSay", "Unstuck.PlayerSay", function( ply, text )
	
	text = string.lower( text )

	// Check for the command prefix, terminate call if not present
	if ( not table.HasValue( 
		Unstuck.Configuration.Command.Prefix,
		text:sub(1, 1)
	 ) ) then return end
	
	// check for the command string, terminate call if not present
	if ( not table.HasValue( 
		Unstuck.Configuration.Command.String, 
		text:sub( 2, #text ) 
	) ) then return end

	//if ( text == "!unstuck" or text == "!stuck" or text == "/stuck" or text == "/unstuck" ) then

	/* ... */

Reduce boilerplate code

function Player:UnstuckMessage( ... )
local args = {...}
net.Start( "Unstuck.Message" )
net.WriteTable( args )
net.Send( self )
end
end
if CLIENT then
net.Receive( "Unstuck.Message", function( len )
local msg = net.ReadTable()
chat.AddText( unpack( msg ) )
end)

Whenever a message is sent using this function, the first 3 arguments are always identical, and the 4th argument is always a predetermined string. As such, these first 3 arguments need not be sent and can instead be curried into the client side net message listener function. The 4th argument (string) can be then replaced with an enumeration that also serves as an index in a dictionary table. This will allow server owners to translate the text seen to the main language of their server through the dictionary configuration, as opposed to having to go through all the code manually. Doing this will also drastically reduce the net message's size to about 2 bytes. #

Replace strings with enumerations

net.WriteString( "add" )
net.WriteString( "box" )

This will allow you to send less data while sending the same amount of information. This would also vastly increase your readability, as the name of the enumeration can explain it's effect, while "add" does not. Consider the following:

Unstuck.Enumerations = {
	Debug = {
		OPPERATION_AND = 1,
		NOUN_BOX = 2
	}
}

You can then do the following:

/* ... */
	net.Start( "Unstuck.Debug" )

	//net.WriteString( "add" )
	net.WriteInt( Unstuck.Enumerations.Debug.OPPERATION_ADD, 8 )

	//net.WriteString( "box" )
	net.WriteInt( Unstuck.Enumerations.Debug.NOUN_BOX , 8 )

	net.WriteVector( ply:GetPos()+minBound )
	net.WriteVector( ply:GetPos()+maxBound )
	net.WriteColor( Color(255,150,150) )
	net.Send( ply )
/* ... */

This will show to anyone reading your code that the two enumerations being sent work together. It also means you can send two identical values for different scenarios (eg maybe "add" could mean other things), while having them represented by different variables, allowing anyone reading the code not to have any doubt over which "add" is meant.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.