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

Why won't this NPC work?

Ecstacy

Mothafuckaaa
Joined
Dec 26, 2008
Messages
3,836
Reaction score
108
Location
The Netherlands
Hello,

I'm not good at making NPC's obviously, but could someone tell my why this NPC won't greet me/work ?

Token Exchanger.xml
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Token Exchanger" script="tokens.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="212" head="20" body="30" legs="40" feet="50" corpse="6054"/>
    <parameters>
      <parameter key="message_greet" value="Greetings |PLAYERNAME|. I exchange tokens for 'items'." />
    </parameters>
  </npc>

tokens.lua
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
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

-- CONFIG --
newitem = "Here you go, glad to be doing bussiness with you!"
noitems = "You don't have enough tokens to pay for that."

-- Yalahari Mask --

function YalahariMask(cid, message, keywords, parameters, node)
    if(not npcHandler:isFocused(cid)) then
        return false
		
    end 
if msgcontains(msg, 'yalahari mask') then
	if getPlayerStorageValue(cid, 11551) then
			if getPlayerItemCount(cid, 9020) >= 10 then
					if doPlayerRemoveItem(cid, 9020, 10) then
							selfSay(newitem, cid)
							doPlayerGiveItem(cid, 9778)
					else
							selfSay(noitems, cid)
					end
			else
					selfSay(noitems, cid)
			end
		end
	end
end

Thanks in advance,
unknown666
 
@unknown666
Cykotitan only help noobs that barely can speak english, try acting like one and he probably helps you!
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
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 YalahariMask(cid, message, keywords, parameters, node)
	if not npcHandler:isFocused(cid) then
		return false
	elseif getPlayerStorageValue(cid, 11551) < 1 then
		selfSay('You\'re not permitted to do this!', cid)
	elseif not doPlayerRemoveItem(cid, 9020, 10) then
		selfSay('You don\'t have enough tokens!', cid)
	else
		selfSay('Here you go, glad to be doing bussiness with you!', cid)
		doPlayerAddItem(cid, 9778, 1)
	end
end 

local node1 = keywordHandler:addKeyword({'mask'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to exchange 10 vampire lord tokens for a yalahari mask?'})
	node1:addChildKeyword({'yes'}, YalahariMask, {npcHandler = npcHandler, onlyFocus = true, reset = true})
	node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Maybe next time.', reset = true})
	
npcHandler:addModule(FocusModule:new())
 
Configurable:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic = {}
local cfg = {
	token = 9020,
	storage = 11551,
	items = {
		['mask'] = {10, 9778},
	}
}

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, cfg.storage) < 0 then
		npcHandler:setMessage("Welcome traveler, you may exchange your tokens here.")
		Topic[cid] = ''
	else
		npcHandler:say("Sorry, I can not talk to you.", cid)
		return false
	end
	return true
end

function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif Topic[cid] == '' then
		for k, v in pairs(cfg.items) do
			if msgcontains(msg, k) then
				Topic[cid] = k
				npcHandler:say('Do you want to exchange ' .. v[1] .. ' ' .. getItemInfo(cfg.token).plural .. ' for ' .. getItemInfo(v[2]).article .. ' ' .. getItemInfo(v[2]).name .. '?', cid)
				break
			end
		end
	else
		local i = cfg.items[Topic[cid]]
		if msgcontains(msg, 'yes') then
			if doPlayerRemoveItem(cid, cfg.token, i[1]) then
				doPlayerAddItem(cid, i[2], 1)
				npcHandler:say('Here you go, glad to be doing business with you!', cid)
			else
				npcHandler:say('You don\'t have enough tokens to pay for that.', cid)
			end
		else
			npcHandler:say('Maybe next time.', cid)
		end
		Topic[cid] = ''
	end
	return true
end

npcHandler:setMessage(MESSAGE_WALKAWAY, "Farewell, traveler!")
npcHandler:setMessage(MESSAGE_FAREWELL, "Farewell, traveler |PLAYERNAME|!")
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Back
Top