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

Solved Noob LUA Question about Shop NPC :) tfs 0.3.6 [solved]

Candlejack

Don't hug me I'm scared
Joined
Jun 20, 2012
Messages
87
Reaction score
38
Location
nowhere
Basically I don't want the player to be able to trade with an NPC unless this storage variable is set to 1.

This isn't working! Any thoughts? Thank you!

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local storage = 5556

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 shopModule = ShopModule:new()


local function creatureSayCallback(cid, type, msg)
    if msgcontains(msg, "trade") then
    if getPlayerStorageValue(cid, storage) == 1 then
      
        npcHandler:addModule(shopModule)

        shopModule:addBuyableItem({'scythe'}, 2550, 800, 1, 'scythe')

        shopModule:addSellableItem({'gram of heroin', 'gram of heroin'}, 5886, 500, 'gram of heroin')
        shopModule:addSellableItem({'gram of weed', 'gram of weed'}, 10608, 175, 'gram of weed')
        shopModule:addSellableItem({'cocaine', 'cocaine'}, 4849, 400, 'cocaine')


        npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
        npcHandler:addModule(FocusModule:new())
    else
        npcHandler:say("Sorry, You're not allowed to use this shop.", cid)
    end
    end
end
 
Last edited:
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 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) == 3 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())
 
Back
Top