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

Melchior Npc

psychosisneamia

~Beginner~
Joined
Jun 7, 2012
Messages
162
Reaction score
7
Hi everyone, I found a script for the Npc Melchior and I get an error I was wondering if anyone could help.

The scripts I have are:

Melchior.xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Melchior" script="data/npc/scripts/Melchior.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="130" head="0" body="25" legs="59" feet="115" addons="0"/>
</npc>

Melchior.lua

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

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 function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local player = Player(cid)
    -- WORD OF GREET
    if(msgcontains(msg, "word of greeting")) then
        if player:getStorageValue(Factions) < 1 then
            npcHandler.topic[cid] = 0
            npcHandler:say({"The djinns have an ancient code of honour. This code includes a special concept of hospitality. Anybody who utters the word of greeting must not be attacked even if he is an enemy. Well, at least that is what the code says. ...","I have found out, though, that this does not work at all times. There is no point to say the word of greeting to an enraged djinn. ...","I can tell you the word of greeting if you're interested. It is {DJANNI'HAH}. Remember this word well, stranger. It might save your life one day. ...","And keep in mind that you must choose sides in this conflict. You can only follow the Efreet or the Marid - once you have made your choice there is no way back. I know from experience that djinn do not tolerate double-crossing."}, cid, 0, 1, 4000)
            player:setStorageValue(Factions, 2)
        end
    end
    return true
end

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

The error I run into in the console is:

Code:
 data/npc/scripts/Melchior.lua:7: in function 'callback'
data/npc/scripts/Melchior.lua:14: in function 'onCreatureSay'
 
Tfs 0.3.7

Full Error:

Code:
 Error -NpcScript Interface ]
data/npc/scripts/Melchior.lua:onCreatureSay
Description :
data/npc/scripts/Melchior.lua:14: attempt to call global 'Player' <a nil value>
stack traceback:
data/npc/scripts/Melchior.lua:14: in function 'callback'
data/npc/lib/npchandler.lua:455: in function OnCreatureSay
data/npc/scripts/Melchior.lua:7: in function <data/npc/scripts/Mechior.lua:7>
 
This script is for TFS 1.0.
Remove this
Code:
local player = Player(cid)

I don't see Factions defined in this script, if it's defined somewhere else you can keep it like that, else change it to a number.
But change the player:getStorageValue to getPlayerStorageValue or getCreatureStorage and player:setStorageValue to setPlayerStorageValue or doCreatureSetStorage.
Don't forgot to add cid and remove npcHandler.topic[cid] = 0.
 
Okay, here is my lua script
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    -- WORD OF GREET
    if(msgcontains(msg, "word of greeting")) then
        if player:getCreatureStorage(Factions) < 1 then
            npcHandler:say({"The djinns have an ancient code of honour. This code includes a special concept of hospitality. Anybody who utters the word of greeting must not be attacked even if he is an enemy. Well, at least that is what the code says. ...","I have found out, though, that this does not work at all times. There is no point to say the word of greeting to an enraged djinn. ...","I can tell you the word of greeting if you're interested. It is {DJANNI'HAH}. Remember this word well, stranger. It might save your life one day. ...","And keep in mind that you must choose sides in this conflict. You can only follow the Efreet or the Marid - once you have made your choice there is no way back. I know from experience that djinn do not tolerate double-crossing."}, cid, 0, 1, 4000)
            getPlayerStorageValue =(cid)
        end
    end
    return true
end

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

It crashes my game before i can see what the error is. Any idea what I did wrong?
 
Like this (I did 61900 as example, incase Factions is not defined).
Code:
getCreatureStorage(cid, 61900)
Code:
doCreatureSetStorage(cid, 61900, 1)
 
okay I have done this, This is the new code I have:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    -- WORD OF GREET
    if(msgcontains(msg, "word of greeting")) then
        if getCreatureStorage(cid, 0) then
            npcHandler:say({"The djinns have an ancient code of honour. This code includes a special concept of hospitality. Anybody who utters the word of greeting must not be attacked even if he is an enemy. Well, at least that is what the code says. ...","I have found out, though, that this does not work at all times. There is no point to say the word of greeting to an enraged djinn. ...","I can tell you the word of greeting if you're interested. It is {DJANNI'HAH}. Remember this word well, stranger. It might save your life one day. ...","And keep in mind that you must choose sides in this conflict. You can only follow the Efreet or the Marid - once you have made your choice there is no way back. I know from experience that djinn do not tolerate double-crossing."}, cid, 0, 1, 4000)
           doCreatureSetStorage(cid, 0, 1)
        end
    end
    return true
end

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

There is no Error; However when you say "Word of Greetings" to the npc he replies with nothing. Just his name and a blank message.
Melchior: (Nothing)

Any idea?
 
I tried that originally, And I thought I must of did something wrong because it gave me the error:
Code:
 Error- Talkaction [Interface]
data/talkactions/scripts/createitem,lua:onSay
Descriptions:
<LuaInterface::luaDoDecayItem> Item not found

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

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 function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    -- WORD OF GREET
    if(msgcontains(msg, "word of greeting")) then
       if getCreatureStorage(cid, 61900) < 1 then
            npcHandler:say({"The djinns have an ancient code of honour. This code includes a special concept of hospitality. Anybody who utters the word of greeting must not be attacked even if he is an enemy. Well, at least that is what the code says. ...","I have found out, though, that this does not work at all times. There is no point to say the word of greeting to an enraged djinn. ...","I can tell you the word of greeting if you're interested. It is {DJANNI'HAH}. Remember this word well, stranger. It might save your life one day. ...","And keep in mind that you must choose sides in this conflict. You can only follow the Efreet or the Marid - once you have made your choice there is no way back. I know from experience that djinn do not tolerate double-crossing."}, cid, 0, 1, 4000)
           doCreatureSetStorage(cid, 61900, 1)
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Weird, Heres my code. No error related to this script. However when you say "word of greeting" you get no reply.

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

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 function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    -- WORD OF GREET
    if(msgcontains(msg, "word of greeting")) then
        if getCreatureStorage(cid, 61900) < 1 then
            npcHandler:say({"The djinns have an ancient code of honour. This code includes a special concept of hospitality. Anybody who utters the word of greeting must not be attacked even if he is an enemy. Well, at least that is what the code says. ...","I have found out, though, that this does not work at all times. There is no point to say the word of greeting to an enraged djinn. ...","I can tell you the word of greeting if you're interested. It is {DJANNI'HAH}. Remember this word well, stranger. It might save your life one day. ...","And keep in mind that you must choose sides in this conflict. You can only follow the Efreet or the Marid - once you have made your choice there is no way back. I know from experience that djinn do not tolerate double-crossing."}, cid, 0, 1, 4000)
            doCreatureSetStorage(cid, 61900, 1)
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Maybe the character you test it with already has storage 61900 with value 1.
You can write else under doCreatureSetStorage and then under that a message from the npc to see it that is the problem.
If it doesn't respond with using npcHandler:say, you can also use selfSay
Code:
selfSay("Text.", cid)
 
Back
Top