Developer Questions

Hey i have been messing around, programming a gamemode in garry’s mod and I have come across a couple questions, i decided to come to this thread again since you guys helped me, and i learned alot from you last time.

  1. Join/Leave messages
    Does anyone know where the join server message “Player <Player> has joined the game” and leave message are located? i was trying to disable them but cant seem to find them.

  2. Base gamemode
    This question sorta stems from my last one, what gamemode does a new gamemode derive from?
    does it have something to do with “Self.Baseclass” function?

  3. Lua beginner
    This might seem like a stupid question but i have only started lua three days ago, what does the “.” period puncuation between a object and another do


  1. Use the ChatText hook client side:
    [lua]hook.Add( “ChatText”, “SuppressJoinLeave”, function( _, _, _, type )

    if type == “joinleave” then return true end

end )[/lua]

  1. I believe that by default your game mode will derive from sandbox. Either way, you can change it in the <gamemodename>.txt file, the value of “base” can be changed to any game mode you want (I’d keep it on “base”)

  2. You can use . to index a table easily (it looks neater), so that
    [lua]tab.Variable = 123[/lua]
    is the same as
    [lua]tab[ “Variable” ] = 123[/lua]
    Note that it will treat your index as a string, if you want to index it using a variable you must use squared brackets.

Oh i see, Thanks man ive been researching this all day haha

[editline]23rd August 2014[/editline]

The code

hook.Add( "ChatText", "SuppressJoinLeave", function( _, _, _, type )

	if type == "joinleave" then return true end

end )

doesn’t seem to work, i have put it in the clientside file.

Read the note:

Use PlayerSay as a hook instead if you want player chat cmds

[editline]23rd August 2014[/editline]

Or did you want to show some message on player join/leave?

When you join a server a message shows up “Player <Player> has joined the game” and also when a player leaves, i think the base gamemode put this message in whenever a player connects, it also does not show up in the console which leads me to believe it is a function in the client-side file, i would like this message disabled, i have tryed hooks and research it but nothing seems to work.

-Ninja’d by OP

I wana update this thread, it seems that when i try to hook the SuppressJoinLeave function it does not recognize “Player <Player> has joined the game” as a event to trigger the hook. Any suggestions?
edit: The message doesnt even seem to show up in the console.

By default, it should be base. However you may not have GAMEMODE.BaseClass initialized unless you Derive… I show how this derive is done in sh_init.lua, check it out.

If you want something to make development easier: Please look into AcecoolDev_Base, a skeletonized-developer-base game-mode which features an autoloader ( to ignore ever needing to use include or AddCSLuaFile ever again, plus console commands to force the game-mode to refresh “loadgm”, and to easily changelevel “relevel/remap <Current Map OR optionally mapname> <Current GM OR optionally gamemode>” ), many new and useful hooks, many helper-functions, many metatable “classes”, and much more.

My networking system ( lightweight version ) will be included in the near future along with a few other nice surprises.

It is recommended that you use a form of GIT/SVN software to allow for easy updating.