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

NPC problem

tompan

Member
Joined
Dec 13, 2008
Messages
646
Reaction score
24
Location
Sweden
so i want my npc to respond difrently depending if i have storage value TRUE or FALSE.


The text in red is where i want it to be the focus if i have that storage or not.
here is my npc (not edited for it)
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
npcHandler:setFocusGreetKeywords("tja") -- you can add multiple if you wish, same for below
npcHandler:setFocusFarewellKeywords("ses")
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)
	if(npcHandler.focus ~= cid) then
		return false
	end
	
		if msgcontains(msg, 'heal') then
		if getPlayerStorageValue(cid, 99998) == -1 then
		if hasCondition(cid, CONDITION_FIRE) == TRUE then
			npcHandler:say('You are burning,' .. getCreatureName(cid) .. '. I will help you.')
			doRemoveCondition(cid, CONDITION_FIRE)
			doSendMagicEffect(getCreaturePosition(cid), 14)
		elseif hasCondition(cid, CONDITION_POISON) == TRUE then
			npcHandler:say('You are poisoned,' .. getCreatureName(cid) .. '. I will help you.')
			doRemoveCondition(cid, CONDITION_POISON)
			doSendMagicEffect(getCreaturePosition(cid), 13)
		elseif getCreatureHealth(cid) < 65 then
			npcHandler:say('You are looking really bad, ' .. getCreatureName(cid) .. '. Let me heal your wounds.')
			doCreatureAddHealth(cid, 65 - getCreatureHealth(cid))
			doSendMagicEffect(getCreaturePosition(cid), 12)
		else
			npcHandler:say('You aren\'t looking that bad,. Sorry, can\' help you.')
		end
		else
		npcHandler:say('I won\'t waste my healing powers on you, spawn of evil!')
		end
		
		elseif msgcontains(msg, 'diary') then
			if getPlayerStorageValue(cid, 99997) == -1 then
				if getPlayerItemCount(cid,1955) >= 1 then
				
					if  getPlayerStorageValue(cid, 9026) == 1 then
						npcHandler:say('Do you want me to inspect a diary?')
						talk_state = 7
					else
					npcHandler:say('You do not have this item.')
					end
				else
				npcHandler:say('You do not have this item.')
				end
			else
			npcHandler:say('Thank you again for handing me that diary.')
			end
		

		[COLOR="#FF0000"]elseif msgcontains(msg, 'crime') then
		greetCallback(cid)
		if getPlayerStorageValue(cid, 99998) == TRUE then
			npcHandler:say('WHAT? You have to be that trespasser my brothers told me about! Entering the restricted area is a horrible crime!')
			talk_state = 2
		else
		npcHandler:say('Welcome, ' .. getCreatureName(cid) .. '! Feel free to tell me what has brought you here.')
		end[/COLOR]


		elseif msgcontains(msg, 'pay') and talk_state == 2 and getPlayerStorageValue(cid, 99998) == 1 then
		if getPlayerLevel(cid) < 21 then
		npcHandler:say ('The only way to redeem such an offense is the sacrifice of 500 gold pieces! Are you willing to pay that sum?')
		talk_state = 3
		
		elseif getPlayerLevel(cid) < 41 then
		npcHandler:say ('The only way to redeem such an offense is the sacrifice of 1.000 gold pieces! Are you willing to pay that sum?')
		talk_state = 4		
		
		elseif getPlayerLevel(cid) < 60 then
		npcHandler:say ('The only way to redeem such an offense is the sacrifice of 5.000 gold pieces! Are you willing to pay that sum?')
		talk_state = 5		
		
		elseif getPlayerLevel(cid) > 59 then
		npcHandler:say ('The only way to redeem such an offense is the sacrifice of 10.000 gold pieces! Are you willing to pay that sum?')
		talk_state = 6
		end

			elseif msgcontains(msg, 'yes') and talk_state == 3 then 
			if getPlayerMoney(cid) >= 500 then
			selfSay('So receive your absolution! And never do such a thing again!')
			doSendMagicEffect(getCreaturePosition(cid), 13)
			setPlayerStorageValue(cid, 99998, -1)
			doPlayerRemoveMoney(cid, 500)
			talk_state = 0
			else 
			npcHandler:say('Begone! You do not have enough money!')
			talk_state = 0
			end		
			
			elseif msgcontains(msg, 'yes') and talk_state == 4 then 
			if getPlayerMoney(cid) >= 1000 then
			selfSay('So receive your absolution! And never do such a thing again!')
			doSendMagicEffect(getCreaturePosition(cid), 13)
			setPlayerStorageValue(cid, 99998, -1)
			doPlayerRemoveMoney(cid, 1000)
			talk_state = 0

			else 
			npcHandler:say('Begone! You do not have enough money!')
			talk_state = 0
			end		
			
			elseif msgcontains(msg, 'yes') and talk_state == 5 then 
			if getPlayerMoney(cid) >= 5000 then
			selfSay('So receive your absolution! And never do such a thing again!')
			doSendMagicEffect(getCreaturePosition(cid), 13)
			setPlayerStorageValue(cid, 99998, -1)
			doPlayerRemoveMoney(cid, 5000)
			talk_state = 0
			else 
			npcHandler:say('Begone! You do not have enough money!')
			talk_state = 0
			end			
			
			elseif msgcontains(msg, 'yes') and talk_state == 6 then 
			if getPlayerMoney(cid) >= 10000 then
					selfSay('So receive your absolution! And never do such a thing again!')
					doSendMagicEffect(getCreaturePosition(cid), 13)
					setPlayerStorageValue(cid, 99998, -1)
					doPlayerRemoveMoney(cid, 10000)
					talk_state = 0
			
			else 
			npcHandler:say('Begone! You do not have enough money!')
			talk_state = 0
			end	
			
			elseif msgcontains(msg, 'yes') and talk_state == 7 then 
			if getPlayerItemCount(cid,1955) >= 1 then
					selfSay('By the gods! This is brother Fugio\'s handwriting and what I read is horrible indeed! You have done our order a great favour by giving this diary to me! Take this blessed Ankh. May it protect you in even your darkest hours.')
					setPlayerStorageValue(cid, 99997, 1)
					doPlayerTakeItem(cid,1955,1)
					doPlayerAddItem(cid,2327,1)
					talk_state = 0
			
			else 
			npcHandler:say('Uhm, as you wish.')
			talk_state = 0
			end	
	end

	return TRUE	
	end

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


