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

[NPC] Will trade only if quest is finished.

Shadowsong

Game Developer & Graphic Designer
Joined
Feb 23, 2010
Messages
3,446
Solutions
21
Reaction score
3,014
Location
Bosnia & Herzegovina
YouTube
ShivaShadowsong
Hi. I need a NPC that will agree to open the trade window only if player has a certain storage value, else the NPC will refuse to trade. It's something like Rashid of RL Tibia, but without all his missions and stuff.
(I btw, have looked at a rl-like Rashid script and couldn't understand how to do this :\)

I'm using TFS 0.3.6. crying damson.
 
I dont know if it works, i've never worked on 8.x ots this is just what i've found and edit

Code:
local keywordHandler = KeywordHandler:new() 
local npcHandler = NpcHandler:new(keywordHandler) 
NpcSystem.parseParameters(npcHandler) 
local talkState = {} 
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
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)
talkState[talkUser] = 0
return true
end

function creatureSayCallback(cid, type, msg) 
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

	        if(not npcHandler:isFocused(cid)) then  
	                return false  
	        end 
local trade = { 
                  {id=7589, buy=80, sell=10, name="strong mana potion"}, 
                  {id=7591, buy=190, sell=10, name="great health potion"},
                  }
local items = {}  
    for _, item in ipairs(trade) do 
    items[item.id] = {storage = item.storage, item_id = item.id, buyPrice = item.buy, sellPrice = item.sell, subType = 0, realName = item.name} 
end 

	local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)  
	    if items[item].buyPrice ~= 0 then  
	        doPlayerRemoveMoney(cid, amount * items[item].buyPrice)  
	        for i = 1, amount do 
	            doPlayerAddItem(cid, items[item].item_id, amount)  
	        end 
	    end 
	end 
	    
	local onSell = function(cid, item, subType, amount, ignoreCap, inBackpacks)  
	    if items[item].sellPrice ~= 0 then  
	        doPlayerAddMoney(cid, items[item].sellPrice * amount)  
	        doPlayerRemoveItem(cid, items[item].item_id, amount)  
	        doNPCTalkALot(cid, 200, {"You sell "..amount.." "..items[item].realName.." for "..items[item].sellPrice * amount.." gold coins."})  
               end 
               end 
    if msgcontains(msg, 'trade') or msgcontains(msg, 'offer') then  
        if (getPlayerStorageValue(cid, 1002) ~= 1) then
            selfSay("I won't trade with you", cid))
       else
            openShopWindow(cid, trade, onBuy, onSell) 
	 selfSay("It's my offer.", cid)   
       end
    end
return 1
end

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