• 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!

Custom book [SOLVED]

demon088

#088 in the Horde
Joined
Jun 17, 2009
Messages
250
Solutions
3
Reaction score
30
Location
Hell
Hello OtLand!
I want to make a special book for my new vocation "Summoner", this book will show all the information about the summons, similar to a spellbook. I need to create a table within the script and write custom information.
I was trying with this, but didn't work.

Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    table.sort(bestiary)
        local line = ""
            line = line .. "Summons for Level " .. 10 .. "\n"           
        end
        text = text .. line .. "  " .. Trained Bat - 25 - Speed attack .. "\n"
    end
    player:showTextDialog(item:getId(), text)
    return true
end
I don't know how to create tables in lua with custom information, so I need a little help over here. Thanks for all the help!

BUMP!
 
Last edited by a moderator:
Solution
Lua:
local summons = {
    {level = 10, summons = {"Trained Bat - 25 - Speed Attack"}},
    {level = 15, summons = {"Magical Skeleton - 45 - Life Drain"}}
}
local text = {}
for _, v in ipairs(summons) do
    text[#text+1] = string.format("Summons for level %d: %s", v.level, table.concat(v.summons, "\n"))
end
text = table.concat(text, "\n")

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    player:showTextDialog(item:getId(), text)
    return true
end
Lua:
local summons = {
    {level = 10, summons = {"Trained Bat - 25 - Speed Attack"}},
    {level = 15, summons = {"Something else", "Another summon", "3rd summon", "etc"}}
}

local text = {}
for _, v in ipairs(summons) do
    text[#test+1] = string.format("Summons for level %d: %s", v.level, table.concat(v.summons, "\n"))
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    player:showTextDialog(item:getId(), text)
    return true
end
 
Lua:
local summons = {
    {level = 10, summons = {"Trained Bat - 25 - Speed Attack"}},
    {level = 15, summons = {"Something else", "Another summon", "3rd summon", "etc"}}
}

local text = {}
for _, v in ipairs(summons) do
    text[#test+1] = string.format("Summons for level %d: %s", v.level, table.concat(v.summons, "\n"))
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    player:showTextDialog(item:getId(), text)
    return true
end

I have an issue with your script:
Code:
Lua Script Error: [Test Interface]
data/actions/scripts/other/bestiary.lua
data/actions/scripts/other/bestiary.lua:8: attempt to get length of global 'test' (a nil value)
stack traceback:
        [C]: in function '__len'
        data/actions/scripts/other/bestiary.lua:8: in main chunk
[Warning - Event::checkScript] Can not load script: scripts/other/bestiary.lua
 
my bad, replace text[#test+1] to text[#text+1]
i misspelled
The book appears empty.

- actions/scripts/bestiary.lua:
Lua:
local summons = {
    {level = 10, summons = {"Trained Bat - 25 - Speed Attack"}},
    {level = 15, summons = {"Magical Skeleton - 45 - Life Drain"}}
}
local text = {}
for _, v in ipairs(summons) do
    text[#text+1] = string.format("Summons for level %d: %s", v.level, table.concat(v.summons, "\n"))
end

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    player:showTextDialog(item:getId(), text)
    return true
end
y14ArrR.png

78TMo

78TMo
 
Lua:
local summons = {
    {level = 10, summons = {"Trained Bat - 25 - Speed Attack"}},
    {level = 15, summons = {"Magical Skeleton - 45 - Life Drain"}}
}
local text = {}
for _, v in ipairs(summons) do
    text[#text+1] = string.format("Summons for level %d: %s", v.level, table.concat(v.summons, "\n"))
end
text = table.concat(text, "\n")

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    player:showTextDialog(item:getId(), text)
    return true
end
 
Solution
Nailed!
Lua:
local summons = {
    {level = 10, summons = {"Trained Bat - 25 - Speed Attack"}},
    {level = 15, summons = {"Magical Skeleton - 45 - Life Drain"}}
}
local text = {}
for _, v in ipairs(summons) do
    text[#text+1] = string.format("Summons for level %d: %s", v.level, table.concat(v.summons, "\n"))
end
text = table.concat(text, "\n")

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    player:showTextDialog(item:getId(), text)
    return true
end
This script is working as an action item in my TFS 1.2! I hope this script might be useful for someone else. @Static_ Thank you so much for all your help!

This is a picture of the script working:
WeGZpbC.png
 
Back
Top