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

Lua tfs 1.2 odd bug

Zombiegod

Active Member
Joined
Oct 22, 2009
Messages
198
Solutions
1
Reaction score
25
so i am using this script Action - [TFS 1.1] Fishing monsters (https://otland.net/threads/tfs-1-1-fishing-monsters.229702/)

and whenever i first load the server it complains about this
Code:
Monster fishing::Warning - Invalid monster name:        Sea Serpent
Monster fishing::Warning - Invalid monster name:        Rotworm
Monster fishing::Warning - Invalid monster name:        Dragon
Monster fishing::Warning - Invalid monster name:        Rat
Monster fishing::Warning - Invalid monster name:        storage
Monster fishing::Warning - Invalid monster name:        EXP
Monster fishing::Warning - Invalid monster name:        Serpent Spawn
Monster fishing::Warning - Invalid monster name:        Wyrm
Monster fishing::Warning - Invalid monster name:        Sea Serpent
Monster fishing::Warning - Invalid monster name:        Rotworm
Monster fishing::Warning - Invalid monster name:        Dragon
Monster fishing::Warning - Invalid monster name:        Rat
Monster fishing::Warning - Invalid monster name:        storage
Monster fishing::Warning - Invalid monster name:        EXP
Monster fishing::Warning - Invalid monster name:        Serpent Spawn
Monster fishing::Warning - Invalid monster name:        Wyrm

and wont let me fish, (they are all valid monsters) however if i /reload actions, it fixes and i can fish monsters like normal.

My guess it it has to do with the code being loaded before monsters get loaded, and that when i reload it registers the now loaded monsters.

The part of the code that spits out the error is this.
Lua:
if config.verifyMonsters then
    local m = {}
    for minLevel, monsters in pairs(config.monsters) do
        m[minLevel] = {}
        if config.debug then print("#monsters", #monsters) end
        for i = 1, #monsters do
            if MonsterType(monsters[i]) then
                table.insert(m[minLevel], monsters[i])
            else
                print("Monster fishing::Warning - Invalid monster name:", monsters[i])
            end
        end
        if config.debug then print("Monster fishing::Debug - #monsters added", #m[minLevel]) end
    end
    config.monsters = m
end
 
Solution
I just put the script in data/actions and changed the script for fishing rod (id 2580) in actions.xml.

Did you try the script exactly as is, without changing anything? You should get a single warning:
Monster fishing::Warning - Invalid monster name: Idontexist
Given the number of threads you have open already, perhaps you should get one script working at a time.

And in this case, there is clearly a mismatch between the data format of config.monsters is in and what the script expects it to be. But you only provided one half the puzzle.

Also, if your server is giving this:
Your Server said:
MonsterType("Sea Serpent")
LuaScript::Warning - Invalid monster name: Sea Serpent
Then you should probably fix that before anything else. Sea Serpent should absolutely be a valid monster.
 
Given the number of threads you have open already, perhaps you should get one script working at a time.

And in this case, there is clearly a mismatch between the data format of config.monsters is in and what the script expects it to be. But you only provided one half the puzzle.

Also, if your server is giving this:

Then you should probably fix that before anything else. Sea Serpent should absolutely be a valid monster.
I take breathers on problem solving one bit of code, cause before i post i am usually spending a few hours on each problem, or i have no clue where to start with the problem.

sorry to quote myself
(they are all valid monsters) however if i /reload actions, it fixes and i can fish monsters like normal.

Like i stated it is a valid monster, i can spawn it, place it on the map, heck even fish it after reloading actions. To my knowledge it should be functional without flaw, but it does this as to why i was asking for help one it.
 
Do you have some sort of debug facilities available?

Like a Lua channel or a /lua talkaction for server Gods?

If they are all valid monsters.... why do you have a monster named "storage" and a monster named "EXP" -- That just seems like a bad idea. How are you loading this code? Is it from a revscriptsys line in your globals or the actions xml? It could be some bug in the server code, in which case your solution is going to be stop using TFS 1.2.
 
Do you have some sort of debug facilities available?

Like a Lua channel or a /lua talkaction for server Gods?

If they are all valid monsters.... why do you have a monster named "storage" and a monster named "EXP" -- That just seems like a bad idea. How are you loading this code? Is it from a revscriptsys line in your globals or the actions xml? It could be some bug in the server code, in which case your solution is going to be stop using TFS 1.2.
atm i am attempting to go to the latest source, but having tons of issues, like atm its compiling, vs has no errors, i followed the github steps part to part, 0 edits fresh source. However when i compile and run the exe, it just closes without error or even showing the console (for like a ms it shows).

to answer your questions.

Q: why do you have a monster named "storage" and a monster named "EXP"
A: The server is still in dev it is not public, "storage" is a monster where i am throwing all special monster functions, such as level, loot bags, and ect, so that i can have access to it. EXP is a simple exp monster to allow me to get to certain levels fast and "properly" to test things.

Q: How are you loading this code?
A: through actions.xml, idk why i would load a item action through global, or if i even could.

Q: Do you have some sort of debug facilities available?
A: No, to my knowledge that is not a common thing, or at least one people hand out on the forums, and i am not a proper coder, i do "Frankenstein" coding, so making such a thing is probably out of my tool set.
 
I tried the script on TFS 1.3 and it works as expected, so it should work on 1.2 as well.
You just need to change player:addItem("fish", 1) to player:addItem(2667, 1) at the end of the script, otherwise you get the wrong fish, at least on TFS 1.3.

You said it works when you reload actions, so it could be that the script is loaded before the monster types are loaded by the server, but that seems unlikely. MonsterType(name) should return userdata if it exists.

However when i compile and run the exe, it just closes without error or even showing the console (for like a ms it shows).
Start the server from a command line to see the output. Open cmd.exe and do something like cd path/to/tfs; forgottenserver.exe. Sorry, I'm not very familiar with Windows command line.
 
I tried the script on TFS 1.3 and it works as expected, so it should work on 1.2 as well.
You just need to change player:addItem("fish", 1) to player:addItem(2667, 1) at the end of the script, otherwise you get the wrong fish, at least on TFS 1.3.

You said it works when you reload actions, so it could be that the script is loaded before the monster types are loaded by the server, but that seems unlikely. MonsterType(name) should return userdata if it exists.


Start the server from a command line to see the output. Open cmd.exe and do something like cd path/to/tfs; forgottenserver.exe. Sorry, I'm not very familiar with Windows command line.
i guess that has to be the case, which is kinda sucky. EDIT: meant this part "script is loaded before the monster types"

As for the compile, i ran it through powershell and got this " Missing file key.pem."
Post automatically merged:

okay doing that gave me the key to solve the compile, why dont they include that darn file. and why do they need it to begin with.

EDIT: oh they do, i just mistook it for the rest of the random files that are unneeded.
 
Last edited:
The key.pem is what the server uses to RSA encrypt connections from clients. You need to generate one or use the one provided.

Code:
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCbZGkDtFsHrJVlaNhzU71xZROd15QHA7A+bdB5OZZhtKg3qmBWHXzLlFL6AIBZ
SQmIKrW8pYoaGzX4sQWbcrEhJhHGFSrT27PPvuetwUKnXT11lxUJwyHFwkpb1R/UYPAbThW+sN4Z
MFKKXT8VwePL9cQB1nd+EKyqsz2+jVt/9QIDAQABAoGAQovTtTRtr3GnYRBvcaQxAvjIV9ZUnFRm
C7Y3i1KwJhOZ3ozmSLrEEOLqTgoc7R+sJ1YzEiDKbbete11EC3gohlhW56ptj0WDf+7ptKOgqiEy
Kh4qt1sYJeeGz4GiiooJoeKFGdtk/5uvMR6FDCv6H7ewigVswzf330Q3Ya7+jYECQQERBxsga6+5
x6IofXyNF6QuMqvuiN/pUgaStUOdlnWBf/T4yUpKvNS1+I4iDzqGWOOSR6RsaYPYVhj9iRABoKyx
AkEAkbNzB6vhLAWht4dUdGzaREF3p4SwNcu5bJRa/9wCLSHaS9JaTq4lljgVPp1zyXyJCSCWpFnl
0WvK3Qf6nVBIhQJBANS7rK8+ONWQbxENdZaZ7Rrx8HUTwSOS/fwhsGWBbl1Qzhdq/6/sIfEHkfeH
1hoH+IlpuPuf21MdAqvJt+cMwoECQF1LyBOYduYGcSgg6u5mKVldhm3pJCA+ZGxnjuGZEnet3qeA
eb05++112fyvO85ABUun524z9lokKNFh45NKLjUCQGshzV43P+RioiBhtEpB/QFzijiS4L2HKNu1
tdhudnUjWkaf6jJmQS/ppln0hhRMHlk9Vus/bPx7LtuDuo6VQDo=
-----END RSA PRIVATE KEY-----
 
I tried the script on TFS 1.3 and it works as expected, so it should work on 1.2 as well.
You just need to change player:addItem("fish", 1) to player:addItem(2667, 1) at the end of the script, otherwise you get the wrong fish, at least on TFS 1.3.

You said it works when you reload actions, so it could be that the script is loaded before the monster types are loaded by the server, but that seems unlikely. MonsterType(name) should return userdata if it exists.


Start the server from a command line to see the output. Open cmd.exe and do something like cd path/to/tfs; forgottenserver.exe. Sorry, I'm not very familiar with Windows command line.
could you please explain what you did to install the script? as i did what i normally do, and fixed that one thing, this time on the latest source, and i am still getting the same issue.
 
I just put the script in data/actions and changed the script for fishing rod (id 2580) in actions.xml.

Did you try the script exactly as is, without changing anything? You should get a single warning:
Monster fishing::Warning - Invalid monster name: Idontexist
 
Solution
I just put the script in data/actions and changed the script for fishing rod (id 2580) in actions.xml.

Did you try the script exactly as is, without changing anything? You should get a single warning:
Monster fishing::Warning - Invalid monster name: Idontexist
only things i remember changing were monsters to check to see if that was the issue, and adding more tiles for faster testing.

Lua:
local waterIds = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 7236, 10499, 15401, 15402, 5405, 5406, 5407, 5408, 5409, 5410}
local lootTrash = {2234, 2238, 2376, 2509, 2667}
local lootCommon = {2152, 2167, 2168, 2669, 7588, 7589}
local lootRare = {2143, 2146, 2149, 7158, 7159}
local lootVeryRare = {7632, 7633, 10220}
local useWorms = false

-- Config for monster fishing
local config = {
    enabled = true, -- enable or disable monster fishing
    debug = false, -- enable debug messages in console
    verifyMonsters = true, -- disable this if you are having problems with Monster fishing::Warning - Invalid monster name
    chance = 50, -- chance to catch a monster in % - 50 means you have a 50/50 chance of getting a monster or a fish
    bossLevel = 300, -- min level to catch a "boss"
    bossSkill = 90, -- min fishing skill to catch a "boss"
    monsters = {
        -- [minLevel] = {"monster", "names", "for", "level"}
        [1] = {"Rotworm", "Dragon", "Rat"},
        [10] = {"Goblin", "EXP"},
        [50] = {"Serpent Spawn", "Wyrm"},
        [100] = {"Sea Serpent"},
    },
    bosses = {
        -- Monsters that can only be caught with atleast "bossLevel" and "bossSkill"
        "Dragon Lord",
    }
}

-- Validate monsters configuration
if config.verifyMonsters then
    local m = {}
    for minLevel, monsters in pairs(config.monsters) do
        m[minLevel] = {}
        if config.debug then print("#monsters", #monsters) end
        for i = 1, #monsters do
            if MonsterType(monsters[i]) then
                table.insert(m[minLevel], monsters[i])
            else
                print("Monster fishing::Warning - Invalid monster name:", monsters[i])
            end
        end
        if config.debug then print("Monster fishing::Debug - #monsters added", #m[minLevel]) end
    end
    config.monsters = m
end

function onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    local targetId = itemEx.itemid
    if not isInArray(waterIds, itemEx.itemid) then
        return false
    end

    if targetId == 10499 then
        local targetItem = Item(itemEx.uid)
        local owner = targetItem:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER)
        if owner ~= 0 and owner ~= player:getId() then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "You are not the owner.")
            return true
        end

        toPosition:sendMagicEffect(CONST_ME_WATERSPLASH)
        targetItem:remove()

        local rareChance = math.random(1, 100)
        if rareChance == 1 then
            player:addItem(lootVeryRare[math.random(#lootVeryRare)], 1)
        elseif rareChance <= 3 then
            player:addItem(lootRare[math.random(#lootRare)], 1)
        elseif rareChance <= 10 then
            player:addItem(lootCommon[math.random(#lootCommon)], 1)
        else
            player:addItem(lootTrash[math.random(#lootTrash)], 1)
        end
        return true
    end

    if targetId ~= 7236 then
        toPosition:sendMagicEffect(CONST_ME_LOSEENERGY)
    end

    if targetId == 493 or targetId == 15402 then
        return true
    end

    player:addSkillTries(SKILL_FISHING, 1)
    if math.random(1, 100) <= math.min(math.max(10 + (player:getEffectiveSkillLevel(SKILL_FISHING) - 10) * 0.597, 10), 50) then
        if useWorms and not player:removeItem("worm", 1) then
            return true
        end

        if targetId == 15401 then
            local targetItem = Item(itemEx.uid)
            targetItem:transform(targetId + 1)
            targetItem:decay()

            if math.random(1, 100) >= 97 then
                player:addItem(15405, 1)
                return true
            end
        elseif targetId == 7236 then
            local targetItem = Item(itemEx.uid)
            targetItem:transform(targetId + 1)
            targetItem:decay()

            local rareChance = math.random(1, 100)
            if rareChance == 1 then
                player:addItem(7158, 1)
                return true
            elseif rareChance <= 4 then
                player:addItem(2669, 1)
                return true
            elseif rareChance <= 10 then
                player:addItem(7159, 1)
                return true
            end
        end
        if config.enabled and math.random(100) <= config.chance then
            local level = player:getLevel()
            local skill = player:getSkillLevel(SKILL_FISHING)
            local tmpMonsters = {}

            for minLevel, monsters in pairs(config.monsters) do
                if config.debug then print("Monster fishing::Debug - Level check:", level, ">=", minLevel) end
                if level >= minLevel then
                    if config.debug then print("Monster fishing::Debug - Level check passed - #monsters:", #monsters) end
                    for i = 1, #monsters do
                        if config.debug then print("Monster fishing::Debug - Found monster:", monsters[i]) end
                        table.insert(tmpMonsters, monsters[i])
                    end
                end
            end

            if level >= config.bossLevel and skill >= config.bossSkill then
                for i = 1, #config.bosses do
                    table.insert(tmpMonsters, config.bosses[i])
                end
            end
            if config.debug then print("Monster fishing::Debug - #tmpMonsters: "..#tmpMonsters) end
            if #tmpMonsters > 0 then
                local pos = player:getPosition()
                Game.createMonster(tmpMonsters[math.random(1, #tmpMonsters)], pos)
                return true
            end
        end
        player:addItem("2667", 1)
    end
    return true
end

EDIT: just realized i am a dumb--- found the problem.
 
Last edited:
Well, share it for the class. So in case someone else did the same thing and they find this they won't have to keep looking.
 
Well, share it for the class. So in case someone else did the same thing and they find this they won't have to keep looking.
Lua:
verifyMonsters = true, -- disable this if you are having problems with Monster fishing::Warning - Invalid monster name
 
Well, I guess if it works for you as a solution, that's fine.

But to me that is not a solution. It is ignoring some underlying problem that may be affecting other scripts as well. 🤷‍♂️ It is a bandage over an ugly wound.

You should be able to have this in literally any script:
Lua:
    do
            if MonsterType("Sea Serpent") then
                print("All is well! Carry on!")
            else
                print("Warning: Your server thinks Sea Serpent isn't a valid monster. Some shit somewhere is fucked up")
            end
    end
 
Well, I guess if it works for you as a solution, that's fine.

But to me that is not a solution. It is ignoring some underlying problem that may be affecting other scripts as well. 🤷‍♂️ It is a bandage over an ugly wound.

You should be able to have this in literally any script:
Lua:
    do
            if MonsterType("Sea Serpent") then
                print("All is well! Carry on!")
            else
                print("Warning: Your server thinks Sea Serpent isn't a valid monster. Some shit somewhere is fucked up")
            end
    end
Well if you can come up with a solution that fixes this problem i would love to hear it, however so far all you have really done is half read my post, assume i am a imbecile. Yes i can tell you half read it by the first comment you made.

I am choosing to "ignore the underlying problem" because, 1: doing that fixed the main issue, and 2: no one has given me even a hint on what to do to fix this, and as you clearly point out early i have a lot of problems i have to fix, and with so many unanswered support threads, only me to rely on to fix them.

EDIT: and thats only the problems i have made public.
 
and thats only the problems i have made public.

This is kinda my point though man. If all these threads you've made are about code coming from a single server, you've got a very complex problem and there is no telling what problems could actually be the cause of these other problems. The only way I could really help you now and not feel like I'm wasting my time is having access to your entire dataset, which is a lot to ask I know. 😖
 
This is kinda my point though man. If all these threads you've made are about code coming from a single server, you've got a very complex problem and there is no telling what problems could actually be the cause of these other problems. The only way I could really help you now and not feel like I'm wasting my time is having access to your entire dataset, which is a lot to ask I know. 😖
not really, most of the work done is barely custom, the little that is custom you dont need access too due to me knowing the code is good to go. HMU on discord, pm me.
 
I did some more testing, and confirmed that the issue is that the script is executed before monsters are loaded. Both MonsterType(name)and Game.createMonster(...) returns nil. Even just running the check through addEvent() solves it.
It is pretty safe to set verifyMonsters to false. If there are no missing monsters it will work fine and if there are, it may occasionally attempt to spawn a missing monster which only results in nothing happening.

Here is a revscriptsys version that runs the check on a startup global event. You need to disable the script in actions.xml to use revscriptsys instead.
Lua:
local waterIds = {493, 4608, 4609, 4610, 4611, 4612, 4613, 4614, 4615, 4616, 4617, 4618, 4619, 4620, 4621, 4622, 4623, 4624, 4625, 7236, 10499, 15401, 15402}
local lootTrash = {2234, 2238, 2376, 2509, 2667}
local lootCommon = {2152, 2167, 2168, 2669, 7588, 7589}
local lootRare = {2143, 2146, 2149, 7158, 7159}
local lootVeryRare = {7632, 7633, 10220}
local useWorms = true

-- Config for monster fishing
local config = {
    enabled = true, -- enable or disable monster fishing
    debug = false, -- enable debug messages in console
    verifyMonsters = true, -- disable this if you are having problems with Monster fishing::Warning - Invalid monster name
    chance = 50, -- chance to catch a monster in % - 50 means you have a 50/50 chance of getting a monster or a fish
    bossLevel = 300, -- min level to catch a "boss"
    bossSkill = 90, -- min fishing skill to catch a "boss"
    monsters = {
        -- [minLevel] = {"monster", "names", "for", "level"}
        [100] = {"Quara Hydromancer", "Quara Constrictor", "Quara Mantassin", "Idontexist"},
        [150] = {"Quara Pincher", "Quara Predator"},
        [200] = {"Serpent Spawn", "Wyrm"},
        [300] = {"Sea Serpent"},
    },
    bosses = {
        -- Monsters that can only be caught with atleast "bossLevel" and "bossSkill"
        "Titan Goddess of Water",
    }
}

-- Validate monsters configuration
local function verifyMonsters()
    if config.verifyMonsters then
        local m = {}
        for minLevel, monsters in pairs(config.monsters) do
            m[minLevel] = {}
            if config.debug then print("#monsters", #monsters) end
            for i = 1, #monsters do
                if MonsterType(monsters[i]) then
                    table.insert(m[minLevel], monsters[i])
                else
                    print("Monster fishing::Warning - Invalid monster name:", monsters[i])
                end
            end
            if config.debug then print("Monster fishing::Debug - #monsters added", #m[minLevel]) end
        end
        config.monsters = m
    end
end

local action = Action()

function action.onUse(player, item, fromPosition, itemEx, toPosition, isHotkey)
    local targetId = itemEx.itemid
    if not isInArray(waterIds, itemEx.itemid) then
        return false
    end

    if targetId == 10499 then
        local targetItem = Item(itemEx.uid)
        local owner = targetItem:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER)
        if owner ~= 0 and owner ~= player:getId() then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "You are not the owner.")
            return true
        end

        toPosition:sendMagicEffect(CONST_ME_WATERSPLASH)
        targetItem:remove()

        local rareChance = math.random(1, 100)
        if rareChance == 1 then
            player:addItem(lootVeryRare[math.random(#lootVeryRare)], 1)
        elseif rareChance <= 3 then
            player:addItem(lootRare[math.random(#lootRare)], 1)
        elseif rareChance <= 10 then
            player:addItem(lootCommon[math.random(#lootCommon)], 1)
        else
            player:addItem(lootTrash[math.random(#lootTrash)], 1)
        end
        return true
    end

    if targetId ~= 7236 then
        toPosition:sendMagicEffect(CONST_ME_LOSEENERGY)
    end

    if targetId == 493 or targetId == 15402 then
        return true
    end

    player:addSkillTries(SKILL_FISHING, 1)
    if math.random(1, 100) <= math.min(math.max(10 + (player:getEffectiveSkillLevel(SKILL_FISHING) - 10) * 0.597, 10), 50) then
        if useWorms and not player:removeItem("worm", 1) then
            return true
        end

        if targetId == 15401 then
            local targetItem = Item(itemEx.uid)
            targetItem:transform(targetId + 1)
            targetItem:decay()

            if math.random(1, 100) >= 97 then
                player:addItem(15405, 1)
                return true
            end
        elseif targetId == 7236 then
            local targetItem = Item(itemEx.uid)
            targetItem:transform(targetId + 1)
            targetItem:decay()

            local rareChance = math.random(1, 100)
            if rareChance == 1 then
                player:addItem(7158, 1)
                return true
            elseif rareChance <= 4 then
                player:addItem(2669, 1)
                return true
            elseif rareChance <= 10 then
                player:addItem(7159, 1)
                return true
            end
        end
        if config.enabled and math.random(100) <= config.chance then
            local level = player:getLevel()
            local skill = player:getSkillLevel(SKILL_FISHING)
            local tmpMonsters = {}

            for minLevel, monsters in pairs(config.monsters) do
                if config.debug then print("Monster fishing::Debug - Level check:", level, ">=", minLevel) end
                if level >= minLevel then
                    if config.debug then print("Monster fishing::Debug - Level check passed - #monsters:", #monsters) end
                    for i = 1, #monsters do
                        if config.debug then print("Monster fishing::Debug - Found monster:", monsters[i]) end
                        table.insert(tmpMonsters, monsters[i])
                    end
                end
            end

            if level >= config.bossLevel and skill >= config.bossSkill then
                for i = 1, #config.bosses do
                    table.insert(tmpMonsters, config.bosses[i])
                end
            end
            if config.debug then print("Monster fishing::Debug - #tmpMonsters: "..#tmpMonsters) end
            if #tmpMonsters > 0 then
                local pos = player:getPosition()
                Game.createMonster(tmpMonsters[math.random(1, #tmpMonsters)], pos)
                return true
            end
        end
        player:addItem(2667, 1)
    end
    return true
end

local startup = GlobalEvent("MonsterFishingStartup")

function startup.onStartup()
    verifyMonsters()
    return true
end

startup:register()

action:id(2580)
action:allowFarUse(true)
action:register()
 
I did some more testing, and confirmed that the issue is that the script is executed before monsters are loaded.

That's the sort of thing that should be noted somewhere by the daemon itself. But thank you for investigating. 👍

I guess since the monster files use scripts for some attacks some scripts would need to be loaded first, but one would expect monsters are loaded before actions.

EDIT: Actually looks like this issue was just touched upon by a recent commit. And that new default behavior the original script should work as-is.
 
Last edited:
Just to clear up for future reference.
Monsters are loaded after the Scripting Interface (classic or revscriptsys doesn't matter)
The problem in this case was a flaw of design in the script itself, which @forgee pointed out pretty well just now.
There is a huge difference between those 3 pieces (just example codes)
1) works
Lua:
local monsters = {}
function onUse(...)
    if MonsterType("rat") then
        print("does exist")
        table.insert(monsters, "rat")
    end
end
2) works
Lua:
local monsters = {}
local function verifyMonster()  
    if MonsterType("rat") then
        print("does exist")
        table.insert(monsters, "rat")
    end
end
function onUse(...)
    verifyMonster()
end
3) does not work
Lua:
-- initializing the monsters table outside (which is fine)
local monsters = {}
-- calling the MonsterType function outside of a function / interface leads to the error.
-- this will be executed immediatly once it reads the lua file and since we are currently in the actions interface (console >> Loading Script System)
-- which is before we even load monsters overall, so the function itself doesn't contain any data so far.
if MonsterType("rat") then
    print("does exist")
    table.insert(monsters, "rat")
end
function onUse(...)
    ...
end

It's all just a matter of order and execution, this is a heavy topic and I just gave a shallow explanation of it, this can go even beyond all of this but it should give a slight idea of why this is not working.
 
Back
Top