Candlejack
Don't hug me I'm scared
I'm still a novice at scripting. But I managed to conjure this up. This is a shop that only allows people of a certain group id to use it. Change the variable group to whatever you want. Right now it's set at Tutors. Tested on TFS 0.3.6.
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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
local shopWindow = {}
local things = {
{action = 0, id = 2195, buy = 10000, name = "Boots of Haste"},
{action = 1, id = 2195, sell = 135, name = "Boots of Haste"}
}
local group = 3
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
if doPlayerRemoveMoney(cid, shopWindow[item].Price*amount) then
if isItemStackable(item) then
doPlayerAddItem(cid, item, amount)
else
for x = 1, amount do
doPlayerAddItem(cid, item, 1)
end
end
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have bought "..amount.."x "..shopWindow[item].Name.." for "..shopWindow[item].Price*amount.." gold.")
else
selfSay("You don't have enough gold.", cid)
end
return true
end
function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
if msgcontains(msg, 'trade') then
if getPlayerGroupId(cid) == group then
for var, item in pairs(things) do
if item.action == 0 then
shopWindow[item.id] = {Price = item.buy, Name = item.name}
elseif item.action == 1 then
shopWindow[item.id] = {Price = item.sell, Name = item.name}
end
end
openShopWindow(cid, things, onBuy, onSell)
else
npcHandler:say("This shop is only for tutors sorry.")
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())