Eccid

Chat Commands Basic Framework

Jul 21st, 2013
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.57 KB | None | 0 0
  1. -----------------------------------
  2. -- Chat Commands Basic Framework --
  3. -- By Eccid                      --
  4. -- put in:                       --
  5. -- garrysmod/lua/autorun     --
  6. -----------------------------------
  7.  
  8. CHATCOMMANDS = CHATCOMMANDS or {}
  9.  
  10. --------------- Cutsom Commands ---------------
  11. CHATCOMMANDS.KillCommands = { -- The name of your commands
  12. "!kill", -- What to be typed into chat
  13. "/kill" -- You can add as many to chat as you'd like.
  14. }
  15. CHATCOMMANDS.ExpCommands = {
  16. "!explode",
  17. "/explode"
  18. }
  19.  
  20. CHATCOMMANDS.RulesCommands = {
  21. "!rules",
  22. "/rules"
  23. }
  24. CHATCOMMANDS.AFKCommands = {
  25. "!afk",
  26. "/afk"
  27. }
  28. --------------- End Cutsom Commands ---------------
  29.  
  30.  
  31. --------------- Block Suicide Hook ---------------
  32. -- One of the biggest reasons I set these       --
  33. -- up, is so people could remove themselves     --
  34. -- from a TTT match without putting the blame on--
  35. -- others. Below blocks users from using kill   --
  36. -- or explode in the console, so they have to   --
  37. -- use the chat commands. There's a work around --
  38. -- in place so that you can allow them to use   --
  39. -- the explode command in chat still.           --
  40. --------------------------------------------------
  41. hook.Add( "CanPlayerSuicide", "BlockSuicide", function(ply)
  42.     if yesyouasplode == nil or false then -- Checks if the user has used a chat command to explode themself.
  43.         ply:PrintMessage( HUD_PRINTTALK, "This command has been disabled, type !kill or !explode into chat instead." )
  44.         return false
  45.     else
  46.         yesyouasplode = false -- If the user used the chat command, it continues to block the command afterward.
  47.         return true
  48.     end
  49. end )
  50. --------------- End Block Suicide Hook ---------------
  51.  
  52. --------------- Chat Commands Hook ---------------
  53. hook.Add( "PlayerSay", "TTN Chat Commands", function(ply, text)
  54. --------------- Kill ---------------
  55.     if table.HasValue( ccprefix..CHATCOMMANDS.KillCommands, string.lower(text) ) then -- Checks if the text contain matched the premade commands above
  56.     if ply:Alive() then -- Can't kill yourself if you're dead, this keeps users from spamming chat with fake death messages.
  57.         ply:Kill() -- The Kill Command
  58.         PrintMessage( HUD_PRINTTALK, ply:Nick().." killed themself." ) -- Tell everyone they killed themself.
  59.     end
  60.     return "" -- This is so the command doesn't appear in the chat box.
  61.     end
  62. --------------- Explode ---------------
  63.     if table.HasValue( CHATCOMMANDS.ExpCommands, string.lower(text) ) then
  64.     if ply:Alive() then
  65.         yesyouasplode = true -- Allows the user to use the explode command just long enough for the chat command
  66.         ply:SendLua([[RunConsoleCommand("explode")]])
  67.         PrintMessage( HUD_PRINTTALK, ply:Nick().." exploded themselves." )
  68.     end
  69.     return ""
  70.     end
  71. --------------- Rules ---------------
  72.     if table.HasValue( CHATCOMMANDS.RulesCommands, string.lower(text) ) then
  73.         ply:ConCommand("ulx motd") -- You can change this to work with whatever admon mod you're using.
  74.         return ""
  75.     end
  76. --------------- Afk Mode ---------------
  77. -- If any other addon you use has a   --
  78. -- command for !afk, you can delete   --
  79. -- this command.                      --
  80. ----------------------------------------
  81.     if table.HasValue( CHATCOMMANDS.AFKCommands, string.lower(text) ) then
  82.         if (not IsValid(ply)) or ply:IsSpec() then
  83.             ply:ConCommand("ttt_spectator_mode 0")
  84.             PrintMessage( HUD_PRINTTALK, ply:Nick().." removed themselves from AFK mode." )
  85.         else
  86.             ply:ConCommand("ttt_spectator_mode 1")
  87.             PrintMessage( HUD_PRINTTALK, ply:Nick().." went AFK." )
  88.          end
  89.         return ""
  90.     end
  91.  
  92. end )
  93. --------------- End Chat Commands Hook ---------------
Advertisement
Add Comment
Please, Sign In to add comment