Chat Solution

Hi there what I am needing now is a chat system that is pretty much stand alone in which I can add to my current game mode.

Main feature needed:

Ability to recognize chat commands and route the chat to a specific destination.

Example: // message will send a message to everyone and the message will have a [Global] Tag before the persons name and message.
Typing normally will give a message to only those players in a certain radius of the sender.

Game mode has been derived from base.

Go learn lua http://wiki.garrysmod.com/?title=Lua_Tutorial_Series then you might actually get somewhere.

For once I actually agree with the retard above, no one will make this for free. Learn lua yourself or you won’t get anywhere with this.


(User was banned for this post ("Flaming" - UberMensch))

This was made by someone before i think, one sec i will get it again ( i think it was IRZilla who made it )

[editline]13th November 2010[/editline]

Yep : Place in lua/includes/modules


local pcall = pcall;
local ErrorNoHalt = ErrorNoHalt;
local pairs = pairs;
local player = player;
local string = string;
local table = table;
local hook = hook;

module( "chatcommand")

local Commands = {}
function Add( name, func )
	Commands[ name ] = func
end

function Call( name, pl, args )
	local func = Commands[ name ]
	if (func) then
		local b, res = pcall( func, pl, name, args )
		if (!b) then
			Commands[ name ] = nil
			ErrorNoHalt( res )
			return false
		end
		return true
	end
end

function FindPlayer( name )
	for _, ply in pairs( player.GetAll() ) do
		if (string.find( ply:Nick(), name ) || (name == ply:Nick())) then return ply end
	end
end

local function PlayerSay( ply, text, toall)
    

	local first = string.sub( text, 1, 1 )
	if (first == "/") then
		local str = string.sub( text, 2 )
		local args = string.Explode( " ", str )
		local com = args[1]
		table.remove( args, 1 )
		local b = Call( com, ply, args )
		if (b) then return "" end
	end
	
	

end
hook.Add( "PlayerSay", "CHATCOMMANDS", PlayerSay )

[lua]
module( “chatcommand”, package.seeall )
[/lua]

:saddowns:

? What’s wrong?

package.seeall :frowning:

I can use package.seeall because he is using alot of librarys, want me to fix ?

[editline]13th November 2010[/editline]


local pcall = pcall;
local ErrorNoHalt = ErrorNoHalt;
local pairs = pairs;
local player = player;
local string = string;
local table = table;
local hook = hook;

module( "chatcommand")

local Commands = {}
function Add( name, func )
	Commands[ name ] = func
end

function Call( name, pl, args )
	local func = Commands[ name ]
	if (func) then
		local b, res = pcall( func, pl, name, args )
		if (!b) then
			Commands[ name ] = nil
			ErrorNoHalt( res )
			return false
		end
		return true
	end
end

function FindPlayer( name )
	for _, ply in pairs( player.GetAll() ) do
		if (string.find( ply:Nick(), name ) || (name == ply:Nick())) then return ply end
	end
end

local function PlayerSay( ply, text, toall)
    

	local first = string.sub( text, 1, 1 )
	if (first == "/") then
		local str = string.sub( text, 2 )
		local args = string.Explode( " ", str )
		local com = args[1]
		table.remove( args, 1 )
		local b = Call( com, ply, args )
		if (b) then return "" end
	end
	
	

end
hook.Add( "PlayerSay", "CHATCOMMANDS", PlayerSay )


fixed :wink: