Posted 31 October 2015 - 07:54 AM
cPrint API: pastebin get QP8yFSPW cprint
PrintShop script: pastebin get juQeX2fS printshop
People keep complaining about the difficulty of creating printed books. It occurred to me that Command Computers could be used to "cheat", making the process much simpler.
So here we have two bits of code: an API that returns terminal objects that can be converted into books, and a script that uses said API to offer books to players.
Returns a terminal object that you can term.redirect() to. Dimensions are 25 columns by an effectively unlimited number of rows.
These objects offers two additional functions over regular ones:
book.printBook([string target], [number amount])
If a target is specified (eg "@p", which would refer to whoever's closest to the computer), places a printed book into their inventory. If no target is specified, the book goes into a chest above the computer. Be aware that this may destroy the two blocks which were previously above it, if any were present!
If an amount is specified, that many copies of the book will be generated. Defaults to one.
book.setLore([string tooltip])
Sets the tooltip that will be used if the book is printed.
For example:
When first run, PrintShop will download a small list of books for you (along with the cPrint API, if it's missing):
It'll then display this list on-screen for users to pick from. Editing "printshop.cfg" allows you to change the selection to suit yourself.
As regular players cannot directly interact with Command Computers, if you wish to offer books to your regular users, you will need to connect the computer to an Advanced Monitor (3x2 blocks minimum) and run it through that:
When users attempt to print books, they will be charged 5 XP levels for each (taken from whoever's standing closest to the computer when it produces the order). You can specify a different amount if you wish.
After each print job, the printer will also "cooldown" for a default period of 30 seconds. These two mechanisms are intended to prevent rogue players from using the system to generate copious amounts of books.
If just using the script for yourself, or if you simply wish to do without these limitations, you'd just set them to 0 at the command line. Eg, by running the script with:
1.0.0
Initial release.
2015/11/02
cPrint 1.0.1
Bug fixes.
PrintShop script: pastebin get juQeX2fS printshop
People keep complaining about the difficulty of creating printed books. It occurred to me that Command Computers could be used to "cheat", making the process much simpler.
So here we have two bits of code: an API that returns terminal objects that can be converted into books, and a script that uses said API to offer books to players.
cPrint API Usage
cprint.newPrintableBook([string book title]) => table book terminal objectReturns a terminal object that you can term.redirect() to. Dimensions are 25 columns by an effectively unlimited number of rows.
These objects offers two additional functions over regular ones:
book.printBook([string target], [number amount])
If a target is specified (eg "@p", which would refer to whoever's closest to the computer), places a printed book into their inventory. If no target is specified, the book goes into a chest above the computer. Be aware that this may destroy the two blocks which were previously above it, if any were present!
If an amount is specified, that many copies of the book will be generated. Defaults to one.
book.setLore([string tooltip])
Sets the tooltip that will be used if the book is printed.
For example:
os.loadAPI("cprint")
local myBook = cprint.newPrintableBook("This is my book")
local oldTerm = term.redirect(myBook)
term.setTextColour(colours.red)
print("Hello, world!")
print()
term.setTextColour(colours.black)
print("This is my great new book!")
term.redirect(oldTerm)
myBook.setLore("by Bomb Bloke")
myBook.printBook("@p")
PrintShop Script Usage
printshop [XP cost] [cooldown]When first run, PrintShop will download a small list of books for you (along with the cPrint API, if it's missing):
pastebin get CWWeJk9g printshop.cfg
It'll then display this list on-screen for users to pick from. Editing "printshop.cfg" allows you to change the selection to suit yourself.
As regular players cannot directly interact with Command Computers, if you wish to offer books to your regular users, you will need to connect the computer to an Advanced Monitor (3x2 blocks minimum) and run it through that:
monitor <monitorside> printshop
When users attempt to print books, they will be charged 5 XP levels for each (taken from whoever's standing closest to the computer when it produces the order). You can specify a different amount if you wish.
After each print job, the printer will also "cooldown" for a default period of 30 seconds. These two mechanisms are intended to prevent rogue players from using the system to generate copious amounts of books.
If just using the script for yourself, or if you simply wish to do without these limitations, you'd just set them to 0 at the command line. Eg, by running the script with:
printshop 0 0
Version History
2015/10/311.0.0
Initial release.
2015/11/02
cPrint 1.0.1
Bug fixes.
Edited on 02 November 2015 - 02:23 AM