• 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 Attempt to index global 'MONSTER_ID'

kuhi

Premium User
Premium User
Joined
Aug 26, 2012
Messages
200
Solutions
1
Reaction score
81
Location
x64dbg
GitHub
Kuhicop
I'm trying to code a task npc, I'm trying to debug with selfSay but I don't understand why it's getting the variable like global not local... maybe I'm wrong and that's not the problem but I'm getting mad trying to solve this xD I'm using OTHire 0.0.3 btw
37366

37365

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions
function onCreatureAppear(cid)            npcHandler:onCreatureAppear(cid)            end
function onCreatureDisappear(cid)        npcHandler:onCreatureDisappear(cid)            end
function onCreatureSay(cid, type, msg)        npcHandler:onCreatureSay(cid, type, msg)        end
function onThink()                npcHandler:onThink()                    end

local status = 0
local HAVE_TASK = false
local TASK_FINISHED = false

local MAIN_STORAGE = 32000
local CONFIG = {
    ["rat"] = {STORAGE = 32001, COUNT = 10, REWARD = 1000},
}
local PARSE = {
    ["32001"] = {NAME = "rat"},
}

function creatureSayCallback(cid, type, msg)      
    if(npcHandler.focus ~= cid) then
        return false
    end

    -- Obtener la task actual
    local PLAYER_TASK = getPlayerStorageValue(cid, MAIN_STORAGE)
    if PLAYER_TASK > 0 then
        selfSay(PLAYER_TASK) --
        HAVE_TASK = true
        local PLAYER_TASK_COUNT = getPlayerStorageValue(cid, PLAYER_TASK)
        selfSay(PLAYER_TASK_COUNT) --
        local MONSTER_ID = PARSE[tostring(PLAYER_TASK)]
        selfSay(MONSTER_ID.NAME..","..PLAYER_TASK) --
        local MONSTER_NAME = CONFIG[MONSTER_ID.NAME]
        selfSay("reward: "..MONSTER_NAME.REWARD) --
        if PLAYER_TASK_COUNT > MONSTER_NAME.COUNT then
            selfSay("TRUE") --
            TASK_FINISHED = true
        else
            selfSay("FALSE") ---
            TASK_FINISHED = false
        end
    else
        HAVE_TASK = false
    end  
       
    -- Menu principal
    if msgcontains(string.lower(msg), 'task') then
        -- Informar del estado de la task actual y si no tiene task, dejar seleccionar una
        if HAVE_TASK then
            if PLAYER_TASK_COUNT then
                -- Task already started with kills
                selfSay("You are hunting "..MONSTER_ID.NAME.."s ("..PLAYER_TASK_COUNT.."/"..MONSTER_NAME.COUNT").")
            else
                -- Task started but 0 kills
                selfSay("You are hunting "..MONSTER_ID.NAME.."s (0/"..MONSTER_NAME.COUNT..".")
            end
            status = 0
        else
            selfSay("Choose a task difficulty: easy, medium, hard.")
            status = 1
        end
    elseif msgcontains(string.lower(msg), 'reward') or msgcontains(string.lower(msg), 'finish') then
        -- Dar reward si ha acabado la task
        status = 2
    elseif msgcontains(string.lower(msg), 'cancel') then
        -- Cancelar task si tiene alguna en curso
        if HAVE_TASK then
            selfSay("Are you sure you want to cancel the "..MONSTER_ID.NAME.."s task?")
            status = 3
        else
            selfSay("You don't have a task.")
            status = 0
        end      
    end  
   
    if status == 1 then
        -- Seleccionar task
        if msgcontains(string.lower(msg), 'easy') then
            selfSay("Easy tasks: rat.")
            status = 4
        elseif msgcontains(string.lower(msg), 'medium') then
            selfSay("Medium tasks: .")
            status = 4
        elseif msgcontains(string.lower(msg), 'hard') then
            selfSay("Hard tasks: .")
            status = 4
        end
    elseif status == 2 then
        if TASK_FINISHED then
            selfSay("Congratulations! You've finished the "..MONSTER_ID.NAME.."s task!")
            setPlayerStorageValue(cid, MAIN_STORAGE, 0)
            doPlayerAddExperience(cid, MONSTER_NAME.REWARD)
            status = 0
        end
    elseif status == 3 then
        if msgcontains(string.lower(msg), 'yes') then
            setPlayerStorageValue(cid, MAIN_STORAGE, 0)
            selfSay("Your task has been cancelled.")
            status = 0
        elseif msgcontains(string.lower(msg), 'no') then
            status = 0
        end
    elseif status == 4 then
        -- Asignar task
        local MONSTER = CONFIG[string.lower(msg)]
        if(not MONSTER) then
            selfSay("I don't know that creature...")
        else
            setPlayerStorageValue(cid, MAIN_STORAGE, MONSTER.STORAGE)
            setPlayerStorageValue(cid, MONSTER.STORAGE, 0)
            selfSay("You've started the "..msg.." task.")
            status = 0
        end      
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top