• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

SCRIPT BOOK SYSTEM HELP !

Chriistian.L.B

Intermediate OT User
Joined
Apr 17, 2008
Messages
230
Solutions
5
Reaction score
129
Hail Everyone, first sorry for my bad english.

I would like to request a script that works as follows:


The player uses it on the bookshelf and receives a book in storage format, a book that is kept forever with him and the book opens with his story and to see what books he has available It uses talkaction !books and opens a modalwindow where he can select what book them whant to read, could anyone help me? I need this script for tfs 1.3

Here some images of the system

VetqK7p.png


When the player use talkaction !books:

IqsG8CG.png

When the player selects the book:
0Y8mYcA.png
 
Last edited:
Solution
Ok, so firstly, i tested this on 1.1, so i don't know how it's gonna end up on 1.3

First, you need to install this kick-ass Lib by @Non Sequitur , just follow his instructions:
[TFS 1.2] Modal Window Helper Lib

Second step is installing my script.

Go to data/lib make new file BOOKS.lua and paste this:
Lua:
BOOKS_TABLE = {    [80001] = {title = "Book vol.1", icon = 2222,
                            text = "This is some cool book."
                                                                                    },
                                                                                  
                [80002] = {title = "Book vol.2", icon = 2222,
                            text = "Sequel is worse."...
Ok, so firstly, i tested this on 1.1, so i don't know how it's gonna end up on 1.3

First, you need to install this kick-ass Lib by @Non Sequitur , just follow his instructions:
[TFS 1.2] Modal Window Helper Lib

Second step is installing my script.

Go to data/lib make new file BOOKS.lua and paste this:
Lua:
BOOKS_TABLE = {    [80001] = {title = "Book vol.1", icon = 2222,
                            text = "This is some cool book."
                                                                                    },
                                                                                  
                [80002] = {title = "Book vol.2", icon = 2222,
                            text = "Sequel is worse."
                                                                                    },
                                                                                  
                [80003] = {title = "Book vol.3", icon = 2222,
                            text = "It's getting ridiculous."
                                                                                    },
                                                                                  
                [80004] = {title = "Book vol.4", icon = 2222,
                            text = "My fucking god..."
                                                                                    },
                [80005] = {title = "Encyclopedia", icon = 2222,
                            text = "Example text1"
                                                                                    },
                [80006] = {title = "Dictionary", icon = 2222,
                            text = "Example text2"
                                                                                    },
                }
Every index number responds to storage value of a book. To add a book to players collection it's storage value must be bigger than -1.
Title will be displayed on top of Text Dialog. Icon is item id.
Books will be sorted alphabetically, don't mind the order.

Open your global.lua and paste this on top:
Lua:
dofile('data/lib/BOOKS.lua')


Now, a talkaction.
Lua:
    <talkaction words="!books" separator=" " script="books.lua" />
Lua:
function onSay(player, words, param)

-- Assemble books list
            local books_pool = {}
            for i, book in pairs(BOOKS_TABLE) do
                if player:getStorageValue(i) > -1 then
                    table.insert(books_pool, BOOKS_TABLE[i].title)
                end
            end
                                table.sort(books_pool)
           
-- Modal window config + choices
      local booksWindow = ModalWindow {
                        title = 'Books',
                        message = string.format("This window contains every book you've ever found.\nBooks collection: %d.", #books_pool)
                        }


                    for _, book in pairs(books_pool) do
                        booksWindow:addChoice(book)
                    end
                   
-- Modal window set-up and programmed buttons

            booksWindow:addButton('Show',
                function(button, choice)
                local btitle = tostring(choice.text)
                for k, book in pairs(BOOKS_TABLE) do
                    if btitle == BOOKS_TABLE[k].title then
                        player:showTextDialog(BOOKS_TABLE[k].icon, string.format('["%s"]\n\n  %s',BOOKS_TABLE[k].title, BOOKS_TABLE[k].text), false)
                    end
                end
               
                                booksWindow:sendToPlayer(player)
                                return true
                end
            )   


                booksWindow:setDefaultEnterButton('Show')           
                booksWindow:addButton('Exit')
                booksWindow:setDefaultEscapeButton('Exit')
               

                booksWindow:sendToPlayer(player)
   
-- send effect   

        player:getPosition():sendMagicEffect(CONST_ME_CRAPS)
            return false
        end

Have fun.
 
Solution
Ok, so firstly, i tested this on 1.1, so i don't know how it's gonna end up on 1.3

First, you need to install this kick-ass Lib by @Non Sequitur , just follow his instructions:
[TFS 1.2] Modal Window Helper Lib

Second step is installing my script.

Go to data/lib make new file BOOKS.lua and paste this:
Lua:
BOOKS_TABLE = {    [80001] = {title = "Book vol.1", icon = 2222,
                            text = "This is some cool book."
                                                                                    },
                                                                                 
                [80002] = {title = "Book vol.2", icon = 2222,
                            text = "Sequel is worse."
                                                                                    },
                                                                                 
                [80003] = {title = "Book vol.3", icon = 2222,
                            text = "It's getting ridiculous."
                                                                                    },
                                                                                 
                [80004] = {title = "Book vol.4", icon = 2222,
                            text = "My fucking god..."
                                                                                    },
                [80005] = {title = "Encyclopedia", icon = 2222,
                            text = "Example text1"
                                                                                    },
                [80006] = {title = "Dictionary", icon = 2222,
                            text = "Example text2"
                                                                                    },
                }
Every index number responds to storage value of a book. To add a book to players collection it's storage value must be bigger than -1.
Title will be displayed on top of Text Dialog. Icon is item id.
Books will be sorted alphabetically, don't mind the order.

Open your global.lua and paste this on top:
Lua:
dofile('data/lib/BOOKS.lua')


Now, a talkaction.
Lua:
    <talkaction words="!books" separator=" " script="books.lua" />
Lua:
function onSay(player, words, param)

-- Assemble books list
            local books_pool = {}
            for i, book in pairs(BOOKS_TABLE) do
                if player:getStorageValue(i) > -1 then
                    table.insert(books_pool, BOOKS_TABLE[i].title)
                end
            end
                                table.sort(books_pool)
          
-- Modal window config + choices
      local booksWindow = ModalWindow {
                        title = 'Books',
                        message = string.format("This window contains every book you've ever found.\nBooks collection: %d.", #books_pool)
                        }


                    for _, book in pairs(books_pool) do
                        booksWindow:addChoice(book)
                    end
                  
-- Modal window set-up and programmed buttons

            booksWindow:addButton('Show',
                function(button, choice)
                local btitle = tostring(choice.text)
                for k, book in pairs(BOOKS_TABLE) do
                    if btitle == BOOKS_TABLE[k].title then
                        player:showTextDialog(BOOKS_TABLE[k].icon, string.format('["%s"]\n\n  %s',BOOKS_TABLE[k].title, BOOKS_TABLE[k].text), false)
                    end
                end
              
                                booksWindow:sendToPlayer(player)
                                return true
                end
            )  


                booksWindow:setDefaultEnterButton('Show')          
                booksWindow:addButton('Exit')
                booksWindow:setDefaultEscapeButton('Exit')
              

                booksWindow:sendToPlayer(player)
  
-- send effect  

        player:getPosition():sendMagicEffect(CONST_ME_CRAPS)
            return false
        end

Have fun.
to learn how to properly format your code: lua-users wiki: Lua Style Guide
 
Kinda sloppy, but readable i guess. What caught up your eye right here?
literally everything
your tabbing isn't great, you have some places where you have like 20 tabs or some shit then some where you dont have any, there's no consistency
generally when you enter another block of code you tab an extra time
Lua:
function a() -- declares a new block
    if true then -- another block
        print(1)
    end -- block ends
end -- function block ends
function, repeat, if, while, do, for, else, and elseif are all keywords that declare a new block with their own scope
 
Ok, so firstly, i tested this on 1.1, so i don't know how it's gonna end up on 1.3

First, you need to install this kick-ass Lib by @Non Sequitur , just follow his instructions:
[TFS 1.2] Modal Window Helper Lib

Second step is installing my script.

Go to data/lib make new file BOOKS.lua and paste this:
Lua:
BOOKS_TABLE = {    [80001] = {title = "Book vol.1", icon = 2222,
                            text = "This is some cool book."
                                                                                    },
                                                                                
                [80002] = {title = "Book vol.2", icon = 2222,
                            text = "Sequel is worse."
                                                                                    },
                                                                                
                [80003] = {title = "Book vol.3", icon = 2222,
                            text = "It's getting ridiculous."
                                                                                    },
                                                                                
                [80004] = {title = "Book vol.4", icon = 2222,
                            text = "My fucking god..."
                                                                                    },
                [80005] = {title = "Encyclopedia", icon = 2222,
                            text = "Example text1"
                                                                                    },
                [80006] = {title = "Dictionary", icon = 2222,
                            text = "Example text2"
                                                                                    },
                }
Every index number responds to storage value of a book. To add a book to players collection it's storage value must be bigger than -1.
Title will be displayed on top of Text Dialog. Icon is item id.
Books will be sorted alphabetically, don't mind the order.

Open your global.lua and paste this on top:
Lua:
dofile('data/lib/BOOKS.lua')


Now, a talkaction.
Lua:
    <talkaction words="!books" separator=" " script="books.lua" />
Lua:
function onSay(player, words, param)

-- Assemble books list
            local books_pool = {}
            for i, book in pairs(BOOKS_TABLE) do
                if player:getStorageValue(i) > -1 then
                    table.insert(books_pool, BOOKS_TABLE[i].title)
                end
            end
                                table.sort(books_pool)
         
-- Modal window config + choices
      local booksWindow = ModalWindow {
                        title = 'Books',
                        message = string.format("This window contains every book you've ever found.\nBooks collection: %d.", #books_pool)
                        }


                    for _, book in pairs(books_pool) do
                        booksWindow:addChoice(book)
                    end
                 
-- Modal window set-up and programmed buttons

            booksWindow:addButton('Show',
                function(button, choice)
                local btitle = tostring(choice.text)
                for k, book in pairs(BOOKS_TABLE) do
                    if btitle == BOOKS_TABLE[k].title then
                        player:showTextDialog(BOOKS_TABLE[k].icon, string.format('["%s"]\n\n  %s',BOOKS_TABLE[k].title, BOOKS_TABLE[k].text), false)
                    end
                end
             
                                booksWindow:sendToPlayer(player)
                                return true
                end
            ) 


                booksWindow:setDefaultEnterButton('Show')         
                booksWindow:addButton('Exit')
                booksWindow:setDefaultEscapeButton('Exit')
             

                booksWindow:sendToPlayer(player)
 
-- send effect 

        player:getPosition():sendMagicEffect(CONST_ME_CRAPS)
            return false
        end

Have fun.

@2Rec Maan thank you, very much ! Just one more question, how i can make the action to the player get this storage when them use the bookcase ?
 
Back
Top