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

NPC need repair. TFS 0.3.5

Moj mistrz

Monster Creator
Joined
Feb 1, 2008
Messages
932
Solutions
10
Reaction score
308
Location
Poland
Hello. Need help with NPC, can someone repair him ?

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

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


local exp = formula * formula2
local formula2 = getPlayerItemCount(cid, 10531)
local level = getPlayerLevel(cid)
local formula = (level * 30)


if msgcontains(msg, 'midnight shard') then
selfSay('Do you want change all of midnight shards for experience?')
talk_state = 1
elseif msgcontains(msg, 'yes') and talk_state == 1 then
selfSay('Are you really sure?')
talk_state = 2
elseif msgcontains(msg, 'yes') then
if doPlayerTakeItem(cid, formula2) == 0 then
selfSay('Thank you very much! Ill give you '..exp..' experience for returning it!')
doPlayerAddExp(cid, formula)
doSendMagicEffect(getPlayerPosition(cid), 14)
doSendAnimatedText(getPlayerPosition(cid), formula, TEXTCOLOR_WHITE)
talk_state = 3

elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 3) then
selfSay('Good bye. |PLAYERNAME|!')
talk_state = 0
end
end
-- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
return true
end

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

Thanks.
 
First error.
[07/12/2009 21:06:19] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/shardnpc65.lua
[07/12/2009 21:06:19] data/npc/scripts/shardnpc65.lua:26: unexpected symbol near 'then'
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}

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(not npcHandler:isFocused(cid)) then
		return false
	elseif Topic[cid] == 2 then
		if msgcontains(msg, "yes") then
			local c = getPlayerItemCount(cid, 10531)
			if 0 < c then
				local exp = getPlayerLevel(cid) * 30 * c
				doPlayerRemoveItem(cid, 10531, c)
				npcHandler:say("Thank you very much! I'll give you " .. exp .. " experience for returning it!", cid)
				doPlayerAddExp(cid, exp)
				doSendMagicEffect(getCreaturePosition(cid), 14)
				doSendAnimatedText(getCreaturePosition(cid), exp, TEXTCOLOR_WHITE)
			else
				npcHandler:say("You don't have any midnight shards.", cid)
			end
		else
			npcHandler:say("Maybe next time.", cid)
		end
		Topic[cid] = 0
	elseif Topic[cid] == 1 then
		if msgcontains(msg, "yes") then
			npcHandler:say("Are you really sure?", cid)
			Topic[cid] = 2
		else
			npcHandler:say("Then not.", cid)
			Topic[cid] = 0
		end
	elseif msgcontains(msg, "midnight") and msgcontains(msg, "shard") then
		npcHandler:say("Do you want change all of midnight shards for experience?", cid)
		Topic[cid] = 1
	end
	return TRUE
end

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