• 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 Oldrak error

mocoba

New Member
Joined
Aug 23, 2008
Messages
332
Reaction score
0
i found this error
PHP:
[Error - Npc interface]
data/npc/scripts/oldrak.lua:onCreatureSay
Description:
data/npc/scripts/oldrak.lua:45: attempt to compare number with nil
stack traceback:
        data/npc/scripts/oldrak.lua:45: in function 'callback'
        data/npc/lib/npcsystem/npchandler.lua:383: in function 'onCreatureSay'
        data/npc/scripts/oldrak.lua:8: in function <data/npc/scripts/oldrak.lua:
and oldrak.lua
PHP:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
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 creatureSayCallback(cid, type, msg)
 
        if(not npcHandler:isFocused(cid)) then
                return false
        end
 
        local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
        if msgcontains(msg, 'hallowed axe') then
                selfSay('Do you want to buy a Hallowed Axe from me?', cid)
                talkState[talkUser] = 1
        elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
                local price = 1000
                if getPlayerItemCount(cid, 2386) >= 1 and getPlayerMoney(cid) >= price then
                        if doPlayerRemoveMoney(cid, price) then
                                selfSay('Here you are. You can now defeat the demon oak with this axe.', cid)
                                doPlayerRemoveItem(cid, 2386, 1)
                                doPlayerAddItem(cid, 8293, 1)
                                talkState[talkUser] = 0
                        end
                else
                        selfSay('I need an axe and ' .. price .. ' gold coins to make you a {hallowed axe}.', cid)
                        talkState[talkUser] = 0
                end
        elseif msgcontains(msg, 'demon oak') then
                selfSay('Did you defeat the demon oak?', cid)
                talkState[talkUser] = 2
        elseif msgcontains(msg, 'yes') and talkState[talkUser] == 2 then
                if getPlayerStorageValue(cid, 35700) == 1 then
                        selfSay('Good job!', cid)
                        doPlayerSetStorageValue(cid, 35700, 2)
                        talkState[talkUser] = 0
                else
                        selfSay('Go defeat the demon oak first.', cid)
                        talkState[talkUser] = 0
                end
        elseif msgcontains(msg, 'no') and (talkState[talkUser] >= 1 and talkState[talkUser] <= 3) then
                selfSay('Ok thanks.', cid)
                talkState[talkUser] = 0
        end
        return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Thanks i Sure Repp++
 
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
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
-- OTServ event handling functions end

function creatureSayCallback(cid, type, msg)
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    if (not npcHandler:isFocused(cid)) then
        return false
    end

        if msgcontains(msg, 'hallowed axe') then
                npcHandler:say('Do you want to buy a Hallowed Axe from me?', cid)
                talk_state = 1
        elseif msgcontains(msg, 'yes') and talk_state == 1 then
                local price = 1000
            if getPlayerItemCount(cid, 2386) >= 1 and getPlayerMoney(cid) >= price then
                if doPlayerRemoveMoney(cid, price) == true then
                    npcHandler:say('Here you are. You can now defeat the demon oak with this axe.', cid)
                    doPlayerRemoveItem(cid, 2386, 1)
                    doPlayerAddItem(cid, 8293, 1)
                    talk_state = 0
                end
            else
                npcHandler:say('I need an axe and ' .. price .. ' gold coins to make you a {hallowed axe}.', cid)
                talk_state = 0
            end
        elseif msgcontains(msg, 'demon oak') then
                npcHandler:say('Did you defeat the demon oak?', cid)
                talk_state = 2
        elseif msgcontains(msg, 'yes') and talk_state == 2 then
            if getPlayerStorageValue(cid, 35700) == 1 then
                npcHandler:say('Good job! Go now to the gravestone south of Demon Oak, you might find something useful there!', cid)
                doPlayerSetStorageValue(cid, 35700, 2)
                talk_state = 0
            else
                npcHandler:say('Go defeat the demon oak first.', cid)
                talk_state = 0
            end
		elseif msgcontains(msg, 'hugo') then
        selfSay('Ah, the bane of the Plains of Havoc, the hidden beast, the unbeatable foe. I live here for years and I am sure it\'s only a {myth}.', cid)
        talk_state = 3
		elseif msgcontains(msg, 'myth') and talk_state == 3 then
            selfSay('There are many tales about the fearsome Hugo. It\'s said it is an abomination, accidentally created by {Yenny the Gentle}. It\'s halve demon, halve something else and people say it\'s still alive after dozens of years.', cid)
                talk_state = 4
		elseif msgcontains(msg, 'yenny the gentle') and talk_state == 4 then
            selfSay('Yenny, known as the Gentle, was one of most powerfull magicwielders in ancient times and known throughout the world for her mercy and kindness.', cid)
					setPlayerStorageValue(cid,6664,1)
					talk_state = 5
------------------------------------------------ confirm no ------------------------------------------------
        elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 3) then
            npcHandler:say('Ok thanks.', cid)
            talk_state = 0
        end
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    return true
end



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