Text Based plugin help

I want to try to create a small text based plugin.

etc: help guide for new admins, if they type !help in chat, a list with avaiable commands pops up in their screen in their chat. (That was just a simple example)

Thi could be pretty mutch anything, but i got really no idea how to start.

Is there anyone who could help out ? maby write down an example line, or post down some links that i can read on??

ive been trying to google myself but well yeh, since im posting here im sure you guessed i didnt find anything useful haha xD

Edit: Basically what im looking for is sending and recieving info. from client to server, from server to client. (only text in the chat)

i just realized this could be more advanced than i thought xDD

i guess i need to make a clientside config, a server side config, and also the .lua with the recieve messages…

hook.Add(“PlayerSay”,“Test”, function(ply, text, toteam)
if ( string.sub( text, 1, 5 ) == “!test” ) then
return “”

Should get you started.

thanks a lot m8 :smiley:
btw if i remove ply and insert txt shoud that give a message to the player instead of killing him?

so far i have made this :smiley:

this is my first attempt on making any kind of lua code xDDDD

i cant get it to work on my server :frowning:

anyone know anything how i might get this to work?

When is the chatcommand function called, and look into sending net messages to send to client from server

Here’s how I do mine: https://dl.dropboxusercontent.com/u/26074909/tutoring/chat_commands/chat_commands.lua.html

If you use the other method, I’d recommend the use of string.lower( ) around the incoming string to ensuifre you don’t need to run tons of checks someone capitalizes one or more of the letters.

With mine, it simply redirects ! and / commands directly to console commands.

hmmm allright thanks ace :smiley: im gonna takwe a look at yours when i come home.

but when i have finished this project. how would i install it??

it itr just put it in: grrysmod/lua and run the openscript command on serverr or is there some other ways?

Hello Kevinky,

The best way to do it would be to create the following folder structure in your server’s add-ons directory:


If you place it in there it’ll auto-run when the server starts. Of course make sure you’ve added any client-side lua files by putting : AddCSLuaFile(“filename.lua”) : at the top of the server side file.

You may want to use ‘Net Receive’ and ‘Net Send’, this is an easier way to send commands, as well as VGUI elements. However you have to implement it serverside and clientside.

Net Receive: http://wiki.garrysmod.com/page/net/Receive
Net Send: http://wiki.garrysmod.com/page/net/Send

Code Example:

[lua]function chatCommand( ply, text, public )
if (string.sub(text, 1, 4) == “!die”) then ply:Kill() – --if the first 4 letters are !die, run the kill command
return(false) --Does not display the command in the textbox when it is typed.
hook.Add( “PlayerSay”, “chatCommand”, chatCommand ); – Bind to playersay hook[/lua]

Need help? Just PM me. (I’m on on an intermediate skill level for GLua, however I like to help people while I can)

allright thanks everyone for you’r help :smiley: i will try my best when i come home. and this code ive made is my first attempt making anything in lua :stuck_out_tongue: iim in early begining stage myself :stuck_out_tongue: altho i know c++9, phyton, java and so on :stuck_out_tongue:

but lemmie that one is for killing urself right… but what i am looking for is that you etc type in !help in chat, and then the server gives u a list with the avaiable commands u have. im not trying to make it execute commands. i only want it to give the text info to players about this and that.


so what would it look like if the player were only going to recieve text back from the server?

Same principle, you just need a VGUI window, to display a DLabel, it’s easy enough done. I’ll PM you my steam.


Here is an example of net libary:

[lua]–[[ Server side ]]–
util.AddNetworkString( ‘’ )

hook.Add( ‘ShowSpare2’, ‘helpmenu’, function( ply )
net.Start( ‘TestIt’ )
net.Send( ply )
net.WriteString( “You Pressed F4, well done you actually accomplished something…” )
end )

–[[ Client Side ]]–

net.Receive( ‘TestIt’, function ()
local COL1 = Color( 255, 0, 0 )
local COL2 = Color( 0, 255, 0 )
chat.AddText( COL1, "[Server] ", COL2, net.ReadString() )[/lua]

[lua]local commands = {

local command_list = {
Name = “!example”,
Desc = “This does this and this”

local command_color = Color(150, 40, 27); – Color that the command tag is

if SERVER then
– Networking –

hook.Add("PlayerSay", "admin.commands", function(ply, txt, team)
	if (table.HasValue(commands, string.sub(txt, 1, 5)) and (ply:IsAdmin()) then -- If they're an admin and it's equal to any value in the list
		net.Start("admin_sendverification"); -- Network to client

net.Receive(“admin_sendverification”, function(len, CLIENT)
for _, command in ipairs(command_list) do – For each entry in the command_list table…
chat.AddText(command_color, “[Commands]”, Color(255, 255, 255), command.Name … " " … command.Desc); – We do a chat print with their name and description

ooooooooh :DD
i need to try this :smiley:
so helpful <3 thanks :smiley:

hi :S bad news. i trried to instal the scripp, sadly it didnt work, i watched loads of tutorials how to instal it, i also followed the simple steps from semajnad but that didnt work either :S i rly dont know why this doesnt work :S

sadly i didnt have time to do so much on my pc last day since i was working for so long lemmie but, today if we both got time. i was thinking of taking a chat with you maby we can sort this problem out together (if you got time, and if you want to help) :stuck_out_tongue:

i wish i had the knowledge that you guys have :stuck_out_tongue:

but sadly i dont. and i am trying my best to learn the basic understanding of lua. and theese scripts you guys prepared also help me understanding. thanks for all of your time guys !!! :smiley:
i really appreciate it :slight_smile:

(sry for my bad english btw… i know some peoples in this forum reacts on it)

PS: sry for my typos. i saw it now :stuck_out_tongue: (instal, scripp and so on)

If I remember correctly, returning false does jack shit, you need to return an empty string.

but if it is like what you say. what will the difference be?? is it enough to bug it up so it wont work or…?

Was it mine that didn’t work? I did it in a macs wordpad at school and wasn’t able to test it. If so, any errors?

Read it yourself, you’ll see it won’t because you have syntax errors and incorrect usage of functions

both you and the one above didnt work. i instaled it like: gmod/lua/autorun

then used the luarun command on server just in case agter server restart. not working

i tested: !help /help !example /example