• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua NPC not working properly.

dominique120

Science & Reason
Senator
Premium User
Joined
Jun 16, 2013
Messages
3,881
Solutions
3
Reaction score
1,046
Location
Númenor
I have this npc that I am trying to make, it will mark the map and heal the player. I already fixed the console errors but I cant seem to get it to do as I say, when I say mark or heal nothing happens.

This script worked fine in OTX 2.60 for ~9.8. now I want it to work with 0.3.6.

Here is the script.

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local random_texts = {'Welcome to our humble temple.', 'If you are hurt ask me, I\'ll heal you.', 'Feeling lost? Ask me for help.', 'Praise our God. He has power to revive adventurers whose adventure is not over yet!'}
local random_texts_chance = 40 -- percent
local random_texts_interval = 7 -- seconds
local talkState = {}

local function round(num, idp)
    local mult = 10^(idp or 0)
    if num >= 0 then return math.floor(num * mult + 0.5) / mult
    else return math.ceil(num * mult - 0.5) / mult end
end

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()
    if(getCreatureStorage(getNpcId(), 1) < os.time()) then
        doCreatureSetStorage(getNpcId(), 1, os.time() + random_texts_interval)
        if(math.random(1, 100) < random_texts_chance) then
            selfSay(random_texts[math.random(1, #random_texts)])
        end
    end
    npcHandler:onThink()
end
function onPlayerEndTrade(cid)                npcHandler:onPlayerEndTrade(cid)            end
function onPlayerCloseChannel(cid)            npcHandler:onPlayerCloseChannel(cid)        end
        function greetCallback(cid)
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    local msg = {
        "Be greeted. If you need {something} just ask me.",
        "Welcome to our humble temple, " .. getPlayerName(cid) .. ".",
        "Welcome, " .. getPlayerName(cid) .. "! Welcome to the temple of {Enigma City}. If you need {healing}, I can help you.",
        "Hello. How may I help you " .. getPlayerName(cid) .. "?",
        "Come in, " .. getPlayerName(cid) .. "."
    }
    npcHandler:setMessage(MESSAGE_GREET, msg[math.random(1, #msg)])
    talkState[talkUser] = 0
    return true
end

function creatureSayCallback(cid, type, msg)
local blessformula = (2000 + ((math.min(130, getPlayerLevel(cid)) - 30) * 200))
if blessformula < 2000 then blessformula = 2000 end
local pvpbformula = (2000 + ((math.min(270, getPlayerLevel(cid)) - 30) * 200))
if pvpbformula < 2000 then pvpbformula = 2000 end
end
local function allformula(cid)
havebless = {}
havepvpbless = 1
local blessformula = (2000 + ((math.min(130, getPlayerLevel(cid)) - 30) * 200))
if blessformula < 2000 then blessformula = 2000 end
local pvpbformula = (2000 + ((math.min(270, getPlayerLevel(cid)) - 30) * 200))
if pvpbformula < 2000 then pvpbformula = 2000 end

    if(not npcHandler:isFocused(cid)) then
        return false
    end

    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    if(msgcontains(msg, 'map') or msgcontains(msg, 'mark')) then
    selfSay('Do you want me to mark your map with important locations in our town?', cid)
    talkState[talkUser] = 1
    end
    if msgcontains(msg, "yes") and talkState[talkUser] == 1 then
        local marks = {
        {mark = 5, pos = {x = 256, y = 256, z = 7}, desc = "Enigma City Temple"},
        {mark = 10, pos = {x = 287, y = 254, z = 7}, desc = "Depot with bank"},
        {mark = 13, pos = {x = 303, y = 247, z = 7}, desc = "Food store"},
        {mark = 8, pos = {x = 278, y = 236, z = 7}, desc = "Smithery"},
        {mark = 8, pos = {x = 271, y = 226, z = 7}, desc = "Distance weapons shop"},
        {mark = 13, pos = {x = 268, y = 241, z = 7}, desc = "Jewellery, magic shop and music instruments shop"},
        {mark = 13, pos = {x = 303, y = 247, z = 7}, desc = "Food store and magic shop"},
        {mark = 7, pos = {x = 252, y = 242, z = 7}, desc = "Tools and furniture"},
        {mark = 13, pos = {x = 258, y = 237, z = 7}, desc = "Creature products and fashion"},
        {mark = 9, pos = {x = 234, y = 215, z = 7}, desc = "Boat"},
    }
    local f_addMark = doPlayerAddMapMark
    if(not f_addMark) then f_addMark = doAddMapMark end
    for _, m  in pairs(marks) do
        f_addMark(cid, m.pos, m.mark, m.desc ~= nil and m.desc or "")
    end
    selfSay('Here you are.', cid)
    talkState[talkUser] = 0
    end
    if (msgcontains(msg, "no") and talkState[talkUser] == 1) or (msgcontains(msg, "no") and talkState[talkUser] == 9) then
    selfSay('May God guide your path then.', cid)
    talkState[talkUser] = 0
    end
    if msgcontains(msg, "heal") then
        if getCreatureCondition(cid, CONDITION_FIRE) == TRUE then
            npcHandler:say("You are burning. I will use water on you.", cid)
            doRemoveCondition(cid, CONDITION_FIRE)
            doSendMagicEffect(getCreaturePosition(cid), 14)
        elseif getCreatureCondition(cid, CONDITION_POISON) == TRUE then
            npcHandler:say("You are poisoned. I will cure you.", cid)
            doRemoveCondition(cid, CONDITION_POISON)
            doSendMagicEffect(getCreaturePosition(cid), 13)
        elseif getCreatureCondition(cid, CONDITION_ENERGY) == TRUE then
            npcHandler:say("You are electrificed. I will help you.", cid)
            doRemoveCondition(cid, CONDITION_ENERGY)
            doSendMagicEffect(getCreaturePosition(cid), 12)
        elseif getCreatureCondition(cid, CONDITION_PARALYZE) == TRUE then
            npcHandler:say("You are paralyzed. I will cure you.", cid)
            doRemoveCondition(cid, CONDITION_PARALYZE)
            doSendMagicEffect(getCreaturePosition(cid), 14)
        elseif getCreatureCondition(cid, CONDITION_DROWN) == TRUE then
            npcHandler:say("You are drowing. I will help you.", cid)
            doRemoveCondition(cid, CONDITION_DROWN)
            doSendMagicEffect(getCreaturePosition(cid), 12)
        elseif getCreatureCondition(cid, CONDITION_FREEZING) == TRUE then
            npcHandler:say("You are cold! I will burn you.", cid)
            doRemoveCondition(cid, CONDITION_FREEZING)
            doSendMagicEffect(getCreaturePosition(cid), 15)
        elseif getCreatureCondition(cid, CONDITION_DAZZLED) == TRUE then
            npcHandler:say("You are dazzled! Do not mess with holy creatures anymore!", cid)
            doRemoveCondition(cid, CONDITION_DAZZLED)
            doSendMagicEffect(getCreaturePosition(cid), 47)
        elseif getCreatureCondition(cid, CONDITION_CURSED) == TRUE then
            npcHandler:say("You are cursed! I will remove it.", cid)
            doRemoveCondition(cid, CONDITION_CURSED)
            doSendMagicEffect(getCreaturePosition(cid), 47)
        elseif getCreatureHealth(cid) < 200 then
            npcHandler:say("You are looking really bad. Let me heal your wounds.", cid)
            doCreatureAddHealth(cid, 65 - getCreatureHealth(cid))
            doSendMagicEffect(getCreaturePosition(cid), 12)
        elseif getCreatureHealth(cid) < 2000 then
            npcHandler:say("I did my best to fix your wounds.", cid)
            doCreatureAddHealth(cid, 2000 - getCreatureHealth(cid))
            doSendMagicEffect(getCreaturePosition(cid), 12)
        else
            local msgheal = {
                "You aren't looking really bad, " .. getCreatureName(cid) .. ". I only help in cases of real emergencies. Raise your health simply by eating food.",
                "Seriously? It's just a scratch",
                "Don't be a child. You don't need any help with your health.",
                "I'm not an expert. If you need help find a medic.",
                "Don't even waste my time, I have bigger problems than your scratched armor."
            }
            npcHandler:say("" .. msgheal[math.random(1, #msgheal)] .. "", cid)
        end
    end

    return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Hello,

so hes answering your greet but when you try mark or heal nothing happends? If you get no errors in the console I doubt it's any syntax error, could be this part:
Code:
if(not npcHandler:isFocused(cid)) then 
return false 
 end

probably return false and kills the script. Try to uncomment it and see if it works.
 
Back
Top