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

Get all monster info

Paulix

Active Member
Joined
Sep 13, 2012
Messages
129
Solutions
7
Reaction score
26
I'm trying to print all monster info on my console, so I know how to use it to make my script. I've been making this but looks like there is a lot of tables inside other tables and I can't figure how to make print it all. Here is how I was trying...

Lua:
function onSay(cid, words, param, channel)

    if(param == '') then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Monster name required.")
        return true
    end
   
    monster = getMonsterInfo(param)
    for k,v in pairs(monster) do
        if type(v) == "table" then
            print(k..": "..tostring(v))
            for l,x in pairs(v) do
                print("     "..l..": "..tostring(x))
            end
        else
            print(k..": "..tostring(v))
        end
    end

    return true
end

and this is the output

Code:
[30/3/2018 8:7:48] description: a dark demon
[30/3/2018 8:7:48] skull: 0
[30/3/2018 8:7:48] healthMax: 6400
[30/3/2018 8:7:48] hostile: true
[30/3/2018 8:7:48] armor: 40
[30/3/2018 8:7:48] illusionable: false
[30/3/2018 8:7:48] outfit: table: 139D49A8
[30/3/2018 8:7:48]      lookAddons: 0
[30/3/2018 8:7:48]      lookType: 12
[30/3/2018 8:7:48]      lookHead: 0
[30/3/2018 8:7:48]      lookTypeEx: 0
[30/3/2018 8:7:49]      lookLegs: 87
[30/3/2018 8:7:49]      lookBody: 95
[30/3/2018 8:7:49]      lookFeet: 113
[30/3/2018 8:7:49] summons: table: 139D09E8
[30/3/2018 8:7:49] loot: table: 139D9C00
[30/3/2018 8:7:49]      1: table: 139DB230
[30/3/2018 8:7:49]      2: table: 139D4EF8
[30/3/2018 8:7:49]      3: table: 139D1910
[30/3/2018 8:7:49]      4: table: 139D5858
[30/3/2018 8:7:49]      5: table: 139D3AD0
[30/3/2018 8:7:49]      6: table: 139D8698
[30/3/2018 8:7:49]      7: table: 139D6758
[30/3/2018 8:7:49]      8: table: 139DF358
[30/3/2018 8:7:49]      9: table: 139D4F20
[30/3/2018 8:7:49]      10: table: 139D2158
[30/3/2018 8:7:49] summonable: false
[30/3/2018 8:7:49] lookCorpse: 6068
[30/3/2018 8:7:49] attacks: table: 139DF7E0
[30/3/2018 8:7:49]      1: table: 139DB0A0
[30/3/2018 8:7:49]      2: table: 139DA088
[30/3/2018 8:7:49]      3: table: 139D9DB8
[30/3/2018 8:7:49]      4: table: 139DBAF0
[30/3/2018 8:7:49] defense: 48
[30/3/2018 8:7:49] attackable: true
[30/3/2018 8:7:49] guildEmblem: 0
[30/3/2018 8:7:49] race: 2
[30/3/2018 8:7:49] defenses: table: 139D6988
[30/3/2018 8:7:49]      1: table: 139D2D10
[30/3/2018 8:7:49] baseSpeed: 275
[30/3/2018 8:7:49] name: Dark Demon
[30/3/2018 8:7:49] partyShield: 0
[30/3/2018 8:7:49] convinceable: false
[30/3/2018 8:7:49] manaCost: 0
[30/3/2018 8:7:49] experience: 5323
[30/3/2018 8:7:49] health: 6400

how can I manage to print every single table inside all tables on my monster info?
 
Solution
add this to global.lua
Lua:
function table.print(t)
    print(string.format("{ %s", t))
    local function output(t, tab)
        tab = tab or 1
        local indent = ("    "):rep(tab)
        for k, v in pairs(t) do
            local key = type(k) == "string" and "'%s'" or "%s"
            if type(v) == "table" then
                print(string.format("%s[".. key .."] = { %s", indent, k, v))
                output(v, tab + 1)
                print(string.format("%s}", indent))
            else
                print(string.format("%s[".. key .."] = %s", indent, k, v))
            end
        end
    end
    output(t)
    print("}")
end

in your code:
table.print(getMonsterInfo(param))
I'm trying to print all monster info on my console, so I know how to use it to make my script. I've been making this but looks like there is a lot of tables inside other tables and I can't figure how to make print it all. Here is how I was trying...

