• 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 When player say HI, heal (SOLVED)

LucasFerraz

Systems Analyst
Joined
Jun 10, 2010
Messages
2,857
Reaction score
96
Location
Brazil
When player say hi
LUA:
		doRemoveCondition(cid, CONDITION_ENERGY)
		doRemoveCondition(cid, CONDITION_PHYSICAL)
		doRemoveCondition(cid, CONDITION_FIRE)
		doRemoveCondition(cid, CONDITION_POISON)
		npcHandler:say("Removed Condidions", cid)
		if getPlayerHealth(cid) <= 100 then
			doCreatureAddHealth(cid, 150)
			npcHandler:say("take healt", cid)
		end

Why do not work?
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic = {}
local cost = 0

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)

		doRemoveCondition(cid, CONDITION_ENERGY)
		doRemoveCondition(cid, CONDITION_PHYSICAL)
		doRemoveCondition(cid, CONDITION_FIRE)
		doRemoveCondition(cid, CONDITION_POISON)
		npcHandler:say("Removed Condidions", cid)
		if getPlayerHealth(cid) <= 100 then
			doCreatureAddHealth(cid, 150)
			npcHandler:say("take healt", cid)
		end
	if not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, "twist") and msgcontains(msg, "fate") then
		if getPlayerLevel(cid) < 31 then
			cost = 2000
		else
			cost = ((getPlayerLevel(cid) - 30) * 200) + 2000
		end
	
		if cost > 20000 then
			cost = 20000
		end
		selfSay('This is a special blessing I can bestow upon you once you have obtained at least one of the other blessings and which functions a bit differently. ...', cid)
		selfSay('It only works when you\'re killed by other adventurers, which means that at least fourty percent of the damage leading to your death was caused by others, not by monsters or the environment. ...', cid)
		selfSay('The {twist of fate} will not reduce the death penalty like the other blessings, but instead prevent you from losing your other blessings as well as the amulet of loss, should you wear one. It costs the same as the other blessings. ...', cid)
		selfSay('Would you like to receive that protection for a sacrifice of '.. cost ..' gold, child?', cid)
		Topic[cid] = 1
	elseif Topic[cid] == 1 then
		if msgcontains(msg, "no") then
			npcHandler:say("You are free to decline my offer.", cid)
			Topic[cid] = nil
		elseif msgcontains(msg, "yes") then
			if (getPlayerStorageValue(cid,88880) <=0) then
				if (getPlayerMoney(cid) >= cost) then
					if getPlayerBlessing(cid, 5) then
						doPlayerRemoveMoney(cid,cost)
						doPlayerAddPVPBlessing(cid)
						selfSay('So receive the protection of the twist of fate, pilgrim.', cid)
						Topic[cid] = 2
					else
						npcHandler:say("You don\'t have any of the other (blessings) nor an amulet of loss, so it wouldn\'t make sense to bestow this protection on you now. Remember that it can only protect you from the loss of those!", cid)
					end
				else
					npcHandler:say("You don\'t have enough money", cid)
				end
			else
				npcHandler:say("You already possess this blessing.", cid)
			end
		end
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
try to change
LUA:
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
to
LUA:
npcHandler:setCallback(CALLBACK_ONTHINK, thinkCallback)
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Good bye.')
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
If the problem is not an error in the console, make this:

Change:

LUA:
		npcHandler:say("Removed Condidions", cid)
		if getPlayerHealth(cid) <= 100 then
			doCreatureAddHealth(cid, 150)
			npcHandler:say("take healt", cid)
		end
to:
LUA:
                        npcHandler:say("Removed conditions and restored health!", cid)
			doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
 
lot of errors in console

- - - Updated - - -

Player must get health only if health <100
If the problem is not an error in the console, make this:

Change:

LUA:
		npcHandler:say("Removed Condidions", cid)
		if getPlayerHealth(cid) <= 100 then
			doCreatureAddHealth(cid, 150)
			npcHandler:say("take healt", cid)
		end
to:
LUA:
                        npcHandler:say("Removed conditions and restored health!", cid)
			doCreatureAddHealth(cid, getCreatureMaxHealth(cid))

- - - Updated - - -

SOLVED

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

local Topic = {}
local cost = 0

function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)
		if msgcontains(msg, "heal") or msgcontains(msg, "healing") then
			if (getCreatureCondition(cid, CONDITION_ENERGY) or getCreatureCondition(cid, CONDITION_PHYSICAL) or getCreatureCondition(cid, CONDITION_FIRE) or getCreatureCondition(cid, CONDITION_POISON)) then
				doRemoveCondition(cid, CONDITION_ENERGY)
				doRemoveCondition(cid, CONDITION_PHYSICAL)
				doRemoveCondition(cid, CONDITION_FIRE)
				doRemoveCondition(cid, CONDITION_POISON)
				local pos = getCreaturePosition(cid)
				doSendMagicEffect(pos, CONST_ME_MAGIC_BLUE)
				if (getCreatureHealth(cid) <= 100) then
					doCreatureAddHealth(cid, 150)
				end
			else
				npcHandler:say("You aren\'t looking that bad. Sorry, I can\'t help you. But if you are looking for additional protection you should go on the {pilgrimage} of ashes or get the protection of the {twist of fate} here.", cid)
			end
		end
		if msgcontains(msg, "hi") and (getCreatureHealth(cid) <= 100) then
			doCreatureAddHealth(cid, 150)
			local pos = getCreaturePosition(cid)
			doSendMagicEffect(pos, CONST_ME_MAGIC_BLUE)
		end
npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
		
function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif msgcontains(msg, "twist") and msgcontains(msg, "fate") then
		if getPlayerLevel(cid) < 31 then
			cost = 2000
		else
			cost = ((getPlayerLevel(cid) - 30) * 200) + 2000
		end
	
		if cost > 20000 then
			cost = 20000
		end
		selfSay('This is a special blessing I can bestow upon you once you have obtained at least one of the other blessings and which functions a bit differently. ...', cid)
		selfSay('It only works when you\'re killed by other adventurers, which means that at least fourty percent of the damage leading to your death was caused by others, not by monsters or the environment. ...', cid)
		selfSay('The {twist of fate} will not reduce the death penalty like the other blessings, but instead prevent you from losing your other blessings as well as the amulet of loss, should you wear one. It costs the same as the other blessings. ...', cid)
		selfSay('Would you like to receive that protection for a sacrifice of '.. cost ..' gold, child?', cid)
		Topic[cid] = 1
	elseif Topic[cid] == 1 then
		if msgcontains(msg, "no") then
			npcHandler:say("You are free to decline my offer.", cid)
			Topic[cid] = nil
		elseif msgcontains(msg, "yes") then
			if (getPlayerStorageValue(cid,88880) <=0) then
				if (getPlayerMoney(cid) >= cost) then
					if getPlayerBlessing(cid, 5) then
						doPlayerRemoveMoney(cid,cost)
						doPlayerAddPVPBlessing(cid)
						selfSay('So receive the protection of the twist of fate, pilgrim.', cid)
						Topic[cid] = 2
					else
						npcHandler:say("You don\'t have any of the other (blessings) nor an amulet of loss, so it wouldn\'t make sense to bestow this protection on you now. Remember that it can only protect you from the loss of those!", cid)
					end
				else
					npcHandler:say("You don\'t have enough money", cid)
				end
			else
				npcHandler:say("You already possess this blessing.", cid)
			end
		end
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top