• 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 Any way to modify shop modules to reference quest status? [OTHire]

Xapafe

Member
Joined
Jul 22, 2013
Messages
83
Reaction score
6
I'm working on the postman quest, and I'm trying to work out my discounts.

As of now, I have a crappy system that will check the status of the quest when you say letter or parcel, and then sell you whichever one you qualify for.. discount or not.

BUT I'd like to know how to allow for multiples, like 3 parcels for example. Right now I can only do one at a time.

This is possible with shop modules but I don't know how to make them check a player storage value to alter the prices.
 
OR Is there a way to "mix" these two scripts? I'm gonna sound totally noobish here so get ready. This is the edge of my understand of this lua.

There a way to do something like

Code:
if getPlayerStorageValue(cid, 60200) == 1 then

shop_module 1 or whatever

end

if getPlayerStorageValue(cid, 60200) ~= 1 then
shop_module 2 or whatever

end
 
Okay okay! I see the light here! I have added a slightly modified version of that function to my npcsystem, but how do I incorporate the postman quest variable into this? I feel like his sotrage.postman.rank is a custom variable.
 
Last edited:
if player:getStorageValue(Storage.thievesGuild.Quest) >= 9 then

so I could just put

if player:getStorageValue(10000) = 1 then ?
 
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 config = {
ranks = {
rank1 = {
    {id = 2597, buy=0, sell = 8, name='letter', name='letter'}, ----- EDIT HERE THE ITEMS IF YOU WANT WITH STORAGE
    {id = 2595, buy=0, sell = 15, name='parcel', name='parcel'}
    },
   
      
rank2 = {
    {id = 2597, buy=0, sell = 5, name='letter', name='letter'}, ----- EDIT HERE THE ITEMS IF YOU WANT WITH STORAGE
    {id = 2595, buy=0, sell = 10, name='parcel', name='parcel'}

    }
        }
                }
   
   
   
local Topic = {}
function greetCallback(cid)
    Topic[cid] = 0
    return true
end

local function setNewTradeTable(table)
local items = {}
for _, v in ipairs(table) do
    items[v.id] = {itemId = v.id, buyPrice = v.buy, sellPrice = v.sell, subType = 0, realName = v.name}
end
return items
end

local function setNewLineTable(oldTable, newTable)
for k, v in pairs(oldTable) do
    table.insert(newTable, k, v)
end
return true
end

function creatureSayCallback(cid, type, msg)
    if(npcHandler.focus ~= cid) then
        return false
    end

local talkUser = cid



if msgcontains(msg, 'trade') then
    if getPlayerStorageValue(cid, 60200) == 1 then
        tradeConfig = config.ranks.rank2
        else
        tradeConfig = config.ranks.rank1
    end
                local items = setNewTradeTable(tradeConfig)
            local function onBuy(cid, item, subType, amount, ignoreCap, inBackpacks)
            if ignoreCap == false and (getPlayerFreeCap(cid) < getItemWeight(items[item].itemId, amount) or inBackpacks and getPlayerFreeCap(cid) < (getItemWeight(items[item].itemId, amount) + getItemWeight(1988, 1))) then
                return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You don\'t have enough cap.')
            end
            if items[item].buyPrice then
                for i = 1, amount do
                    if inBackpacks then
                        doPlayerRemoveMoney(cid, amount * items[item].buyPrice + 20)
                        local backpack = doPlayerAddItem(cid, 1988, 1)
                        doAddContainerItem(backpack, items[item].itemId, amount)
                        return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You bought '..amount..'x '..items[item].realName..' for '..(items[item].buyPrice * amount + 20)..' gold coins.')
                    else
                                                doPlayerRemoveMoney(cid, amount * items[item].buyPrice)
                                                doPlayerAddItem(cid, items[item].itemId, amount, true)
                                                return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You bought '..amount..'x '..items[item].realName..' for '..items[item].buyPrice * amount..' gold coins.')
                    end
                end
            end
            return true
            end
end

return TRUE
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Here's what I have so far, he isn't responding to "trade", but I assume its probably a TFS mismatch, since I'm using OTHire.

Any way to make this an "automatic" style conversation.

Like, he checks the status when you say hi, and goes from here.

for instance.

Player(nonDiscount): buy parcel
NPC: Want to buy parcel for 15gp?

Player(discount): buy parcel
NPC: want to buy parcel for 10gp?

With this current clipped up script, you would have to initiate "trade" after you say hi.


Ya know? Sorry, I'm trying to properly articulate this, lol.
 
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 config = {
ranks = {
rank1 = {
    {id = 2597, buy=0, sell = 8, name='letter', name='letter'}, ----- EDIT HERE THE ITEMS IF YOU WANT WITH STORAGE
    {id = 2595, buy=0, sell = 15, name='parcel', name='parcel'}
    },
  
     
rank2 = {
    {id = 2597, buy=0, sell = 5, name='letter', name='letter'}, ----- EDIT HERE THE ITEMS IF YOU WANT WITH STORAGE
    {id = 2595, buy=0, sell = 10, name='parcel', name='parcel'}

    }
        }
                }
  
  
  
local Topic = {}
function greetCallback(cid)
    Topic[cid] = 0
    return true
end

local function setNewTradeTable(table)
local items = {}
for _, v in ipairs(table) do
    items[v.id] = {itemId = v.id, buyPrice = v.buy, sellPrice = v.sell, subType = 0, realName = v.name}
end
return items
end

local function setNewLineTable(oldTable, newTable)
for k, v in pairs(oldTable) do
    table.insert(newTable, k, v)
