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

Healing NPC Script (Creature not found)

revion

New Member
Joined
Oct 27, 2009
Messages
46
Reaction score
0
Hello!
I wanted to have NPC like, for example Cipfried from real tibia, who is healing a player when his hp is lower than 65.
But when player (having hp <65) says 'heal' to him, then NPC just says the text and doesn't heal him.
In my console I get this:
Code:
[Error - Npc interface]
data/npc/scripts/heal.lua:onCreatureSay
Description:
(luaGetThingPosition) Thing not found

[Error - Npc interface]
data/npc/scripts/heal.lua:onCreatureSay
Description:
(luaDoCreatureAddHealth) Creature not found
Here is my script for this NPC (texts which NPC has are in Polish :P):
Code:
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


-------------------------------------Healing Part------------------------------
function healCreature(cid, message, keywords, parameters)
    if(getCreatureHealth(cid) < parameters.maxheal) then
        position = getCreaturePosition(npcHandler.focus)
        doSendMagicEffect(position, 12)
        local healHP = parameters.maxheal - getCreatureHealth(cid)
        doCreatureAddHealth(npcHandler.focus,healHP)
        npcHandler:say('Wygladasz naprawde zle, pozwol ze cie wylecze.', cid)
    else
        npcHandler:say('Nie wygladasz az tak zle, ' .. getCreatureName(cid) .. '. Pomagam tylko w awaryjnych sytuacjach. Mozesz zwiekszyc ilosc swojego zycia dzieki jedzeniu.', cid)
    end    
    return true
end

function healCreatureNoMsg(cid, maxheal)
    if(getCreatureHealth(cid) < maxheal) then
        position = getCreaturePosition(npcHandler.focus)
        doSendMagicEffect(position, 12)
        local healHP = maxheal - getCreatureHealth(cid)
        doCreatureAddHealth(npcHandler.focus,healHP)
        npcHandler:say('Hello, ' .. getCreatureName(cid) .. '! Wygladasz naprawde zle. Pozwol ze cie wylecze.', cid)
    end    
    return true
end


function farewell(cid, message, keywords, parameters)         return npcHandler:defaultFarewellHandler(cid, message, keywords, parameters) end

keywordHandler:addKeyword({'heal'},     healCreature, {maxheal = 65})
keywordHandler:addKeyword({'help'},     healCreature, {maxheal = 65})


npcHandler:addModule(FocusModule:new())
Please help me :P
 
if error is only this then...

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


-------------------------------------Healing Part------------------------------
function healCreature(cid, message, keywords, parameters)
    if(getCreatureHealth(cid) < parameters.maxheal) then
        position = getCreaturePosition(npcHandler.focus)
        doSendMagicEffect(position, 12)
        local healHP = parameters.maxheal - getCreatureHealth(cid)
        doCreatureAddHealth(cid, healHP)
        npcHandler:say('Wygladasz naprawde zle, pozwol ze cie wylecze.', cid)
    else
        npcHandler:say('Nie wygladasz az tak zle, ' .. getCreatureName(cid) .. '. Pomagam tylko w awaryjnych sytuacjach. Mozesz zwiekszyc ilosc swojego zycia dzieki jedzeniu.', cid)
    end    
    return true
end

function healCreatureNoMsg(cid, maxheal)
    if(getCreatureHealth(cid) < maxheal) then
        position = getCreaturePosition(npcHandler.focus)
        doSendMagicEffect(position, 12)
        local healHP = maxheal - getCreatureHealth(cid)
        doCreatureAddHealth(cid, healHP)
        npcHandler:say('Hello, ' .. getCreatureName(cid) .. '! Wygladasz naprawde zle. Pozwol ze cie wylecze.', cid)
    end    
    return true
end


function farewell(cid, message, keywords, parameters)         return npcHandler:defaultFarewellHandler(cid, message, keywords, parameters) end

keywordHandler:addKeyword({'heal'},     healCreature, {maxheal = 65})
keywordHandler:addKeyword({'help'},     healCreature, {maxheal = 65})


npcHandler:addModule(FocusModule:new())
 
Last edited:
mm try it
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

function creatureSayCallback(cid, type, msg)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	if (msgcontains(msg, "hello") or msgcontains(msg, "hi")) and not npcHandler:isFocused(cid) then
		if getCreatureHealth(cid) < 65 then
			npcHandler:say("Hello, "..getCreatureName(cid).."! You are looking really bad. Let me heal your wounds.", cid)
			doCreatureAddHealth(cid, 65 - getCreatureHealth(cid))
			doSendMagicEffect(getCreaturePosition(cid), 12)
		else
			selfSay("Hello, "..getCreatureName(cid).."! I'll {heal} you if you are badly injured or poisoned. Feel free to ask me for {help} or general {hints}.", cid, TRUE)
			npcHandler:addFocus(cid)
		end
		return true
	end
	if(not npcHandler:isFocused(cid)) then
		return false
	elseif msgcontains(msg, "bye") or msgcontains(msg, "farewell") then
		selfSay("Farewell, " .. getCreatureName(cid) .. "!", cid, TRUE)
		npcHandler:releaseFocus(cid)
	elseif msgcontains(msg, "heal") then
		if getCreatureCondition(cid, CONDITION_FIRE) == TRUE then
			npcHandler:say("You are burning. I will help you.", cid)
			doRemoveCondition(cid, CONDITION_FIRE)
			doSendMagicEffect(getCreaturePosition(cid), 14)
		elseif getCreatureCondition(cid, CONDITION_POISON) == TRUE then
			npcHandler:say("You are poisoned. I will help you.", cid)
			doRemoveCondition(cid, CONDITION_POISON)
			doSendMagicEffect(getCreaturePosition(cid), 13)
		elseif getCreatureHealth(cid) < 65 then
			npcHandler:say("You are looking really bad. Let me heal your wounds.", cid)
			doCreatureAddHealth(cid, 65 - getCreatureHealth(cid))
			doSendMagicEffect(getCreaturePosition(cid), 12)
		else
			npcHandler:say("You aren't looking really bad, " .. getCreatureName(cid) .. ". I only help in cases of real emergencies. Raise your health simply by eating {food}.", cid)
		end
	end
	return TRUE
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_WALKAWAY, "Well, bye then.")
 
Back
Top