This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Shnupbups's profile picture

[ImmibisPeripherals] CCCustomCommands BETA 1.0 - Make Custom Commands for your Server! (Using regular chat)

Started by Shnupbups, 19 March 2013 - 03:17 PM
Shnupbups #1
Posted 19 March 2013 - 04:17 PM
Ever wanted to make your own commands to use for your server? Like /gamemode and /say, but your OWN ones? Well, now you can with:
CCCustomCommands By Shnupbups100 (yes I know it's abbreviated CCCC)

This awesome tool allows you to make your own commands run via chat like all the vanilla ones! With CC code! How awesome!? It requires Immibis Peripherals' adventure map interface and a command block set up in any fashion around a computer.

How to use:

Spoiler
  1. On first use it will create the 'Commands' folder.
  2. CTRL-T the program.
  3. Make a file in the Commands folder and call it whatever you want, it doesn't need a '/'.
  4. If you want to know who ran the command, capture the arguments. The first argument is the person who ran the command.
  5. Code what you want the command to do using the Adventure map interface's API and the program's own API. (see Documentation section)
  6. Save, exit and run CCCustomCommands.
  7. When you type '/<nameOfCommand>' in the chat, it will execute the program! Hooray!
  8. ????
  9. PROFIT?!

Note: eventually you will be able to create commands within the program itself

Documentation:
Spoiler
runCmd(<cmd>,<user>)
More for internal usage, but used to run commands a user has made. <cmd> is the command name (without the '/' or the location, just the command name) and <user> is the user who ran it.

cmdBlockRun(<side>,<cmd>,[player])
Used to run vanilla commands through the command block on <side>. <cmd> is the command to use (the whole thing, e.g. "say I am awesome") and [player] is an optional argument which, when used, will replace all occurrences of '&amp;p' in <cmd> with itself, so you can direct commands on players. e.g.

cmdBlockRun("left","tell &amp;p &amp;p is awesome","Shnupbups100")
would output in the chat, to only Shnupbups100,

@ whispers to you: Shnupbups100 is awesome

Note: you do not need the name of CCCC and a '.' before function names as they are being used from inside the CCCC program.

Examples:
SpoilerTeamFortress 2 'Medic' command example:
Spoiler
args = {...}
local chance = math.random(6)
if chance == 1 then
cmdBlockRun("left","say &amp;p: Medic!",args[1])
elseif chance == 2 then
cmdBlockRun("left","say &amp;p: MEDIC!",args[1])
elseif chance == 3 then
cmdBlockRun("left","say &amp;p: Doctor!",args[1])
elseif chance == 4 then
cmdBlockRun("left","say &amp;p: DOCTOR!",args[1])
elseif chance == 5 then
cmdBlockRun("left","say &amp;p: I need a medic over here!",args[1])
elseif chance == 6 then
cmdBlockRun("left","say &amp;p: HELP!",args[1])
end

'Awesome' command example:
Spoiler
args = {...}
cmdBlockRun("left","say &amp;p is awesome!",args[1])
'Murder' command example:
Spoiler


args = {...}
cmdBlockRun("left","tell &amp;p Whom are we murdering, &amp;p? (Say after a slash, like a command)",args[1])
local _,user,msg = os.pullEvent("chat_message")
if user == args[1] and string.byte(msg) == 47 then
local msg = string.gsub(msg,"/","",1)
local adv = peripheral.wrap("right")
local pl = adv.getPlayerByName(msg)
if pl ~= nil then
  if pl.getGamemode() ~= 1 then
   pl.damage(50)
   cmdBlockRun("left","tell &amp;p The deed is done, my lord &amp;p.",args[1])
  else
   cmdBlockRun("left","tell &amp;p The deed could not be done, for the player you wish to kill is in creative, my lord &amp;p.",args[1])
  end
else
  cmdBlockRun("left","tell &amp;p That player could not be found...",args[1])
end
else
cmdBlockRun("left","tell &amp;p Invalid answer.",args[1])
end

Download:
SpoilerGet it here or by typing:

pastebin get qL9Ed16V startup
I recommend you save it as startup. DO NOT SAVE IT AS 'commands'! Please read how to use and documentation before using!
CODE:
Spoiler

function runCmd(cmd,user)
shell.run("commands/"..cmd,user)
end
function cmdBlockRun(side,cmd,player)
local cmdB = peripheral.wrap(side)
if player then
  local cmd = string.gsub(cmd,"&amp;p",player)
  cmdB.setCommand(cmd)
else
  cmdB.setCommand(cmd)
end
cmdB.runCommand()
cmdB.setCommand("")
end
if not fs.exists("commands") then
fs.makeDir("commands")
end
while true do
local _,user,cmd = os.pullEvent("chat_message")
print(user.." typed "..cmd)
if string.byte(cmd) == 47 then
  local cmd = string.gsub(cmd,"/","",1)
  if fs.exists("commands/"..cmd) then
   print("Valid command! Running...")
   runCmd(cmd,user)
  else
   print("Invalid command!")
  end
else
  print("Not a command!")
end
end



Use this however you like!
PixelToast #2
Posted 19 March 2013 - 04:31 PM
o-o i made something similar
for example
!jet infinikiller64 1000
will spawn 1000 tnt explosions on my feet sending me VERRY high up
R167 #3
Posted 19 March 2013 - 04:32 PM
looks cool. Wish i cold get my friends to use this on their server
Shnupbups #4
Posted 19 March 2013 - 04:40 PM
o-o i made something similar, but it responded to chat comands
for example
!jet infinikiller64 1000
will spawn 1000 tnt explosions on my feet sending me VERRY high up
This IS responding to chat commands…
EDIT: Your new avatar is cool…
PixelToast #5
Posted 19 March 2013 - 05:13 PM
lol thanks, people say i change my avatar WAAY too often, i might keep this one for awhile

you arent localizing tArgs in the examples
and in some cases it isnt needed
cmdBlockRun("left","say &amp;p is awesome!",({...})[1])
Shnupbups #6
Posted 19 March 2013 - 06:01 PM
you arent localizing tArgs in the examples
and in some cases it isnt needed
cmdBlockRun("left","say &amp;p is awesome!",({...})[1])
Eh, I never localise tArgs. and I know it isn't needed, I just like using it sometimes more than that.