• 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 Another healing NPC problem

Rudixx

New Member
Joined
Aug 3, 2007
Messages
246
Reaction score
0
Location
England
I want to make NPC which will heal player under 65 hp and also he will delete conditions such poisonous. Here is the code:

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()
	talk = math.random(1,40)
	if talk == 1 then
		selfSay("Long life to the king!")
	end
end

function creatureSayCallback(cid, type, msg)
	if(npcHandler.focus ~= cid) then
		return FALSE
	end
 if msgcontains(msg, 'heal') and getCreatureHealth(cid) < 65 then
		selfSay("You're hurt, let me heal you.")
		heal = 65 - getCreatureHealth(cid)
		doCreatureAddHealth(cid, heal)
		doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE)
	elseif msgcontains(msg, 'heal') and getCreatureHealth(cid) >= 65 then
		selfSay("You aren\'t looking really bad, |PLAYERNAME|. I only help in cases of real emergencies. Raise your health simply by eating food.")
	end

	end
	return TRUE
end


keywordHandler:addKeyword({'food'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Food is very important for your health. If you are hurt in a fight with a monster, select \'Use\' on food such as cheese, ham or meat to eat it. This will slowly refill yourhealth.'})

keywordHandler:addKeyword({'monster'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Monsters are a constant threat to this village. You would tremendously help us by fighting them, starting with rats in the sewers, then turning to spiders or wolves.'})

keywordHandler:addKeyword({'rats'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'A single rat doesn\'t pose a grave danger to you, but be careful not to get cornered by many of them. They could still kill you.'})

keywordHandler:addKeyword({'kill'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'If you get killed, you will revive in this temple. However, you will lose experience and also equipment, which can be quite painful. Take good care of yourself!'})

keywordHandler:addKeyword({'sewers'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'The sewers are right below this village. North of this temple, you find a sewer grate which leads down, but there are also many small huts in the village which areconnected to the sewers.'})

keywordHandler:addKeyword({'spiders'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'If you face spiders, beware of the poisonous ones. If you are poisoned, you will constantly lose health. Come to me and I\'ll heal you from poison.'})

keywordHandler:addKeyword({'wolves'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Wolves can only be found outside of the village. If you want to know where their dens are, best talk to Dallheim or Zerbrus at the bridges.'})

keywordHandler:addKeyword({'dallheim'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'May the gods bless our loyal guardsmen! Day and night they stand watch on our bridges, ensuring that it is not passed by dangerous monsters!'})

keywordHandler:addKeyword({'zerbrus'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'May the gods bless our loyal guardsmen! Day and night they stand watch on our bridges, ensuring that it is not passed by dangerous monsters!'})

keywordHandler:addKeyword({'poisonous'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Poison is very dangerous! Don\'t ever drink green liquids, they are poisonous and will make you lose health!'})

keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'How can I help you? I can tell you about specific citizens if you tell me their name. I can also give you general hints about Tibia.'})

keywordHandler:addKeyword({'citizens'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Only a few people live in our village, most of them being merchants. You can either ask them for a trade or about various other topics, like the names of other citizens, their job or Tibia in general.'})

keywordHandler:addKeyword({'merchants'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You can buy and sell goods from merchants. To do so, simply talk to them and ask them for a trade. They will gladly show you their offers and also the things they buy from you.'})

keywordHandler:addKeyword({'trade'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I don\'t have any goods for trade, but if you ask one of the merchants, he or she will gladly show you what you can buy or sell.'})

keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Me? Oh, I am just a humble monk. Ask me if you need help or healing.'})

keywordHandler:addKeyword({'monk'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sacrifice my life to serve the good gods of Tibia and help newcomers to this world.'})

keywordHandler:addKeyword({'tibia'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'That\'s where we are. The world of Tibia. In a village called Rookgaard, to be precise, with many monsters, quests and citizens around.'})

keywordHandler:addKeyword({'rookgaard'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'The gods have chosen this isle as the point of arrival for the newborn souls. The citizens will help you  if you ask them.'})

keywordHandler:addKeyword({'quests'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Oh, I can handle my tasks myself, thank you. If you are looking for something to do, you should listen to the local citizens and ask them for quests. You could also help usfight monsters.'})

keywordHandler:addKeyword({'gods'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'They created Tibia and all life on it. Visit our academy and learn about them.'})

keywordHandler:addKeyword({'academy'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'The academy is just to the north of here. Talk to Seymour, the teacher, if you want to learn more things about the world of Tibia. Also, you can try out a few basicthings in the cellar of the academy.'})

keywordHandler:addKeyword({'seymour'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Seymour is a loyal follower of the king and a teacher in the academy.'})

keywordHandler:addKeyword({'king'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Well, King Tibianus of course. The island of Rookgaard belongs to his kingdom.'})

keywordHandler:addKeyword({'hints'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'If you don\'t know the meaning of an icon on the right side, move the mouse cursor on it and wait a moment.'})

keywordHandler:addKeyword({'cipfried'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Yes? How can I help you?'})

keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'My name is Cipfried.'})

keywordHandler:addKeyword({'willie'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Willie is a farmer, just like his cousin Billy. His farm is located to the left of the temple. You can buy and sell food there.'})

keywordHandler:addKeyword({'billy'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'He is a farmer, just like his cousin Willie. He doesn\'t talk to everybody, though.'})

keywordHandler:addKeyword({'gold'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You can earn a fair amount of gold by fighting monsters and picking up the things they carry. Many citizens are buying some of that loot, simply ask around.'})

keywordHandler:addKeyword({'equipment'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You can buy equipment from the merchants in this village once you earned some gold. Some monsters also carry equipment pieces with them.'})


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

And error message in ot console:

Code:
Cipfried.lua:31: '<eof>' expected near 'end'


Signed,
Rudixx
 
Code:
if getCreatureCondition(cid, CONDITION_POISON) == TRUE then
    doRemoveCondition(cid, CONDITION_POISON)
end
 
Hello!

Try this:
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()
	talk = math.random(1,40)
	if talk == 1 then
		selfSay("Long life to the king!")
	end
end

function creatureSayCallback(cid, type, msg)
	if(npcHandler.focus ~= cid) then
		return FALSE
	end
	if msgcontains(msg, 'heal') and getCreatureHealth(cid) < 65 and (getCreatureCondition(cid, CONDITION_POISON)) == TRUE then
    		doRemoveCondition(cid, CONDITION_POISON)
		selfSay("You're hurt, let me heal you.")
		heal = 65 - getCreatureHealth(cid)
		doCreatureAddHealth(cid, heal)
		doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE)
	elseif msgcontains(msg, 'heal') and getCreatureHealth(cid) >= 65 then
		selfSay("You aren\'t looking really bad, |PLAYERNAME|. I only help in cases of real emergencies. Raise your health simply by eating food.")
	elseif msgcontains(msg, 'heal') and getCreatureHealth(cid) < 65 then
		selfSay("You're hurt, let me heal you.")
		heal = 65 - getCreatureHealth(cid)
		doCreatureAddHealth(cid, heal)
		doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE)
[COLOR="Blue"]	end

	[COLOR="Orange"]return TRUE[/COLOR]
end
[/COLOR]

keywordHandler:addKeyword({'food'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Food is very important for your health. If you are hurt in a fight with a monster, select \'Use\' on food such as cheese, ham or meat to eat it. This will slowly refill yourhealth.'})

keywordHandler:addKeyword({'monster'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Monsters are a constant threat to this village. You would tremendously help us by fighting them, starting with rats in the sewers, then turning to spiders or wolves.'})

keywordHandler:addKeyword({'rats'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'A single rat doesn\'t pose a grave danger to you, but be careful not to get cornered by many of them. They could still kill you.'})

keywordHandler:addKeyword({'kill'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'If you get killed, you will revive in this temple. However, you will lose experience and also equipment, which can be quite painful. Take good care of yourself!'})

keywordHandler:addKeyword({'sewers'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'The sewers are right below this village. North of this temple, you find a sewer grate which leads down, but there are also many small huts in the village which areconnected to the sewers.'})

keywordHandler:addKeyword({'spiders'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'If you face spiders, beware of the poisonous ones. If you are poisoned, you will constantly lose health. Come to me and I\'ll heal you from poison.'})

keywordHandler:addKeyword({'wolves'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Wolves can only be found outside of the village. If you want to know where their dens are, best talk to Dallheim or Zerbrus at the bridges.'})

keywordHandler:addKeyword({'dallheim'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'May the gods bless our loyal guardsmen! Day and night they stand watch on our bridges, ensuring that it is not passed by dangerous monsters!'})

keywordHandler:addKeyword({'zerbrus'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'May the gods bless our loyal guardsmen! Day and night they stand watch on our bridges, ensuring that it is not passed by dangerous monsters!'})

keywordHandler:addKeyword({'poisonous'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Poison is very dangerous! Don\'t ever drink green liquids, they are poisonous and will make you lose health!'})

keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'How can I help you? I can tell you about specific citizens if you tell me their name. I can also give you general hints about Tibia.'})

keywordHandler:addKeyword({'citizens'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Only a few people live in our village, most of them being merchants. You can either ask them for a trade or about various other topics, like the names of other citizens, their job or Tibia in general.'})

keywordHandler:addKeyword({'merchants'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You can buy and sell goods from merchants. To do so, simply talk to them and ask them for a trade. They will gladly show you their offers and also the things they buy from you.'})

keywordHandler:addKeyword({'trade'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I don\'t have any goods for trade, but if you ask one of the merchants, he or she will gladly show you what you can buy or sell.'})

keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Me? Oh, I am just a humble monk. Ask me if you need help or healing.'})

keywordHandler:addKeyword({'monk'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sacrifice my life to serve the good gods of Tibia and help newcomers to this world.'})

keywordHandler:addKeyword({'tibia'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'That\'s where we are. The world of Tibia. In a village called Rookgaard, to be precise, with many monsters, quests and citizens around.'})

keywordHandler:addKeyword({'rookgaard'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'The gods have chosen this isle as the point of arrival for the newborn souls. The citizens will help you  if you ask them.'})

keywordHandler:addKeyword({'quests'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Oh, I can handle my tasks myself, thank you. If you are looking for something to do, you should listen to the local citizens and ask them for quests. You could also help usfight monsters.'})

keywordHandler:addKeyword({'gods'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'They created Tibia and all life on it. Visit our academy and learn about them.'})

keywordHandler:addKeyword({'academy'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'The academy is just to the north of here. Talk to Seymour, the teacher, if you want to learn more things about the world of Tibia. Also, you can try out a few basicthings in the cellar of the academy.'})

keywordHandler:addKeyword({'seymour'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Seymour is a loyal follower of the king and a teacher in the academy.'})

keywordHandler:addKeyword({'king'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Well, King Tibianus of course. The island of Rookgaard belongs to his kingdom.'})

keywordHandler:addKeyword({'hints'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'If you don\'t know the meaning of an icon on the right side, move the mouse cursor on it and wait a moment.'})

keywordHandler:addKeyword({'cipfried'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Yes? How can I help you?'})

keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'My name is Cipfried.'})

keywordHandler:addKeyword({'willie'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Willie is a farmer, just like his cousin Billy. His farm is located to the left of the temple. You can buy and sell food there.'})

keywordHandler:addKeyword({'billy'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'He is a farmer, just like his cousin Willie. He doesn\'t talk to everybody, though.'})

keywordHandler:addKeyword({'gold'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You can earn a fair amount of gold by fighting monsters and picking up the things they carry. Many citizens are buying some of that loot, simply ask around.'})

keywordHandler:addKeyword({'equipment'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You can buy equipment from the merchants in this village once you earned some gold. Some monsters also carry equipment pieces with them.'})


npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
That's the same you have but with a deleted end and with the option that removes your poison, of course, if you are poisoned. Add the function that remove you the condition of fire and energy if you want that ,when you say heal, the NPC removes you those conditions too.

Sorry for my English, I'm Spanish.
 
Last edited:
Fixed version. I don't test it, but i think this works.

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()
    local talk = math.random(1, 40)
    if(talk == 1) then
        selfSay("Long life to the king!")
    end
    npcHandler:onThink()
end

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    
    local name = getCreatureName(cid)
    local position = getPlayerPosition(cid)
    local health = getCreatureHealth(cid)
    
    if(msgcontains(msg, 'heal') and health < 65) then
        selfSay('You\'re hurt, let me heal you.', cid)
        doCreatureAddHealth(cid, - (health + 65))
        doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
    elseif(msgcontains(msg, 'heal') and health >= 65) then
        selfSay('You aren\'t looking really bad, '.. name ..'. I only help in cases of real emergencies. Raise your health simply by eating food.', cid)
    end
    
    return TRUE
end


keywordHandler:addKeyword({'food'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Food is very important for your health. If you are hurt in a fight with a monster, select \'Use\' on food such as cheese, ham or meat to eat it. This will slowly refill yourhealth.'})
keywordHandler:addKeyword({'monster'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Monsters are a constant threat to this village. You would tremendously help us by fighting them, starting with rats in the sewers, then turning to spiders or wolves.'})
keywordHandler:addKeyword({'rats'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'A single rat doesn\'t pose a grave danger to you, but be careful not to get cornered by many of them. They could still kill you.'})
keywordHandler:addKeyword({'kill'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'If you get killed, you will revive in this temple. However, you will lose experience and also equipment, which can be quite painful. Take good care of yourself!'})
keywordHandler:addKeyword({'sewers'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'The sewers are right below this village. North of this temple, you find a sewer grate which leads down, but there are also many small huts in the village which areconnected to the sewers.'})
keywordHandler:addKeyword({'spiders'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'If you face spiders, beware of the poisonous ones. If you are poisoned, you will constantly lose health. Come to me and I\'ll heal you from poison.'})
keywordHandler:addKeyword({'wolves'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Wolves can only be found outside of the village. If you want to know where their dens are, best talk to Dallheim or Zerbrus at the bridges.'})
keywordHandler:addKeyword({'dallheim'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'May the gods bless our loyal guardsmen! Day and night they stand watch on our bridges, ensuring that it is not passed by dangerous monsters!'})
keywordHandler:addKeyword({'zerbrus'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'May the gods bless our loyal guardsmen! Day and night they stand watch on our bridges, ensuring that it is not passed by dangerous monsters!'})
keywordHandler:addKeyword({'poisonous'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Poison is very dangerous! Don\'t ever drink green liquids, they are poisonous and will make you lose health!'})
keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'How can I help you? I can tell you about specific citizens if you tell me their name. I can also give you general hints about Tibia.'})
keywordHandler:addKeyword({'citizens'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Only a few people live in our village, most of them being merchants. You can either ask them for a trade or about various other topics, like the names of other citizens, their job or Tibia in general.'})
keywordHandler:addKeyword({'merchants'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You can buy and sell goods from merchants. To do so, simply talk to them and ask them for a trade. They will gladly show you their offers and also the things they buy from you.'})
keywordHandler:addKeyword({'trade'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I don\'t have any goods for trade, but if you ask one of the merchants, he or she will gladly show you what you can buy or sell.'})
keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Me? Oh, I am just a humble monk. Ask me if you need help or healing.'})
keywordHandler:addKeyword({'monk'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sacrifice my life to serve the good gods of Tibia and help newcomers to this world.'})
keywordHandler:addKeyword({'tibia'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'That\'s where we are. The world of Tibia. In a village called Rookgaard, to be precise, with many monsters, quests and citizens around.'})
keywordHandler:addKeyword({'rookgaard'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'The gods have chosen this isle as the point of arrival for the newborn souls. The citizens will help you  if you ask them.'})
keywordHandler:addKeyword({'quests'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Oh, I can handle my tasks myself, thank you. If you are looking for something to do, you should listen to the local citizens and ask them for quests. You could also help usfight monsters.'})
keywordHandler:addKeyword({'gods'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'They created Tibia and all life on it. Visit our academy and learn about them.'})
keywordHandler:addKeyword({'academy'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'The academy is just to the north of here. Talk to Seymour, the teacher, if you want to learn more things about the world of Tibia. Also, you can try out a few basicthings in the cellar of the academy.'})
keywordHandler:addKeyword({'seymour'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Seymour is a loyal follower of the king and a teacher in the academy.'})
keywordHandler:addKeyword({'king'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Well, King Tibianus of course. The island of Rookgaard belongs to his kingdom.'})
keywordHandler:addKeyword({'hints'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'If you don\'t know the meaning of an icon on the right side, move the mouse cursor on it and wait a moment.'})
keywordHandler:addKeyword({'cipfried'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Yes? How can I help you?'})
keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'My name is Cipfried.'})
keywordHandler:addKeyword({'willie'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Willie is a farmer, just like his cousin Billy. His farm is located to the left of the temple. You can buy and sell food there.'})
keywordHandler:addKeyword({'billy'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'He is a farmer, just like his cousin Willie. He doesn\'t talk to everybody, though.'})
keywordHandler:addKeyword({'gold'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You can earn a fair amount of gold by fighting monsters and picking up the things they carry. Many citizens are buying some of that loot, simply ask around.'})
keywordHandler:addKeyword({'equipment'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You can buy equipment from the merchants in this village once you earned some gold. Some monsters also carry equipment pieces with them.'})

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
My script working with 8.31 npc structure, you forgot to change
Code:
if(npcHandler.focus ~= cid) then
   return FALSE
end
with this
Code:
if(not npcHandler:isFocused(cid)) then
   return false
end
Now script removing some conditions.
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()
    local talk = math.random(1, 40)
    if(talk == 1) then
        selfSay("Long life to the king!")
    end
    npcHandler:onThink()
end

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    
    local conditions = {CONDITION_POISON, CONDITION_FIRE, CONDITION_ENERGY, CONDITION_LIFEDRAIN, CONDITION_PARALYZE, CONDITION_DRUNK, CONDITION_FREEZING, CONDITION_DAZZLED, CONDITION_CURSED}
    
    local name = getCreatureName(cid)
    local position = getPlayerPosition(cid)
    local health = getCreatureHealth(cid)
    
    if(msgcontains(msg, 'heal') and health < 65) then
        for i = 1, table.maxn(conditions) do
            doRemoveCondition(cid, conditions[i])
        end
        doCreatureAddHealth(cid, - (health + 65))
        doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
        selfSay('You\'re hurt, let me heal you.', cid)
    elseif(msgcontains(msg, 'heal') and health >= 65) then
        selfSay('You aren\'t looking really bad, '.. name ..'. I only help in cases of real emergencies. Raise your health simply by eating food.', cid)
    end
    
    return TRUE
end


keywordHandler:addKeyword({'food'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Food is very important for your health. If you are hurt in a fight with a monster, select \'Use\' on food such as cheese, ham or meat to eat it. This will slowly refill yourhealth.'})
keywordHandler:addKeyword({'monster'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Monsters are a constant threat to this village. You would tremendously help us by fighting them, starting with rats in the sewers, then turning to spiders or wolves.'})
keywordHandler:addKeyword({'rats'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'A single rat doesn\'t pose a grave danger to you, but be careful not to get cornered by many of them. They could still kill you.'})
keywordHandler:addKeyword({'kill'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'If you get killed, you will revive in this temple. However, you will lose experience and also equipment, which can be quite painful. Take good care of yourself!'})
keywordHandler:addKeyword({'sewers'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'The sewers are right below this village. North of this temple, you find a sewer grate which leads down, but there are also many small huts in the village which areconnected to the sewers.'})
keywordHandler:addKeyword({'spiders'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'If you face spiders, beware of the poisonous ones. If you are poisoned, you will constantly lose health. Come to me and I\'ll heal you from poison.'})
keywordHandler:addKeyword({'wolves'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Wolves can only be found outside of the village. If you want to know where their dens are, best talk to Dallheim or Zerbrus at the bridges.'})
keywordHandler:addKeyword({'dallheim'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'May the gods bless our loyal guardsmen! Day and night they stand watch on our bridges, ensuring that it is not passed by dangerous monsters!'})
keywordHandler:addKeyword({'zerbrus'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'May the gods bless our loyal guardsmen! Day and night they stand watch on our bridges, ensuring that it is not passed by dangerous monsters!'})
keywordHandler:addKeyword({'poisonous'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Poison is very dangerous! Don\'t ever drink green liquids, they are poisonous and will make you lose health!'})
keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'How can I help you? I can tell you about specific citizens if you tell me their name. I can also give you general hints about Tibia.'})
keywordHandler:addKeyword({'citizens'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Only a few people live in our village, most of them being merchants. You can either ask them for a trade or about various other topics, like the names of other citizens, their job or Tibia in general.'})
keywordHandler:addKeyword({'merchants'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You can buy and sell goods from merchants. To do so, simply talk to them and ask them for a trade. They will gladly show you their offers and also the things they buy from you.'})
keywordHandler:addKeyword({'trade'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I don\'t have any goods for trade, but if you ask one of the merchants, he or she will gladly show you what you can buy or sell.'})
keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Me? Oh, I am just a humble monk. Ask me if you need help or healing.'})
keywordHandler:addKeyword({'monk'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sacrifice my life to serve the good gods of Tibia and help newcomers to this world.'})
keywordHandler:addKeyword({'tibia'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'That\'s where we are. The world of Tibia. In a village called Rookgaard, to be precise, with many monsters, quests and citizens around.'})
keywordHandler:addKeyword({'rookgaard'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'The gods have chosen this isle as the point of arrival for the newborn souls. The citizens will help you  if you ask them.'})
keywordHandler:addKeyword({'quests'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Oh, I can handle my tasks myself, thank you. If you are looking for something to do, you should listen to the local citizens and ask them for quests. You could also help usfight monsters.'})
keywordHandler:addKeyword({'gods'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'They created Tibia and all life on it. Visit our academy and learn about them.'})
keywordHandler:addKeyword({'academy'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'The academy is just to the north of here. Talk to Seymour, the teacher, if you want to learn more things about the world of Tibia. Also, you can try out a few basicthings in the cellar of the academy.'})
keywordHandler:addKeyword({'seymour'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Seymour is a loyal follower of the king and a teacher in the academy.'})
keywordHandler:addKeyword({'king'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Well, King Tibianus of course. The island of Rookgaard belongs to his kingdom.'})
keywordHandler:addKeyword({'hints'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'If you don\'t know the meaning of an icon on the right side, move the mouse cursor on it and wait a moment.'})
keywordHandler:addKeyword({'cipfried'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Yes? How can I help you?'})
keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'My name is Cipfried.'})
keywordHandler:addKeyword({'willie'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Willie is a farmer, just like his cousin Billy. His farm is located to the left of the temple. You can buy and sell food there.'})
keywordHandler:addKeyword({'billy'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'He is a farmer, just like his cousin Willie. He doesn\'t talk to everybody, though.'})
keywordHandler:addKeyword({'gold'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You can earn a fair amount of gold by fighting monsters and picking up the things they carry. Many citizens are buying some of that loot, simply ask around.'})
keywordHandler:addKeyword({'equipment'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You can buy equipment from the merchants in this village once you earned some gold. Some monsters also carry equipment pieces with them.'})

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Uhms... ok sorry, I didn't saw that.
I have a question, I'm scripter, yes, but not many 'expert'.
Can you explain me this part?:
for i = 1, table.maxn(conditions) do
doRemoveCondition(cid, conditions)
end



Thanks ;)
 
I read it but I don't understand it too much xD.
table.maxn (table)

Returns the largest positive numerical index of the given table, or zero if the table has no positive numerical indices. (To do its job this function does a linear traversal of the whole table.)
Use a translator Polish/English and I will read your post (if it's a bad english, no problem).
I want an easy example, sorry to trouble you.
 
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()
    local talk = math.random(1, 40)
    if(talk == 1) then
        selfSay("Long life to the king!")
    end
    npcHandler:onThink()
end

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end

    local conditions = {CONDITION_POISON, CONDITION_FIRE, CONDITION_ENERGY, CONDITION_LIFEDRAIN, CONDITION_PARALYZE, CONDITION_DRUNK, CONDITION_FREEZING, CONDITION_DAZZLED, CONDITION_CURSED}

    local name = getCreatureName(cid)
    local position = getPlayerPosition(cid)
    local health = getCreatureHealth(cid)

    if(msgcontains(msg, 'heal') and health < 65) then
        for i = 1, table.maxn(conditions) do
            doRemoveCondition(cid, conditions)
        end
        doCreatureAddHealth(cid, 65)
        doSendMagicEffect(position, CONST_ME_MAGIC_BLUE)
        selfSay('You\'re hurt, let me heal you.', cid)
    elseif(msgcontains(msg, 'heal') and health >= 65) then
        selfSay('You aren\'t looking really bad, '.. name ..'. I only help in cases of real emergencies. Raise your health simply by eating food.', cid)
    end

    return TRUE
end


keywordHandler:addKeyword({'food'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Food is very important for your health. If you are hurt in a fight with a monster, select \'Use\' on food such as cheese, ham or meat to eat it. This will slowly refill yourhealth.'})
keywordHandler:addKeyword({'monster'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Monsters are a constant threat to this village. You would tremendously help us by fighting them, starting with rats in the sewers, then turning to spiders or wolves.'})
keywordHandler:addKeyword({'rats'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'A single rat doesn\'t pose a grave danger to you, but be careful not to get cornered by many of them. They could still kill you.'})
keywordHandler:addKeyword({'kill'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'If you get killed, you will revive in this temple. However, you will lose experience and also equipment, which can be quite painful. Take good care of yourself!'})
keywordHandler:addKeyword({'sewers'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'The sewers are right below this village. North of this temple, you find a sewer grate which leads down, but there are also many small huts in the village which areconnected to the sewers.'})
keywordHandler:addKeyword({'spiders'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'If you face spiders, beware of the poisonous ones. If you are poisoned, you will constantly lose health. Come to me and I\'ll heal you from poison.'})
keywordHandler:addKeyword({'wolves'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Wolves can only be found outside of the village. If you want to know where their dens are, best talk to Dallheim or Zerbrus at the bridges.'})
keywordHandler:addKeyword({'dallheim'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'May the gods bless our loyal guardsmen! Day and night they stand watch on our bridges, ensuring that it is not passed by dangerous monsters!'})
keywordHandler:addKeyword({'zerbrus'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'May the gods bless our loyal guardsmen! Day and night they stand watch on our bridges, ensuring that it is not passed by dangerous monsters!'})
keywordHandler:addKeyword({'poisonous'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Poison is very dangerous! Don\'t ever drink green liquids, they are poisonous and will make you lose health!'})
keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'How can I help you? I can tell you about specific citizens if you tell me their name. I can also give you general hints about Tibia.'})
keywordHandler:addKeyword({'citizens'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Only a few people live in our village, most of them being merchants. You can either ask them for a trade or about various other topics, like the names of other citizens, their job or Tibia in general.'})
keywordHandler:addKeyword({'merchants'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You can buy and sell goods from merchants. To do so, simply talk to them and ask them for a trade. They will gladly show you their offers and also the things they buy from you.'})
keywordHandler:addKeyword({'trade'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I don\'t have any goods for trade, but if you ask one of the merchants, he or she will gladly show you what you can buy or sell.'})
keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Me? Oh, I am just a humble monk. Ask me if you need help or healing.'})
keywordHandler:addKeyword({'monk'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I sacrifice my life to serve the good gods of Tibia and help newcomers to this world.'})
keywordHandler:addKeyword({'tibia'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'That\'s where we are. The world of Tibia. In a village called Rookgaard, to be precise, with many monsters, quests and citizens around.'})
keywordHandler:addKeyword({'rookgaard'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'The gods have chosen this isle as the point of arrival for the newborn souls. The citizens will help you  if you ask them.'})
keywordHandler:addKeyword({'quests'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Oh, I can handle my tasks myself, thank you. If you are looking for something to do, you should listen to the local citizens and ask them for quests. You could also help usfight monsters.'})
keywordHandler:addKeyword({'gods'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'They created Tibia and all life on it. Visit our academy and learn about them.'})
keywordHandler:addKeyword({'academy'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'The academy is just to the north of here. Talk to Seymour, the teacher, if you want to learn more things about the world of Tibia. Also, you can try out a few basicthings in the cellar of the academy.'})
keywordHandler:addKeyword({'seymour'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Seymour is a loyal follower of the king and a teacher in the academy.'})
keywordHandler:addKeyword({'king'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Well, King Tibianus of course. The island of Rookgaard belongs to his kingdom.'})
keywordHandler:addKeyword({'hints'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'If you don\'t know the meaning of an icon on the right side, move the mouse cursor on it and wait a moment.'})
keywordHandler:addKeyword({'cipfried'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Yes? How can I help you?'})
keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'My name is Cipfried.'})
keywordHandler:addKeyword({'willie'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Willie is a farmer, just like his cousin Billy. His farm is located to the left of the temple. You can buy and sell food there.'})
keywordHandler:addKeyword({'billy'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'He is a farmer, just like his cousin Willie. He doesn\'t talk to everybody, though.'})
keywordHandler:addKeyword({'gold'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You can earn a fair amount of gold by fighting monsters and picking up the things they carry. Many citizens are buying some of that loot, simply ask around.'})
keywordHandler:addKeyword({'equipment'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'You can buy equipment from the merchants in this village once you earned some gold. Some monsters also carry equipment pieces with them.'})

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

Just had to add
doCreatureAddHealth(cid, 65)
insted of
doCreatureAddHealth(cid, - (health + 65)) <---- which was killing my character instantly as I said heal under 65 health..
 
Last edited by a moderator:
Back
Top