• 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] Change g helmet for piggybank

Nevalopo

Demigod
Joined
Jul 21, 2008
Messages
5,165
Reaction score
68
Location
Sweden, Landskrona
[Request] Change g helmet for piggybank
Yeah well.. it sounds stupid lol i know but i want an npc to change a g helmet for a piggybank.. i tryed messing with the scripts but it fails all time so i need someone to help me :p
id g helmet: 2471
id piggybank: 2508
Thanks
 
PHP:
if doPlayerRemoveItem(cid,2471,1) == TRUE then
    selfSay('Take this piggybank as a reward!')
    doPlayerAddItem(cid, 2508, 1)
else
    selfSay('You do not have the required item.')
end
That should do (thank you Marcinek for the clearance).
 
Last edited:
Code:
    if doPlayerRemoveItem(cid, 2471, 1) == TRUE then

And checking count is not necessery when you are removing the item o,o
 
PHP:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
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
-- OTServ event handling functions end


function creatureSayCallback(cid, type, msg)
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    if(npcHandler.focus ~= cid) then
        return false
    end

    if msgcontains(msg, 'piggybank') or msgcontains(msg, 'golden helmet') then
        if doPlayerRemoveItem(cid,2471,1) == TRUE then
            selfSay('Take this piggybank as a reward!')
            doPlayerAddItem(cid, 2508, 1)
        else
            selfSay('You do not have the required item.')
        end  
    end
end

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

There you go. ^^
 
Code:
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, 'golden helmet') or msgcontains(msg, 'trade')) then
		selfSay("I will trade a piggy bank for your golden helmet. Deal?", cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'deal') or msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if doPlayerRemoveItem(cid,2471,1) == TRUE then
			selfSay('Take this piggybank as a reward!')
			doPlayerAddItem(cid, 2508, 1)
		else
			selfSay('You do not have the required item.')
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
		selfSay("Then not, gtfo.", cid)
		talkState[talkUser] = 0
	return true
end

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

Should do the thing.
 
Back
Top