• 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] NPC.

Allu

Member
Joined
Sep 19, 2008
Messages
30
Reaction score
0
Location
Mexico
Hello there.
I am currently looking for help to create one NPC,
this is very important to fullfill my server and no mather how I try, it wont work.

NPC:
This NPC will sell you dome items if you give him an item,
lets say the Vampire Lord Token as example.
He will only accept the token, if you want to buy one of his items.
So the token, not money.
 
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 creatureSayCallback(cid, type, msg)

if(npcHandler.focus ~= cid) then
	return false
end

		playertokens = getPlayerItemCount(cid,9020)

---- example of keyword->respond

		if msgcontains(msg, 'offer') then
			selfSay('I can offer you a plate armor and plate legs for vampire lord tokens.')
		elseif msgcontains(msg, 'tokens') then
			selfSay('Vampire lord tokens are very valuable. Many treasure hunters looks for them.')

---- first item in offer

		elseif msgcontains(msg, 'plate armor') then
				if getPlayerItemCount(cid,9020) >= 5 then
                npcHandler:say('Did you bring me 5 vampire lord tokens to exchange for plate armor?', cid)
					talk_state = 1
				else
                npcHandler:say('I need 5 vampire lord tokens to exchange them to plate armor.', cid)
					talk_state = 0
				end

		elseif msgcontains(msg, 'yes') and talk_state == 1 then
			talk_state = 0
			if getPlayerItemCount(cid,9020) >= 5 then
					if doPlayerTakeItem(cid,9020,5) == 0 then
						selfSay('Here you are.')
						doPlayerAddItem(cid,2463,1)
					end
			else
                npcHandler:say('You haven\'t enough vampire lord tokens!', cid)
			end

---- /first item in offer

---- second item in offer

		elseif msgcontains(msg, 'plate legs') then
				if getPlayerItemCount(cid,9020) >= 5 then
                npcHandler:say('Did you bring me 5 vampire lord tokens to exchange for plate legs?', cid)
					talk_state = 2
				else
                npcHandler:say('I need 5 vampire lord tokens to exchange them to plate legs.', cid)
					talk_state = 0
				end

		elseif msgcontains(msg, 'yes') and talk_state == 2 then
			talk_state = 0
			if getPlayerItemCount(cid,9020) >= 5 then
					if doPlayerTakeItem(cid,9020,5) == 0 then
						selfSay('Here you are.')
						doPlayerAddItem(cid,2647,1)
					end
			else
                npcHandler:say('You haven\'t enough vampire lord tokens!', cid)
			end

---- /second item in offer

---- what happens if player say "no", if you are going to add more items, remember to change "talk_state <= 2"

		elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 2) then
			selfSay('Then not.')
			talk_state = 0
		end
	return true
end

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

Here is the npc HALF made to 8.31 (if you change npcHandler:say lines to the old npcsystem, the NPC will work on 8.1). Now I have to modify
Code:
		elseif msgcontains(msg, 'plate armor') then
to new NPC system but I don't know how >.>

So that NPC which I've made WON'T respond. I don't know how to use keyword in lua in the newest NPCsystem so now you got to wait for someone better :D
 
Last edited:
Code:
			if getPlayerItemCount(cid,9020) >= 5 then
					if doPlayerTakeItem(cid,9020,1) == 0 then

Why checking if he has 5 tokens and then removing 1?

Code:
    if doPlayerTakeItem(cid, 9020, 5) == TRUE then
        --additem
    else
        --selfsay
    end
 
Back
Top Bottom