end
return true
end

function creatureSayCallback(cid, type, msg)
    if(npcHandler.focus ~= cid) then
        return false
    end

local talkUser = cid



if msgcontains(msg, 'trade') then
    if getPlayerStorageValue(cid, 60200) == 1 then
        tradeConfig = config.ranks.rank2
        else
        tradeConfig = config.ranks.rank1
    end
                local items = setNewTradeTable(tradeConfig)
            local function onBuy(cid, item, subType, amount, ignoreCap, inBackpacks)
            if ignoreCap == false and (getPlayerFreeCap(cid) < getItemWeight(items[item].itemId, amount) or inBackpacks and getPlayerFreeCap(cid) < (getItemWeight(items[item].itemId, amount) + getItemWeight(1988, 1))) then
                return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You don\'t have enough cap.')
            end
            if items[item].buyPrice then
                for i = 1, amount do
                    if inBackpacks then
                        doPlayerRemoveMoney(cid, amount * items[item].buyPrice + 20)
                        local backpack = doPlayerAddItem(cid, 1988, 1)
                        doAddContainerItem(backpack, items[item].itemId, amount)
                        return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You bought '..amount..'x '..items[item].realName..' for '..(items[item].buyPrice * amount + 20)..' gold coins.')
                    else
                                                doPlayerRemoveMoney(cid, amount * items[item].buyPrice)
                                                doPlayerAddItem(cid, items[item].itemId, amount, true)
                                                return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You bought '..amount..'x '..items[item].realName..' for '..items[item].buyPrice * amount..' gold coins.')
                    end
                end
            end
            return true
            end
end

return TRUE
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Here's what I have so far, he isn't responding to "trade", but I assume its probably a TFS mismatch, since I'm using OTHire.

Any way to make this an "automatic" style conversation.

Like, he checks the status when you say hi, and goes from here.

for instance.

Player(nonDiscount): buy parcel
NPC: Want to buy parcel for 15gp?

Player(discount): buy parcel
NPC: want to buy parcel for 10gp?

With this current clipped up script, you would have to initiate "trade" after you say hi.


Ya know? Sorry, I'm trying to properly articulate this, lol.
Learn to properly tab your code.
You'll spend 80-90% of your time reading code, and 10% writing it.
Since most of your time is spent reading code, spending the extra time to properly indent the code in the first place, is going to save you, and others, lots of time.

Here's your code, properly indented. (with some green text added, that may solve your issue.. (I never really looked at the code itself.))
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 config = {
    ranks = {
        rank1 = {
            {id = 2597, buy=0, sell = 8, name='letter', name='letter'}, ----- EDIT HERE THE ITEMS IF YOU WANT WITH STORAGE
            {id = 2595, buy=0, sell = 15, name='parcel', name='parcel'}
          },
   
     
    rank2 = {
        {id = 2597, buy=0, sell = 5, name='letter', name='letter'}, ----- EDIT HERE THE ITEMS IF YOU WANT WITH STORAGE
        {id = 2595, buy=0, sell = 10, name='parcel', name='parcel'}
    }
}
-- } -- THIS IS AN EXTRA??
   
   
   
local Topic = {}
function greetCallback(cid)
    Topic[cid] = 0
    return true
end

local function setNewTradeTable(table)
    local items = {}
    for _, v in ipairs(table) do
        items[v.id] = {itemId = v.id, buyPrice = v.buy, sellPrice = v.sell, subType = 0, realName = v.name}
    end
    return items
end

local function setNewLineTable(oldTable, newTable)
    for k, v in pairs(oldTable) do
        table.insert(newTable, k, v)
    end
    return true
end

function creatureSayCallback(cid, type, msg)
    if(npcHandler.focus ~= cid) then
        return false
    end

    local talkUser = cid



    if msgcontains(msg, 'trade') then
        if getPlayerStorageValue(cid, 60200) == 1 then
            tradeConfig = config.ranks.rank2
        else
            tradeConfig = config.ranks.rank1
        end
        local items = setNewTradeTable(tradeConfig)
        local function onBuy(cid, item, subType, amount, ignoreCap, inBackpacks)
        if ignoreCap == false and (getPlayerFreeCap(cid) < getItemWeight(items[item].itemId, amount) or inBackpacks and getPlayerFreeCap(cid) < (getItemWeight(items[item].itemId, amount) + getItemWeight(1988, 1))) then
            return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You don\'t have enough cap.')
        end
        if items[item].buyPrice then
            for i = 1, amount do
                if inBackpacks then
                    doPlayerRemoveMoney(cid, amount * items[item].buyPrice + 20)
                    local backpack = doPlayerAddItem(cid, 1988, 1)
                    doAddContainerItem(backpack, items[item].itemId, amount)
                    return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You bought '..amount..'x '..items[item].realName..' for '..(items[item].buyPrice * amount + 20)..' gold coins.')
                else
                    doPlayerRemoveMoney(cid, amount * items[item].buyPrice)
                    doPlayerAddItem(cid, items[item].itemId, amount, true)
                    return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, 'You bought '..amount..'x '..items[item].realName..' for '..items[item].buyPrice * amount..' gold coins.')
                end
            end
        end
        -- return true -- IS THIS RETURN TRUE NEEDED?
    end
-- end -- THIS IS AN EXTRA END

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Bump.

Disregard my last posts, I'm wrong. The code I was using relied on a "trade" command to open, while OTHire doesn't use it. It's 7.6.
 
Back
Top