here is my try to make this work.
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
npcHandler:setFocusGreetKeywords("hi")
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 greetCallback(cid)
	if getPlayerStorageValue(cid, 99998) == 1 then
		npcHandler:say("I SHOULD SAY THIS IF I HAVE STORAGE 99998 BUT I DONT :'('")
	else
 
		npcHandler:say("I DONT SAY THIS EITHER!!")
	end
	return true
end

function creatureSayCallback(cid, type, msg)
	if(npcHandler.focus ~= cid) then
		return false
	end
	
	
		if msgcontains(msg, 'heal') then
		if getPlayerStorageValue(cid, 99998) == -1 then
		if hasCondition(cid, CONDITION_FIRE) == TRUE then
			npcHandler:say('You are burning,' .. getCreatureName(cid) .. '. I will help you.')
			doRemoveCondition(cid, CONDITION_FIRE)
			doSendMagicEffect(getCreaturePosition(cid), 14)
		elseif hasCondition(cid, CONDITION_POISON) == TRUE then
			npcHandler:say('You are poisoned,' .. getCreatureName(cid) .. '. I will help you.')
			doRemoveCondition(cid, CONDITION_POISON)
			doSendMagicEffect(getCreaturePosition(cid), 13)
		elseif getCreatureHealth(cid) < 65 then
			npcHandler:say('You are looking really bad, ' .. getCreatureName(cid) .. '. Let me heal your wounds.')
			doCreatureAddHealth(cid, 65 - getCreatureHealth(cid))
			doSendMagicEffect(getCreaturePosition(cid), 12)
		else
			npcHandler:say('You aren\'t looking that bad,. Sorry, can\' help you.')
		end
		else
		npcHandler:say('I won\'t waste my healing powers on you, spawn of evil!')
		end
		
		elseif msgcontains(msg, 'diary') then
			if getPlayerStorageValue(cid, 99997) == -1 then
				if getPlayerItemCount(cid,1955) >= 1 then
				
					if  getPlayerStorageValue(cid, 9026) == 1 then
						npcHandler:say('Do you want me to inspect a diary?')
						talk_state = 7
					else
					npcHandler:say('You do not have this item.')
					end
				else
				npcHandler:say('You do not have this item.')
				end
			else
			npcHandler:say('Thank you again for handing me that diary.')
			end
		

		[COLOR="#FF0000"]elseif msgcontains(msg, 'hi') then
		greetCallback(cid)
		if getPlayerStorageValue(cid, 99998) == TRUE then
			npcHandler:say('WHAT? You have to be that trespasser my brothers told me about! Entering the restricted area is a horrible crime!')
			talk_state = 2
		else[/COLOR]
		npcHandler:say('Welcome, ' .. getCreatureName(cid) .. '! Feel free to tell me what has brought you here.')
		end


		elseif msgcontains(msg, 'crime') and talk_state == 2 and getPlayerStorageValue(cid, 99998) == 1 then
		if getPlayerLevel(cid) < 21 then
		npcHandler:say ('The only way to redeem such an offense is the sacrifice of 500 gold pieces! Are you willing to pay that sum?')
		talk_state = 3
		
		elseif getPlayerLevel(cid) < 41 then
		npcHandler:say ('The only way to redeem such an offense is the sacrifice of 1.000 gold pieces! Are you willing to pay that sum?')
		talk_state = 4		
		
		elseif getPlayerLevel(cid) < 60 then
		npcHandler:say ('The only way to redeem such an offense is the sacrifice of 5.000 gold pieces! Are you willing to pay that sum?')
		talk_state = 5		
		
		elseif getPlayerLevel(cid) > 59 then
		npcHandler:say ('The only way to redeem such an offense is the sacrifice of 10.000 gold pieces! Are you willing to pay that sum?')
		talk_state = 6
		end

			elseif msgcontains(msg, 'yes') and talk_state == 3 then 
			if getPlayerMoney(cid) >= 500 then
			selfSay('So receive your absolution! And never do such a thing again!')
			doSendMagicEffect(getCreaturePosition(cid), 13)
			setPlayerStorageValue(cid, 99998, -1)
			doPlayerRemoveMoney(cid, 500)
			talk_state = 0
			else 
			npcHandler:say('Begone! You do not have enough money!')
			talk_state = 0
			end		
			
			elseif msgcontains(msg, 'yes') and talk_state == 4 then 
			if getPlayerMoney(cid) >= 1000 then
			selfSay('So receive your absolution! And never do such a thing again!')
			doSendMagicEffect(getCreaturePosition(cid), 13)
			setPlayerStorageValue(cid, 99998, -1)
			doPlayerRemoveMoney(cid, 1000)
			talk_state = 0

			else 
			npcHandler:say('Begone! You do not have enough money!')
			talk_state = 0
			end		
			
			elseif msgcontains(msg, 'yes') and talk_state == 5 then 
			if getPlayerMoney(cid) >= 5000 then
			selfSay('So receive your absolution! And never do such a thing again!')
			doSendMagicEffect(getCreaturePosition(cid), 13)
			setPlayerStorageValue(cid, 99998, -1)
			doPlayerRemoveMoney(cid, 5000)
			talk_state = 0
			else 
			npcHandler:say('Begone! You do not have enough money!')
			talk_state = 0
			end			
			
			elseif msgcontains(msg, 'yes') and talk_state == 6 then 
			if getPlayerMoney(cid) >= 10000 then
					selfSay('So receive your absolution! And never do such a thing again!')
					doSendMagicEffect(getCreaturePosition(cid), 13)
					setPlayerStorageValue(cid, 99998, -1)
					doPlayerRemoveMoney(cid, 10000)
					talk_state = 0
			
			else 
			npcHandler:say('Begone! You do not have enough money!')
			talk_state = 0
			end	
			
			elseif msgcontains(msg, 'yes') and talk_state == 7 then 
			if getPlayerItemCount(cid,1955) >= 1 then
					selfSay('By the gods! This is brother Fugio\'s handwriting and what I read is horrible indeed! You have done our order a great favour by giving this diary to me! Take this blessed Ankh. May it protect you in even your darkest hours.')
					setPlayerStorageValue(cid, 99997, 1)
					doPlayerTakeItem(cid,1955,1)
					doPlayerAddItem(cid,2327,1)
					talk_state = 0
			
			else 
			npcHandler:say('Uhm, as you wish.')
			talk_state = 0
			end	

	end

	return TRUE	
	end
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


Thank you!
 
Last edited:
Back
Top