• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[NPC] Need Remake My NPC (he don't work)

merfus

Member
Joined
Dec 27, 2011
Messages
214
Reaction score
5
Location
Poland
What don't work?:
When i said change its good, when i buy armor ring #1 its good too
but when i say armor ring #2 nothing happens.
It should remove me 2 Items 2168 and 1 item 2207 and give me item id 2208
But NPC dont said to me nothing, can anyone help me?

Here is script:

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

	if(msgcontains(msg, 'change')) then
		selfSay('What Armor Ring You want? Type Armor Ring #Number', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'armor ring #1') and talkState[talkUser] == 1) then
		if(getPlayerItemCount(cid, 2168) >= 1) then
			if(doPlayerRemoveMoney(cid, 1000000)) then
				local item = getPlayerItemById(cid, true, 2168)
				doTransformItem(item.uid, 2207)
				selfSay('Here you are.', cid)
			else
				selfSay('Sorry, you don\'t have enough gold.', cid)
		end
				talkState[talkUser] = 0
	elseif(msgcontains(msg, 'armor ring #2') and talkState[talkUser] == 1) then
		if(getPlayerItemCount(cid, 2168) >= 2) and (getPlayerItemCount(cid, 2207) >= 1) then
			if(doPlayerRemoveMoney(cid, 1000000)) then
				local item = getPlayerItemById(cid, true, 2168)
				local item = getPlayerItemById(cid, true, 2207)
				doTransformItem(item.uid, 2208)
				selfSay('Here you are.', cid)
			else
				selfSay('Sorry, you don\'t have enough gold.', cid)
			end
		else
			selfSay('Sorry, you don\'t have the item.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	end

	return true
end
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Change
LUA:
local item = getPlayerItemById(cid, true, 2168)
local item = getPlayerItemById(cid, true, 2207)
doTransformItem(item.uid, 2208)
to
LUA:
doPlayerRemoveItem(cid, 2168, 2)
local item = getPlayerItemById(cid, true, 2207)
doTransformItem(item.uid, 2208)
You can only transform one item into another, unfortunately not 2 items to 1 ;)
 
Change
LUA:
local item = getPlayerItemById(cid, true, 2168)
local item = getPlayerItemById(cid, true, 2207)
doTransformItem(item.uid, 2208)
to
LUA:
doPlayerRemoveItem(cid, 2168, 2)
local item = getPlayerItemById(cid, true, 2207)
doTransformItem(item.uid, 2208)
You can only transform one item into another, unfortunately not 2 items to 1 ;)

Still dont work, NPC just don't answer me :(:

03:12 GoD [8]: armor ring #1
03:12 Aldo: Sorry, you don't have enough gold. (I know i dont have gold, but NPC answer when i said to him armor ring #1)
03:12 GoD [8]: armor ring #2
And nothing
 
You'd have to say:

GoD: change
Aldo: blabla
God: armor ring #2

If you exchange the first ring then the talkState[talkUser] will be back to 0.
Either say "change" again or delete this line:
LUA:
elseif(msgcontains(msg, 'armor ring #1') and talkState[talkUser] == 1) then
		if(getPlayerItemCount(cid, 2168) >= 1) then
			if(doPlayerRemoveMoney(cid, 1000000)) then
				local item = getPlayerItemById(cid, true, 2168)
				doTransformItem(item.uid, 2207)
				selfSay('Here you are.', cid)
			else
				selfSay('Sorry, you don\'t have enough gold.', cid)
		end
				talkState[talkUser] = 0  --delete it or comment it out and try again
	elseif(msgcontains(msg, 'armor ring #2') and talkState[talkUser] == 1) then
		if(getPlayerItemCount(cid, 2168) >= 2) and (getPlayerItemCount(cid, 2207) >= 1) then
			if(doPlayerRemoveMoney(cid, 1000000)) then
				local item = getPlayerItemById(cid, true, 2168)
				local item = getPlayerItemById(cid, true, 2207)
				doTransformItem(item.uid, 2208)
				selfSay('Here you are.', cid)
			else
				selfSay('Sorry, you don\'t have enough gold.', cid)
			end
		else
			selfSay('Sorry, you don\'t have the item.', cid)
		end
		talkState[talkUser] = 0 -- this line to, delete or comment it out

The rest seems fine, if it still won't work I'll test it on my own server and fix it.
 
You'd have to say:

GoD: change
Aldo: blabla
God: armor ring #2

If you exchange the first ring then the talkState[talkUser] will be back to 0.
Either say "change" again or delete this line:
LUA:
elseif(msgcontains(msg, 'armor ring #1') and talkState[talkUser] == 1) then
		if(getPlayerItemCount(cid, 2168) >= 1) then
			if(doPlayerRemoveMoney(cid, 1000000)) then
				local item = getPlayerItemById(cid, true, 2168)
				doTransformItem(item.uid, 2207)
				selfSay('Here you are.', cid)
			else
				selfSay('Sorry, you don\'t have enough gold.', cid)
		end
				talkState[talkUser] = 0  --delete it or comment it out and try again
	elseif(msgcontains(msg, 'armor ring #2') and talkState[talkUser] == 1) then
		if(getPlayerItemCount(cid, 2168) >= 2) and (getPlayerItemCount(cid, 2207) >= 1) then
			if(doPlayerRemoveMoney(cid, 1000000)) then
				local item = getPlayerItemById(cid, true, 2168)
				local item = getPlayerItemById(cid, true, 2207)
				doTransformItem(item.uid, 2208)
				selfSay('Here you are.', cid)
			else
				selfSay('Sorry, you don\'t have enough gold.', cid)
			end
		else
			selfSay('Sorry, you don\'t have the item.', cid)
		end
		talkState[talkUser] = 0 -- this line to, delete or comment it out

The rest seems fine, if it still won't work I'll test it on my own server and fix it.

Still don't work just like lines about armor ring #2 does not exist
 
Aight, fixed it:

LUA:
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 talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
	if(msgcontains(msg, 'change')) then
		selfSay('What Armor Ring You want? Type Armor Ring #Number', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'armor ring #1') and talkState[talkUser] == 1) then
		if(getPlayerItemCount(cid, 2168) >= 1) then
			if(doPlayerRemoveMoney(cid, 1000000)) then
				local item = getPlayerItemById(cid, true, 2168)
				doTransformItem(item.uid, 2207)
				selfSay('Here you are.', cid)
			else
				selfSay('Sorry, you don\'t have enough gold.', cid)
			end
		else
			selfSay('Sorry, you don\'t have the item.', cid)
		end
		talkState[talkUser] = 0
	elseif (msgcontains(msg, 'armor ring #2') and talkState[talkUser] == 1) then
		if (getPlayerItemCount(cid, 2168) >= 2) and (getPlayerItemCount(cid, 2207) >= 1) then
			if doPlayerRemoveMoney(cid, 1000000) then
				doPlayerRemoveItem(cid, 2168, 2)
				local item = getPlayerItemById(cid, true, 2207)
				doTransformItem(item.uid, 2208)
				selfSay('Here you are.', cid)
			else
				selfSay('Sorry, you don\'t have enough gold.', cid)
			end
		else
			selfSay('Sorry, you don\'t have the item.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	end 
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

You'd have to do it like that:

GoD: change
NPC: blabla
GoD: armor ring #1
NPC: here you go
GoD: change
NPC: blabla
GoD: armor ring #2
NPC: here you go

You always have to say "change" again if you want to exchange another ring.
If you don't want to do that tell me, I'll edit it so you say "armor ring #1 -> here you go / armor ring #2 -> here you go"
But I guess it's fine like that.
 
Last edited:
Back
Top