• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

NPC Tutor Shop - An NPC shop only Tutors or GM's can use!

Candlejack

Don't hug me I'm scared
Joined
Jun 20, 2012
Messages
87
Reaction score
38
Location
nowhere
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())
 
mehh, I don't really see the point in this script but if you only want tutors --> Admins to use it then it should be written like so,
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 = 2

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())
Maybe you want to set certain items as rewards for the good work that those tutors have done, or normal items at cheaper prices & the players have to work their way to become tutors, which will motivate them to help others?
 
It was very useful in my OT TibiaLife.
In my OT Tutors are "Cops" and enforce Laws. They could use this shop to buy special items to send players to jail, handcuff players or tase them if they run away.
As a result they'd collect bounty money when they stopped criminals to buy even better "cop items".
SHAMELESS ADVERTISEMENT: https://otland.net/threads/tibialif...rugs-robbery-jail-bounties-mining-etc.231528/

It took me forever to figure out how to script this and I couldn't much help from the forums. So I just decided to release it in case someone ends up like I did :)
 
not sure if it would work (with some modifications) in your version, but when I did this, it was only a few lines:
npc.xml
Code:
<parameter key="module_shop" value="1"/>
<parameter key="shop_buyable" value="assassin star,7368,100" />

npc.lua
Code:
function onTradeRequest(cid)
    local player = Player(cid)
    if not Player(player) then
        return false
    end
   
    return player:getGroup() == 3 and true or npcHandler:say("I have nothing to trade with you.", cid)
end
npcHandler:setCallback(CALLBACK_ONTRADEREQUEST, onTradeRequest)
Not sure if your version of TFS has such npc callbacks or not.
 
Back
Top