• 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 rozmowa dopiero po "hi"

Status
Not open for further replies.

Zombiexon

Member
Joined
Mar 12, 2011
Messages
220
Reaction score
7
Location
/home/var/
Otóż mam taki skrypt npc, lecz on działał nawet bez powiedzenia "hi"
w jaki sposób można by było zrobić aby on działał dopiero po hi?

PHP:
function msgcontains(txt, str)
    return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
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
 
npcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|. May I help you?")
 
function greetCallback(cid)
	-- Resetting talkState[talkUser]
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	talkState[talkUser] = 0
    return true
end
 
function creatureSayCallback (cid, type, msg)
 
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
	if msgcontains(msg, 'time') then
		selfSay('Now it\'s ' .. getWorldTime() .. '.')
	end

	if(msgcontains(msg, "parcel") or msgcontains(msg, "label")) then
		npcHandler:say("Do you want to buy a parcel for 15 gold coins?",cid)
		talkState[talkUser] = 1
	
		elseif(msgcontains(msg, "yes") and talkState[talkUser] == 1) then
			if doPlayerRemoveMoney(cid, 15) == TRUE then -- edit the amount of gold here
			doPlayerAddItem(cid,2595,1)
			doPlayerAddItem(cid,2599,1)
			npcHandler:say("Here you are. Don't forget to write the name and the address of the receiver on the label. The label has to be in the parcel before you put the parcel in a mailbox.",cid)
			talkState[talkUser] = 0
			else
			npcHandler:say("Oh, you have not enough gold to buy a parcel.", cid)
			talkState[talkUser] = 0
			end
			
			elseif(talkState[talkUser] == 1) then
			npcHandler:say("Not good enough, eh? What else can I do for you?", cid)
			talkState[talkUser] = 0
		
	elseif(msgcontains(msg, "letter") or msgcontains(msg, "letter")) then
		npcHandler:say("Do you want to buy a letter for 5 gold coins?",cid)
		talkState[talkUser] = 4
		
	elseif(msgcontains(msg, "yes") and talkState[talkUser] == 4) then
			if doPlayerRemoveMoney(cid, 5) == TRUE then -- edit the amount of gold here
			doPlayerAddItem(cid,2599,1)
			npcHandler:say("Here it is. Don't forget to write the name of the receiver in the first line and the address in the second one before you put the letter in a mailbox.",cid)
			talkState[talkUser] = 0
			else
			npcHandler:say("Oh, you have not enough gold to buy a letter.", cid)
			talkState[talkUser] = 0
			end
			
		elseif(talkState[talkUser] == 1) then
			npcHandler:say("Not good enough, eh? What else can I do for you?", cid)
			talkState[talkUser] = 0
			
		elseif(msgcontains(msg, "mail") or msgcontains(msg, "mail")) then
		npcHandler:say("Our mail system is unique! And so simple even males can use it. Do you want to know more about it?",cid)
		talkState[talkUser] = 3
		
		elseif((msgcontains(msg, "yes") and talkState[talkUser] == 3) ) or (msgcontains(msg, "no") and talkState[talkUser] == 3) then
			if msgcontains(msg, "yes") == yes  then 
			npcHandler:say("Is there anything else, I can do for you?", cid)
			talkState[talkUser] = 0
		    else
			npcHandler:say("The Mail System enables you to send and receive letters and parcels. You can buy them here if you want.", cid)
			talkState[talkUser] = 0
		    end
		  	
	elseif(talkState[talkUser] == 1) then
	npcHandler:say("Not good enough, eh? What else can I do for you?", cid)
	talkState[talkUser] = 0
	
	end
	
	
	return true
end
 
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Pokmiń nad greetCallback i sprawdź jak jest w innych skryptach npc.
 
Hmm, może inaczej jest to avesta 7.4 z troszeczkę innym systemem niż był na 7.4 a bardziej po 8+ przykładów owych nie ma;p


Edit:
W sumie wpadłem na pewien pomysł i chodzi wystarczyło po rozpoczęciu funkcji dopisać;
if(npcHandler.focus ~= cid) then
return false
end

Do zamknięcia.
 
Last edited:
Status
Not open for further replies.
Back
Top