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

Lua I'm asking the wrong question regarding modifying the shop modules [OTHire]

Xapafe

Member
Joined
Jul 22, 2013
Messages
83
Reaction score
6
I have identifed the solution, I just need a bit of help now. In regards to StreamSlide's post, I've used this code to change around my modules.lua.

Code:
    -- Discount function for postman style quests
   
    local travelDiscounts = {
    ['letter'] = {price = 3, storage = 60200, value = 1},
}

function StdModule.travelDiscount(player, discounts)
    local discountPrice, discount = 0
    if type(discounts) == 'string' then
        discount = travelDiscounts[discounts]
        if discount and player:getStorageValue(discount.storage) >= discount.value then
            return discount.price
        end
    else
        for i = 1, #discounts do
            discount = travelDiscounts[discounts[i]]
            if discount and player:getStorageValue(discount.storage) >= discount.value then
                discountPrice = discountPrice + discount.price
            end
        end
    end

    return discountPrice
end

So now the discount function is defined, I'm unsure on how to modify the syntax for buying items.. for example here is a sample code of a normal shop module without the discount attribute.

Code:
shopModule:addBuyableItem({'letter'},2597, 8,         'letter')

How do I change the rest of my buyable items module to allow for an extra variable "discount" to something like this:

Code:
shopModule:addBuyableItem({'letter'},2597, 8,        'letter', 'postmanDiscount')

My modules.lua: http//pastebin.com/5ygMXK6S

(Ignore the top line on this pastebin, my copy pasta game is weak!)




Again, thank you so much to anyone who takes their time to help me!!

The help I've received here is both undeserved and most helpful, I seriously love this forum!
 
Code:
player:getStorageValue(discount.storage)

this is a tfs 1.x function.. metatable .. could you post addBuyableItem function?
 
Code:
player:getStorageValue(discount.storage)

this is a tfs 1.x function.. metatable .. could you post addBuyableItem function?


I think this is the function you are looking for.


Code:
-- Adds a new buyable item.
    --    names = A table containing one or more strings of alternative names to this item.
    --    itemid = the itemid of the buyable item
    --    cost = the price of one single item with item id itemid ^^
    --    charges - The charges of each rune or fluidcontainer item. Can be left out if it is not a rune/fluidcontainer and no realname is needed. Default value is nil.
    --    realname - The real, full name for the item. Will be used as ITEMNAME in MESSAGE_ONBUY and MESSAGE_ONSELL if defined. Default value is nil (keywords[1]/names  will be used)
    function ShopModule:addBuyableItem(names, itemid, cost, charges, realname)
        for i, name in pairs(names) do
            local parameters = {
                    itemid = itemid,
                    cost = cost,
                    eventType = SHOPMODULE_BUY_ITEM,
                    module = self
                }
            if(realname ~= nil) then
                parameters.realname = realname
            end
            if(isItemRune(itemid) == TRUE or isItemFluidContainer(itemid) == TRUE) then
                parameters.charges = charges
            end
            keywords = {}
            table.insert(keywords, name)
            local node = self.npcHandler.keywordHandler:addKeyword(keywords, ShopModule.tradeItem, parameters)
            node:addChildKeywordNode(self.yesNode)
            node:addChildKeywordNode(self.noNode)
        end
    end
 
http://pastebin.com/Kn4n5Rm9

this is what i edited

Code:
  local travelDiscounts = {
     ['letter'] = {price = 3, storage = 60200, value = 1},
   }
  function ShopModule.onConfirm(cid, message, keywords, parameters, node)
  local module = parameters.module
  if(cid ~= module.npcHandler.focus) then
  return false
  end
  local parentParameters = node:getParent():getParameters()
  local parseInfo = {
  [TAG_PLAYERNAME] = getPlayerName(cid),
  [TAG_ITEMCOUNT] = module.amount,
  [TAG_TOTALCOST] = parentParameters.cost*module.amount,
  [TAG_ITEMNAME] = parentParameters.realname or node:getParent():getKeywords()[1]
  }
  if(parentParameters.eventType == SHOPMODULE_SELL_ITEM) then
  local ret = doPlayerSellItem(cid, parentParameters.itemid, module.amount, parentParameters.cost*module.amount)
  if(ret == LUA_NO_ERROR) then
  local msg = module.npcHandler:getMessage(MESSAGE_ONSELL)
  msg = module.npcHandler:parseMessage(msg, parseInfo)
  module.npcHandler:say(msg)
  else
  local msg = module.npcHandler:getMessage(MESSAGE_NOTHAVEITEM)
  msg = module.npcHandler:parseMessage(msg, parseInfo)
  module.npcHandler:say(msg)
  end
  elseif(parentParameters.eventType == SHOPMODULE_BUY_ITEM) then
       if travelDiscounts[getItemNameById(parentParameters.itemid)] and getPlayerStorageValue(cid travelDiscounts[getItemNameById(parentParameters.itemid)].storage) >= travelDiscounts[getItemNameById(parentParameters.itemid)].value then
         parentParameters.cost = travelDiscounts[getItemNameById(parentParameters.itemid)].price
       end
  local ret = doPlayerBuyItem(cid, parentParameters.itemid, module.amount, parentParameters.cost*module.amount, parentParameters.charges)
  if(ret == LUA_NO_ERROR) then
  local msg = module.npcHandler:getMessage(MESSAGE_ONBUY)
  msg = module.npcHandler:parseMessage(msg, parseInfo)
  module.npcHandler:say(msg)
  else
  local msg = module.npcHandler:getMessage(MESSAGE_NEEDMOREMONEY)
  msg = module.npcHandler:parseMessage(msg, parseInfo)
  module.npcHandler:say(msg)
  end
  end
  
  module.npcHandler:resetNpc()
  return true
  end

Each time the player buys an item.. it checks if it is added in the table.. if yes and player have storage then the price will be edited.. else the price is same
 
Sorry i am not that familiar with npcs it is just an alternative solution

Okay so when I approach a post office NPC and say "letter" they should check my storage value, and if I have said storage it will tell me the normal price - discount.

So in this case, a letter will show as 5?

Because I'm still getting the normal sale price. :S
 
OH I see why.. the NPC system didn't like the new module file lol

Apparently all of my NPC script files that have this cause an error.
NpcSystem.parseParameters(npcHandler)
 
Back
Top