Fermantor
Active Member
Hello everyone. I have a few questions about the npc question for the trade function.
Things I know how to do, but wanna do "better" are:
-Send trade window only if specific storage is on X
-Trade more items, the more storageValue you got
-Trade only on special word (not trade)
-Buy with Backpacks enabled
What I want:
Add items the usual way with the "shopModule:addBuyableItem" function and only check in the trade request for a storage.
Here is a npc script, that has a few of this things, but (imo) very poorly done
Things I know how to do, but wanna do "better" are:
-Send trade window only if specific storage is on X
-Trade more items, the more storageValue you got
-Trade only on special word (not trade)
-Buy with Backpacks enabled
What I want:
Add items the usual way with the "shopModule:addBuyableItem" function and only check in the trade request for a storage.
Here is a npc script, that has a few of this things, but (imo) very poorly done
Lua:
local t = {
[18457] = {price = 150, price2 = 0}, -- [ITEMID TO SELL] = {Buy cost (0 = not buyable), sell cost (0 = not sellable)}
}
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
local price = t[item].price*amount
if inBackpacks then
price = price + 20
end
if getPlayerMoney(cid) < price then
selfSay("Es tut mir leid, aber Du hast nicht genug Geld.", cid)
else
if inBackpacks then
local Backpack = doCreateItemEx(1988, 1)
doAddContainerItem(Backpack, item, amount)
doPlayerAddItemEx(cid, Backpack)
else
doPlayerAddItem(cid, item, amount)
end
doPlayerRemoveMoney(cid, price)
doPlayerSendTextMessage(cid, 20, "Du hast " .. amount .. "x " .. getItemName(item) .. " für " .. price .. " Gold gekauft.")
end
return true
end
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
if msg == "hi" or msg == "hallo" or msg == "hello" then
if getPlayerStorageValue(cid, 51234) == 2 then
npcHandler:say("Oh, hallo! Ich bin der Gnome-Mensch Beziehungs Assistent. Ich tausche Deine {Tokens} gegen {Equipment}, versoge Dich mit Missions {Items} und rede mit Dir über Deine {Beziehung} zu uns Gnomen! Außerdem tausche ich Teile von {Statuen} ein.", cid)
npcHandler:addFocus(cid)
else
npcHandler:say("Du scheinst neu hier zu sein. Sprich am besten erstmal mit Gnomette!", cid)
end
else
return false
end
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local shopWindow = {}
if msg == "job" or msg == "beruf" then
npcHandler:say('',cid)
elseif msg == "items" then
if getPlayerStorageValue(cid, 51234) == 2 then
for var, ret in pairs(t) do
table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = ret.price2, name = getItemName(var)})
end
openShopWindow(cid, shopWindow, onBuy, onSell)
npcHandler:say('Hier ist mein Angebot. Es ist nicht groß, aber es erfüllt seinen Zweck.', cid)
end
elseif msgcontains(msg, "bye") then
npcHandler:say("Bye.", cid)
npcHandler:releaseFocus(cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)