Lua:
function onSay(cid, words, param, channel)

    if(param == '') then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Monster name required.")
        return true
    end
  
    monster = getMonsterInfo(param)
    for k,v in pairs(monster) do
        if type(v) == "table" then
            print(k..": "..tostring(v))
            for l,x in pairs(v) do
                print("     "..l..": "..tostring(x))
            end
        else
            print(k..": "..tostring(v))
        end
    end

    return true
end

and this is the output

Code:
[30/3/2018 8:7:48] description: a dark demon
[30/3/2018 8:7:48] skull: 0
[30/3/2018 8:7:48] healthMax: 6400
[30/3/2018 8:7:48] hostile: true
[30/3/2018 8:7:48] armor: 40
[30/3/2018 8:7:48] illusionable: false
[30/3/2018 8:7:48] outfit: table: 139D49A8
[30/3/2018 8:7:48]      lookAddons: 0
[30/3/2018 8:7:48]      lookType: 12
[30/3/2018 8:7:48]      lookHead: 0
[30/3/2018 8:7:48]      lookTypeEx: 0
[30/3/2018 8:7:49]      lookLegs: 87
[30/3/2018 8:7:49]      lookBody: 95
[30/3/2018 8:7:49]      lookFeet: 113
[30/3/2018 8:7:49] summons: table: 139D09E8
[30/3/2018 8:7:49] loot: table: 139D9C00
[30/3/2018 8:7:49]      1: table: 139DB230
[30/3/2018 8:7:49]      2: table: 139D4EF8
[30/3/2018 8:7:49]      3: table: 139D1910
[30/3/2018 8:7:49]      4: table: 139D5858
[30/3/2018 8:7:49]      5: table: 139D3AD0
[30/3/2018 8:7:49]      6: table: 139D8698
[30/3/2018 8:7:49]      7: table: 139D6758
[30/3/2018 8:7:49]      8: table: 139DF358
[30/3/2018 8:7:49]      9: table: 139D4F20
[30/3/2018 8:7:49]      10: table: 139D2158
[30/3/2018 8:7:49] summonable: false
[30/3/2018 8:7:49] lookCorpse: 6068
[30/3/2018 8:7:49] attacks: table: 139DF7E0
[30/3/2018 8:7:49]      1: table: 139DB0A0
[30/3/2018 8:7:49]      2: table: 139DA088
[30/3/2018 8:7:49]      3: table: 139D9DB8
[30/3/2018 8:7:49]      4: table: 139DBAF0
[30/3/2018 8:7:49] defense: 48
[30/3/2018 8:7:49] attackable: true
[30/3/2018 8:7:49] guildEmblem: 0
[30/3/2018 8:7:49] race: 2
[30/3/2018 8:7:49] defenses: table: 139D6988
[30/3/2018 8:7:49]      1: table: 139D2D10
[30/3/2018 8:7:49] baseSpeed: 275
[30/3/2018 8:7:49] name: Dark Demon
[30/3/2018 8:7:49] partyShield: 0
[30/3/2018 8:7:49] convinceable: false
[30/3/2018 8:7:49] manaCost: 0
[30/3/2018 8:7:49] experience: 5323
[30/3/2018 8:7:49] health: 6400

how can I manage to print every single table inside all tables on my monster info?

You need to check if x is a table aswell.

otservme/global860
 
add this to global.lua
Lua:
function table.print(t)
    print(string.format("{ %s", t))
    local function output(t, tab)
        tab = tab or 1
        local indent = ("    "):rep(tab)
        for k, v in pairs(t) do
            local key = type(k) == "string" and "'%s'" or "%s"
            if type(v) == "table" then
                print(string.format("%s[".. key .."] = { %s", indent, k, v))
                output(v, tab + 1)
                print(string.format("%s}", indent))
            else
                print(string.format("%s[".. key .."] = %s", indent, k, v))
            end
        end
    end
    output(t)
    print("}")
end

in your code:
table.print(getMonsterInfo(param))
 
Solution
@Static_ I had to make some adjustments for it to work on my server, but it is doing what I needed. Thank you very much!
Here is the code if you're interested

Lua:
function table.print(t)
    print("{ "..tostring(t))
    local function output(t, tab)
        tab = tab or 1
        local indent = ("    "):rep(tab)
        for k, v in pairs(t) do
            local key = type(k) == "string" and "'%s'" or "%s"
            if type(v) == "table" then
                print(indent.."["..k.."] = { "..tostring(v))
                output(v, tab + 1)
                print(indent.."}")
            else
                print(indent.."[".. k.."] = "..tostring(v))
            end
        end
    end
    output(t)
    print("}")
end
 
Back
Top