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

Solved Help with NPC

Phemus

Member
Joined
Jun 16, 2012
Messages
150
Solutions
2
Reaction score
13
Hi! I have a problem... I have a npc script that when you give to him 100 white pearls and 100 black pearls it have to give you a storage value. But my problem is that when you give to him 100 white pearls and like 50 black pearls, it removes you the white pearls and leave you with the black pearls. It is supposed that he only needs to say, "Do not try to deceive me." and leave you with the pearls.

Here is the 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, 'panda')) then
	selfSay('To have the panda outfit you need 100 white pearls and 100 black pearls, when you come back tell me about the {outfit}.', cid)
 
	talkState[talkUser] = 1
elseif (msgcontains(msg, 'outfit')) then
	if (getPlayerStorageValue(cid,12703) >= 1) then
		selfSay('already have this outfit, I\'m sorry.', cid)
	else
		if (doPlayerRemoveItem(cid, 2143, 100) == TRUE) and (doPlayerRemoveItem(cid, 2144, 100) == TRUE) then
			setPlayerStorageValue(cid,12703,1)
			doSendMagicEffect(getCreaturePosition(cid), 13)
			selfSay('I thank you, thank you very much, is not much but take this as thanks.', cid)
		else
			selfSay('Do not try to deceive me.', cid)
end
		
	end
	return true
end
    return TRUE    
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

I hope that you can understand my problem and somebody could help and sorry for my bad English. :)
 
Last edited:
change this line
LUA:
if (doPlayerRemoveItem(cid, 2143, 100) == TRUE) and (doPlayerRemoveItem(cid, 2144, 100) == TRUE) then
to
LUA:
if (getPlayerItemCount(cid, 2143) >= 100) and (doPlayerRemoveItem(cid, 2144, 100) == TRUE) then
 

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, 'panda')) then
		selfSay('To have the panda outfit you need 100 white pearls and 100 black pearls, when you come back tell me about the {outfit}.', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'outfit')) then
		if (getPlayerStorageValue(cid,12703) >= 1) then
			selfSay('already have this outfit, I\'m sorry.', cid)
		else
			if(getPlayerItemCount(cid, 2143) >= 100 and getPlayerItemCount(cid, 2144) >= 100) then
				if(doPlayerRemoveItem(cid, 2143, 100) and doPlayerRemoveItem(cid, 2144, 100)) then
					setPlayerStorageValue(cid,12703,1)
					doSendMagicEffect(getCreaturePosition(cid), 13)
					selfSay('I thank you, thank you very much, is not much but take this as thanks.', cid)
				else
					selfSay('Something has gone wrong, please report this to a gamemaster.', cid)
				end
			else
				selfSay('Do not try to deceive me.', cid)
			end
		end
		return true
	end
    return true    
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

What you are doing wrong is that you are trying to remove the item from the player and if it doesnt remove them all then it says the text, you should only be checking to see if the items are there before proceeding (using getPlayerItemCount >= 100, you have 100 or more black pearls)

EDIT: as up post says too :P
 
Back
Top