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

Help with an NPC Script? :)

Skylinx

Game Programmer
Joined
Nov 26, 2008
Messages
399
Reaction score
14
Location
TORONTO, CANADA
Heres the script.
Basically, just trades 1 ANNICOIN (Christmas token) for demon armor.
Code:
function msgcontains(txt, str)
	return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

function onCreatureSay(cid, type, msg)
	msg = string.lower(msg)

	if (msgcontains(msg, 'hi') and focus == 0) and getDistanceToCreature(cid) < 4 then
		selfSay('Hello ' .. getCreatureName(cid) .. '! say magic sword or the anni reward you want!')
		focus = cid
		talk_start = os.clock()
	elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
		selfSay('Sorry, ' .. getCreatureName(cid) .. '! I talk with you in one minute.')
	-- Demon armor
	elseif msgcontains(msg, 'demon armor') then
		selfSay('Do you want to trade one Annilator Token for demon armor?')
		talk_state = 1
		talk_start = os.clock()
	elseif talk_state == 1 and msgcontains(msg, 'yes') then
		if getPlayerItemCount(cid,6527) >= 1 then
			if doPlayerRemoveItem(cid,6527,1) then
				selfSay('There you go, No refunds.')
				doPlayerAddItem(cid,2494,1)
			end
		else
			selfSay('I\'m afraid you don\'t have an Anni-Token')
		end
	-- Sov
	elseif msgcontains(msg, 'magic sword') then
		selfSay('Do you want to trade one Annilator Token for magic sword?')
		talk_state = 1
		talk_start = os.clock()
	elseif talk_state == 1 and msgcontains(msg, 'yes') then
		if getPlayerItemCount(cid,6527) >= 1 then
			if doPlayerRemoveItem(cid,6527,1) then
				selfSay('There you go, No refunds.')
				doPlayerAddItem(cid,2400,1)
			end
		else
			selfSay('I\'m afraid you don\'t have an Anni-Token')
		end
	-- SCA
	elseif msgcontains(msg, 'stone cutter axe') then
		selfSay('Do you want to trade one Annilator Token, for stone cutter axe?')
		talk_state = 1
		talk_start = os.clock()
	elseif talk_state == 1 and msgcontains(msg, 'yes') then
		if getPlayerItemCount(cid,6527) >= 1 then
			if doPlayerRemoveItem(cid,6527,1) then
				selfSay('There you go, No refunds.')
				doPlayerAddItem(cid,2431,1)
			end
		else
			selfSay('I\'m afraid you don\'t have an Anni-Token')
		end
	end
end

Heres the error I get.
Code:
[22/02/2009 15:36:00] data/npc/scripts/AnniToken.lua:39: attempt to compare nil with number
[22/02/2009 15:36:00] stack traceback:
[22/02/2009 15:36:00] 	data/npc/scripts/AnniToken.lua:39: in function <data/npc/scripts/AnniToken.lua:36>
[/B]
Im using [B][U]The Forgotten Server, version 0.3 (Beta 3)[/U][/B]
 
Last edited:
Thanks for that..
Now I get
Code:
[22/02/2009 15:22:04] [Warning - NpcScript::NpcScript] Can not load script: data/npc/scripts/AnniToken.lua
[22/02/2009 15:22:04] data/npc/scripts/AnniToken.lua:64: ')' expected near 'm'
 
