Page 1 of 1

Writable Books...

PostPosted: Tue Feb 10, 2015 11:06
by TenPlus1
For players wanting to write inside books and have other players read them, here is the latest book code that has been submitted to minetest_game as a feature request... <fingers crossed> it will be included in default minetest :)

Note: VanessaE's latest homedecor mod has writable books also but the following code word-wraps books when being read.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
--= Book (use to read or write to)

minetest.register_craftitem(":default:book", {
   description = "Book",
   inventory_image = "default_book.png",
   groups = {book=1},
   stack_max = 1,
   on_use = function(itemstack, user, pointed_thing)
      local player_name = user:get_player_name()
      local data = minetest.deserialize(itemstack:get_metadata())
      local title, text, owner = "", "", player_name
      if data then
         title, text, owner = data.title, data.text, data.owner
      end
      local formspec
      if owner == player_name then
         formspec = "size[8,8]"..default.gui_bg.. -- default.gui_bg_img..
            "field[0.5,1;7.5,0;title;Title:;"..
               minetest.formspec_escape(title).."]"..
            "textarea[0.5,1.5;7.5,7;text;Contents:;"..
               minetest.formspec_escape(text).."]"..
            "button_exit[2.5,7.5;3,1;save;Save]"
         minetest.show_formspec(user:get_player_name(), "default:book", formspec)
      else
         formspec = "size[8,8]"..default.gui_bg.. -- default.gui_bg_img..
            "button_exit[7,0.25;1,0.5;close;x]"..
            "label[0.5,0;"..minetest.formspec_escape(title).."]"..
            "label[0.5,0.5;by "..owner.."]"..
            "textarea[0.5,1.5;7.5,7;text;;"..
               minetest.formspec_escape(text).."]"
         minetest.show_formspec(user:get_player_name(), "default:lockedbook", formspec)
      end
   end,
})

minetest.register_on_player_receive_fields(function(player, form_name, fields)
   if form_name ~= "default:book" or not fields.save then
      return
   end
   local stack = player:get_wielded_item()
   if minetest.get_item_group(stack:get_name(), "book") == 0 then
      return
   end
   local data = minetest.deserialize(stack:get_metadata())
   if not data then data = {} end
   data.title, data.text, data.owner =
      fields.title, fields.text, player:get_player_name()
   stack:set_metadata(minetest.serialize(data))
   player:set_wielded_item(stack)
end)

Re: Writable Books...

PostPosted: Thu Feb 12, 2015 15:52
by davidthecreator
That would make a good thing to default I also hope it will get adder to default game

Re: Writable Books...

PostPosted: Thu Feb 12, 2015 20:02
by Krock
A good idea :)

Re: Writable Books...

PostPosted: Fri Feb 13, 2015 10:14
by TenPlus1
...and if you want to re-use a book that someone else gave you, place book in crafting with 1 white dye to erase contents and return an empty book :)

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_craft({
   output = 'default:book',
   recipe = {
      {'default:book', 'dye:white', ''},
   },
})

Re: Writable Books...

PostPosted: Fri Mar 06, 2015 05:23
by Sokomine
Nice idea! Hope this gets merged. So far, books are only craft items. They could be used for messages with this change.

Re: Writable Books...

PostPosted: Mon May 04, 2015 20:21
by sofar
Can you add a "copy book" recipe? Where you combine a written book and an empty book to create a second written book (and obviously retain the original one as well)?

Re: Writable Books...

PostPosted: Tue May 05, 2015 10:43
by twoelk
Sokomine wrote:Nice idea! Hope this gets merged. So far, books are only craft items. They could be used for messages with this change.


hm maybe a guestbook function?
So that contents can be added but not easily deletet.
Like the signs on Mt.Meru on Landrush server that state who managed it to the top.
Thinking further in this direction there could be an achievement reward triggered by adding an entry to a guestbook.
This could be made into some gameplay function like "collect 10 mountaineer badges" or "visit 5 touristic highlights on this server".

