Chat Commands Basic Framework

-----------------------------------
-- Chat Commands Basic Framework --
-- By Eccid                      --
-- put in:                       --
-- garrysmod/lua/autorun --
-----------------------------------

CHATCOMMANDS = CHATCOMMANDS or {}

--------------- Cutsom Commands ---------------
CHATCOMMANDS.KillCommands = { -- The name of your commands
"!kill", -- What to be typed into chat
"/kill" -- You can add as many to chat as you'd like.
}
CHATCOMMANDS.ExpCommands = {
"!explode",
"/explode"
}

CHATCOMMANDS.RulesCommands = {
"!rules",
"/rules"
}
CHATCOMMANDS.AFKCommands = {
"!afk",
"/afk"
}
--------------- End Cutsom Commands ---------------


--------------- Block Suicide Hook ---------------
-- One of the biggest reasons I set these       --
-- up, is so people could remove themselves     --
-- from a TTT match without putting the blame on--
-- others. Below blocks users from using kill   --
-- or explode in the console, so they have to   --
-- use the chat commands. There's a work around --
-- in place so that you can allow them to use   --
-- the explode command in chat still.           --
--------------------------------------------------
hook.Add( "CanPlayerSuicide", "BlockSuicide", function(ply)
if yesyouasplode == nil or false then -- Checks if the user has used a chat command to explode themself.
ply:PrintMessage( HUD_PRINTTALK, "This command has been disabled, type !kill or !explode into chat instead." )
return false
else
yesyouasplode = false -- If the user used the chat command, it continues to block the command afterward.
return true
end
end )
--------------- End Block Suicide Hook ---------------

--------------- Chat Commands Hook ---------------
hook.Add( "PlayerSay", "TTN Chat Commands", function(ply, text)
--------------- Kill ---------------
if table.HasValue( ccprefix..CHATCOMMANDS.KillCommands, string.lower(text) ) then -- Checks if the text contain matched the premade commands above
if ply:Alive() then -- Can't kill yourself if you're dead, this keeps users from spamming chat with fake death messages.
ply:Kill() -- The Kill Command
PrintMessage( HUD_PRINTTALK, ply:Nick().." killed themself." ) -- Tell everyone they killed themself.
end
return "" -- This is so the command doesn't appear in the chat box.
end
--------------- Explode ---------------
if table.HasValue( CHATCOMMANDS.ExpCommands, string.lower(text) ) then
if ply:Alive() then
yesyouasplode = true -- Allows the user to use the explode command just long enough for the chat command
ply:SendLua([[RunConsoleCommand("explode")]])
PrintMessage( HUD_PRINTTALK, ply:Nick().." exploded themselves." )
end
return ""
end
--------------- Rules ---------------
if table.HasValue( CHATCOMMANDS.RulesCommands, string.lower(text) ) then
ply:ConCommand("ulx motd") -- You can change this to work with whatever admon mod you're using.
return ""
end
--------------- Afk Mode ---------------
-- If any other addon you use has a   --
-- command for !afk, you can delete   --
-- this command.                      --
----------------------------------------
if table.HasValue( CHATCOMMANDS.AFKCommands, string.lower(text) ) then
        if (not IsValid(ply)) or ply:IsSpec() then
            ply:ConCommand("ttt_spectator_mode 0")
PrintMessage( HUD_PRINTTALK, ply:Nick().." removed themselves from AFK mode." )
        else
            ply:ConCommand("ttt_spectator_mode 1")
PrintMessage( HUD_PRINTTALK, ply:Nick().." went AFK." )
end
return ""
end

end )
--------------- End Chat Commands Hook ---------------

No comments:

Post a Comment