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

{Request} Script update

Kavalor

(Real)Creator of ChaosOT
Joined
Dec 13, 2007
Messages
260
Reaction score
52
Location
Washington State, USA
This npc is not working correctly

I have a lot of npc's who run off code like this, they are not working with the latest tfs because they do not answer back to the keyword in the lua file. they answer when you say hi correctly though.

Code:
<?xml version="1.0"?>
<npc name="Goa Commander Sleek" script="data/npc/scripts/Goa Commander Sleek.lua" walkinterval="2000" floorchange="0" access="5" level="9999999" maglevel="1">
  <health now="150" max="150" />
	<look type="131" head="114" body="114" legs="95" feet="58" addons="2"/>
  <parameters>
   <parameter key="message_greet" value="Deep in gridwall desert cave is an old wizard. Lord Abbadon is a busy man and cannot pay him a visit, however this erran falls on lesser heros. It needs done at once. Travel there and gain the fireswarm spell document. Bring it back to me."/>
    
  </parameters>
</npc>

and .lua

Code:
-- start configuration
local keyword = 'document' --what must the player say to get involved into the conversation
local reqItemCount = 1 -- how many items the player needs
local reqItemID = 1952 -- what is the item ID of the item needed
local experience = 10000 -- how much experience will the player get
local givenItemCount = 0 -- how many items will the player get (the count of givenItemID)
local givenItemID = 0 -- which item will the player get
local storageValue = 1337 -- must be a UNIQUE storage value!!!
-- end configuration

if reqItemCount == 1 then
	subfix = ''
else
	subfix = 's'
end
                    
if givenItemCount == 1 then
	subfix2 = ''
else
	subfix2 = 's'
end

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

-- OTServ event handling functions start
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
-- OTServ event handling functions end

function creatureSayCallback(cid, type, msg)
	if(npcHandler.focus ~= cid) then
		return false
	end

	if msgcontains(msg, keyword) then
		if getPlayerItemCount(cid,reqItemID) >= reqItemCount then
			selfSay('Did you bring me '..reqItemCount..' '..getItemName(reqItemID)..subfix..'?')
			talkState = 1
		else
			selfSay('Come back when you have '..reqItemCount..' '..getItemName(reqItemID)..subfix..'.')
		end
	elseif msgcontains(msg, 'yes') and talkState == 1 then
		if getPlayerItemCount(cid,reqItemID) >= reqItemCount then
			if getPlayerStorageValue(cid,storageValue) ~= 1 then
				if doPlayerTakeItem(cid,reqItemID,reqItemCount) == 0 then
					doPlayerAddExp(cid,experience)
					
					
					
					selfSay('Here you go, '..experience..' experience points and some nice new addons lesser hero!')

				doPlayerAddOutfit(cid, 150, 2)
						doPlayerAddOutfit(cid, 134, 1)
						doPlayerAddOutfit(cid, 142, 1)
						doPlayerAddOutfit(cid, 134, 2)
						doPlayerAddOutfit(cid, 142, 2)
						doPlayerAddOutfit(cid, 145, 2)
						doPlayerAddOutfit(cid, 149, 2)	
					
					doSendMagicEffect(getPlayerPosition(cid),11)
				end
			else
				selfSay('Sorry, but you already brought be the items I requested.')
			end
		else
			selfSay('Sorry, you do not have the items.')
		end
		talkState = 0
	elseif msgcontains(msg, 'no') and talkState == 1 then
		selfSay('Ok than.')
		talkState = 0
	end
	return true
end

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



once again when you say hi they answer correctly in the npc window. when you say document they say nothing. :/
 
Code:
-- start configuration
local reqItemCount = 1 -- how many items the player needs
local reqItemID = 1952 -- what is the item ID of the item needed
local experience = 10000 -- how much experience will the player get
local givenItemCount = 0 -- how many items will the player get (the count of givenItemID)
local givenItemID = 0 -- which item will the player get
local storageValue = 1337 -- must be a UNIQUE storage value!!!
-- end configuration

if reqItemCount == 1 then
	subfix = ''
else
	subfix = 's'
end
                    
if givenItemCount == 1 then
	subfix2 = ''
else
	subfix2 = 's'
end

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

-- OTServ event handling functions start
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
-- OTServ event handling functions end

function creatureSayCallback(cid, type, msg)
	if(npcHandler.focus ~= cid) then
		return false
	end

	if msgcontains(msg, document) then
		if getPlayerItemCount(cid,reqItemID) >= reqItemCount then
			selfSay('Did you bring me '..reqItemCount..' '..getItemName(reqItemID)..subfix..'?')
			talkState = 1
		else
			selfSay('Come back when you have '..reqItemCount..' '..getItemName(reqItemID)..subfix..'.')
		end
	elseif msgcontains(msg, 'yes') and talkState == 1 then
		if getPlayerItemCount(cid,reqItemID) >= reqItemCount then
			if getPlayerStorageValue(cid,storageValue) ~= 1 then
				if doPlayerTakeItem(cid,reqItemID,reqItemCount) == 0 then
					doPlayerAddExp(cid,experience)
					
					
					
					selfSay('Here you go, '..experience..' experience points and some nice new addons lesser hero!')

				doPlayerAddOutfit(cid, 150, 2)
						doPlayerAddOutfit(cid, 134, 1)
						doPlayerAddOutfit(cid, 142, 1)
						doPlayerAddOutfit(cid, 134, 2)
						doPlayerAddOutfit(cid, 142, 2)
						doPlayerAddOutfit(cid, 145, 2)
						doPlayerAddOutfit(cid, 149, 2)	
					
					doSendMagicEffect(getPlayerPosition(cid),11)
				end
			else
				selfSay('Sorry, but you already brought be the items I requested.')
			end
		else
			selfSay('Sorry, you do not have the items.')
		end
		talkState = 0
	elseif msgcontains(msg, 'no') and talkState == 1 then
		selfSay('Ok than.')
		talkState = 0
	end
	return true
end

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