Of course such a guestbook could also be used in the traditionall way to collect praise or feedback for something ;-P

ps. I could use one for my Northern Inn and I could imagine Bulldog on VE-creative would be delighted to use them in in his growing eat and sleep network. :-D

Re: Writable Books...

PostPosted: Tue May 05, 2015 14:42
by Dopium
+1 without a doubt this would add another element to mp survival gameplay. Even though it can be a mod, would be a nice addition to the default game. Books are not much use if you can't write in them :)

Re: Writable Books...

PostPosted: Wed May 06, 2015 21:44
by red
I took all the code for the books in this topic and made it in to a mod.Here is the zip file.
Edit
divieded books into locked books and books. Locked book can olny be edited by the player that wrote them and books can be edited by any one. New download here
Old download here

Re: Writable Books...

PostPosted: Thu May 07, 2015 18:08
by domtron vox
twoelk wrote:hm maybe a guestbook function?
So that contents can be added but not easily deletet.


This could be done without the player actually editing the book. Have a book on a lecturn that is readable only but has a button at the top that says "add name". clicking on said button would append the character's name if it isn't already in the book.

twoelk wrote:Of course such a guestbook could also be used in the traditional way to collect praise or feedback for something ;-P

I see this being done with a "mail drop" type chest. Get a book. Write suggestions and feedback. Drop it in the mail drop chest.

Re: Writable Books...

PostPosted: Thu May 07, 2015 18:48
by twoelk
hm , press a button? hmm

Ha, I could imagine some book of rules that is presented at first join.
"press the button if you have read and understood the rules"
and the name gets added to a list.
Breaking the rules gets the name erased so on the next join one is forced to read the rules again.

hm ...
or multiple buttons for multiple choice tests ...
or dialog trees
or ...

Re: Writable Books...

PostPosted: Sat May 09, 2015 12:43
by red
Modified the source code for the mod to make the default book editable by anyone and make a locked book that can olny be edited by the orginal player. A locked book can be crafted using a iron ingot and a book.

Edit added texture for locked book and updated .zip file to have it.

Re: Writable Books...

PostPosted: Sun May 10, 2015 14:35
by Napiophelios
red wrote:Modified the source code for the mod to make the default book editable by anyone and make a locked book that can olny be edited by the orginal player. A locked book can be crafted using a iron ingot and a book.

Edit added texture for locked book and updated .zip file to have it.


it would be cool if unlocked, written-to books could be converted
to a locked status without losing their contents.
also if players could add multiple pages/tabs instead of one long entry.

regardless,nice work.
this is pretty neat.

Re: Writable Books...

PostPosted: Sun May 10, 2015 15:54
by red
Napiophelios wrote:
it would be cool if unlocked, written-to books could be converted
to a locked status without losing their contents.

I am planing on creating a writing table with will allowed you to copy the text from one book to another. I already have a nodebox made for the table I only need to figure out how the formspec works.
also if players could add multiple pages/tabs instead of one long entry.

That dosn't sound too hard to do, will look into it.

regardless,nice work.
this is pretty neat.

Thank you

Re: Writable Books...

PostPosted: Sun May 10, 2015 17:44
by Napiophelios
Just a thought... if the tool-tip/description were changed to the book's title once written-to,
would make looking through a bookshelf much more interesting.

Re: Writable Books...

PostPosted: Sun May 10, 2015 18:56
by red
Napiophelios wrote:Just a thought... if the tool-tip/description were changed to the book's title once written-to,
would make looking through a bookshelf much more interesting.

Yes it would be, sadly it isn't possibly with the current lua api.

Re: Writable Books...

PostPosted: Mon May 11, 2015 19:20
by red
Tenplus1 under what license is the code you pasted in the frist post?

Re: Writable Books...

PostPosted: Tue May 12, 2015 06:17
by TenPlus1
WTFL license... you can do what you like with it...