Change:
Code:
selfSay('I'm afraid you don't have[...]

to
Code:
selfSay('I\'m afraid you don't have[...]

( I'm -> I\'m )
 
Yes thanks! xD
BUT..
Now I get .. :(
Code:
[22/02/2009 15:29:24] [Warning - NpcScript::NpcScript] Can not load script: data/npc/scripts/AnniToken.lua
[22/02/2009 15:29:24] data/npc/scripts/AnniToken.lua:97: 'end' expected (to close 'if' at line 41) near '<eof>'
 
Code:
local focus = 0
local talk_start = 0
local target = 0
local following = false
local attacking = false

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
	if focus == cid then
		selfSay('Good bye then.')
		focus = 0
		talk_start = 0
	end
end


function onCreatureTurn(callback)

end


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

function onCreatureSay(cid, type, msg)
	msg = string.lower(msg)

	if (msgcontains(msg, 'hi') and focus == 0) and getDistanceToCreature(cid) < 4 then
		selfSay('Hello ' .. getCreatureName(cid) .. '! say magic sword or the anni reward you want!')
		focus = cid
		talk_start = os.clock()
	elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
		selfSay('Sorry, ' .. getCreatureName(cid) .. '! I talk with you in one minute.')
	-- Demon armor
	elseif msgcontains(msg, 'demon armor') then
		selfSay('Do you want to trade one Annilator Token for demon armor?')
		talk_state = 1
		talk_start = os.clock()
	elseif talk_state == 1 and msgcontains(msg, 'yes') then
		if getPlayerItemCount(cid,6527) >= 1 then
			if doPlayerRemoveItem(cid,6527,1) then
				selfSay('There you go, No refunds.')
				doPlayerAddItem(cid,2494,1)
			end
		else
			selfSay('I\'m afraid you don\'t have an Anni-Token')
		end
	-- Sov
	elseif msgcontains(msg, 'magic sword') then
		selfSay('Do you want to trade one Annilator Token for magic sword?')
		talk_state = 1
		talk_start = os.clock()
	elseif talk_state == 1 and msgcontains(msg, 'yes') then
		if getPlayerItemCount(cid,6527) >= 1 then
			if doPlayerRemoveItem(cid,6527,1) then
				selfSay('There you go, No refunds.')
				doPlayerAddItem(cid,2400,1)
			end
		else
			selfSay('I\'m afraid you don\'t have an Anni-Token')
		end
	-- SCA
	elseif msgcontains(msg, 'stone cutter axe') then
		selfSay('Do you want to trade one Annilator Token, for stone cutter axe?')
		talk_state = 1
		talk_start = os.clock()
	elseif talk_state == 1 and msgcontains(msg, 'yes') then
		if getPlayerItemCount(cid,6527) >= 1 then
			if doPlayerRemoveItem(cid,6527,1) then
				selfSay('There you go, No refunds.')
				doPlayerAddItem(cid,2431,1)
			end
		else
			selfSay('I\'m afraid you don\'t have an Anni-Token')
		end
	end
end
 
Yay thanks!

But when I try to say HI to him,
He doesn't respond, and I get a console error.

Code:
[22/02/2009 15:36:00] data/npc/scripts/AnniToken.lua:39: attempt to compare nil with number
[22/02/2009 15:36:00] stack traceback:
[22/02/2009 15:36:00] 	data/npc/scripts/AnniToken.lua:39: in function <data/npc/scripts/AnniToken.lua:36>
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local item = {}

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 talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

	if msgcontains(msg, 'demon armor') then
		selfSay('Do you want to trade one Annilator Token for demon armor?', cid)
		talkState[talkUser] = 1
		item[talkUser] = 2494
	elseif msgcontains(msg, 'magic sword') then
		selfSay('Do you want to trade one Annilator Token for magic sword?', cid)
		talkState[talkUser] = 1
		item[talkUser] = 2400
	elseif msgcontains(msg, 'stonecutter axe') then
		selfSay('Do you want to trade one Annilator Token, for stone cutter axe?', cid)
		talkState[talkUser] = 1
		item[talkUser] = 2431
	elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
		if doPlayerRemoveItem(cid, 6527, 1) == TRUE then
			selfSay('Here is your '..getItemName(item[talkUser])..', no refunds.', cid)
			doPlayerAddItem(cid, item[talkUser], 1)
			talkState[talkUser] = 0
		else
			selfSay('You do not have the anni coin.', cid)
			talkState[talkUser] = 0
		end
	elseif (msgcontains(msg, 'no') or msgcontains(msg, 'gtfo')) and talkState[talkUser] == 1 then
		selfSay('Then not.', cid)
		talkState[talkUser] = 0
	end

	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Anyone can edit one action to me? I like to much "configs" see it:
-if player click win one storage value, {use this id to pass in some doors}
-if player click, can go to X position or Y position
-if player click lose X damage by a item {DAMAGE IN % OF LIFE}
-If player click say one msg
-need level/m level FOR MAGES CLICK exemple {min, level 100, ml 70}
-need level/skills to KNIGHT CLICK exemple {min, level 100, skills 90}
-player can click only one X, if click again say: you already used this!~


Can anyone help me? :p
 
Wtf, it randomlly stopped working!!
Code:
[22/02/2009 19:13:36] Lua Script Error: [Npc interface] 
[22/02/2009 19:13:36] data/npc/scripts/AnniToken.lua:onCreatureSay

[22/02/2009 19:13:36] data/lib/function.lua:311: attempt to index a number value
[22/02/2009 19:13:36] stack traceback:
[22/02/2009 19:13:36] 	data/lib/function.lua:311: in function 'getItemName'
[22/02/2009 19:13:36] 	data/npc/scripts/AnniToken.lua:33: in function 'callback'
[22/02/2009 19:13:36] 	data/npc/lib/npcsystem/npchandler.lua:374: in function 'onCreatureSay'
[22/02/2009 19:13:36] 	data/npc/scripts/AnniToken.lua:9: in function <data/npc/scripts/AnniToken.lua:9>
 
Back
Top