• 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 [TFS 0.X] NPC Responds to "instant buy"

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,403
Solutions
17
Reaction score
151
Location
Brazil
Hello guys, how are you?

I saw this in another retro OTs a very interesting thing. How to NPC answer a player without put it in a queue, like some servers have "bring me to" in boaters NPC without need to say "hi". I want the same thing for my sellers and buyers NPCs. If u want to buy a SD just say "instant buy 3 sd" npc gives instantly (if player have money). In another one, "instant sell golden legs". There's a way to do this?

Here's an example for rune seller NPC:

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

shopModule:addBuyableItem({'light wand', 'lightwand'},         2163, 500,         'magic light wand')
shopModule:addBuyableItem({'blank'},                 2260, 10,         'blank rune')

shopModule:addBuyableItem({'wand of inferno', 'inferno'},                 2187, 15000,     'wand of inferno')
shopModule:addBuyableItem({'wand of plague', 'plague'},                 2188, 5000,     'wand of plague')
shopModule:addBuyableItem({'wand of cosmic energy', 'cosmic energy'},             2189, 10000,    'wand of cosmic energy')
shopModule:addBuyableItem({'wand of vortex', 'vortex'},                 2190, 500,     'wand of vortex')
shopModule:addBuyableItem({'wand of dragonbreath', 'dragonbreath'},             2191, 1000,     'wand of dragonbreath')

shopModule:addBuyableItem({'quagmire rod', 'quagmire'},                 2181, 10000,     'quagmire rod')
shopModule:addBuyableItem({'snakebite rod', 'snakebite'},                 2182, 500,     'snakebite rod')
shopModule:addBuyableItem({'tempest rod', 'tempest'},                     2183, 15000,     'tempest rod')
shopModule:addBuyableItem({'volcanic rod', 'volcanic'},                 2185, 5000,     'volcanic rod')
shopModule:addBuyableItem({'moonlight rod', 'moonlight'},                 2186, 1000,       'moonlight rod')
shopModule:addBuyableItem({'suden death', 'sd'},                 2268, 6000,100,       'sudden death rune')
shopModule:addBuyableItem({'mana rune', 'manarune'},                 2281,70000,100,       'mana rune')
shopModule:addBuyableItem({'magic wall', 'mw'},                 2293, 8000,100,       'magic wall rune')
shopModule:addBuyableItem({'ultimate healing', 'uh'},                 2273, 3000,100,       'ultimate healing rune')
shopModule:addBuyableItem({'explosion', 'explosion'},                 2313, 3000,100,       'explosion rune')
shopModule:addBuyableItem({'mana fluid', 'manafluid'}, 5891, 100,     'mana fluid')
shopModule:addBuyableItemContainer({'bpmanafluid', 'bp of mf', 'manafluidbp', 'backpack manafluid', 'bp of manafluid', 'bp of mana fluid', 'backpack of mf', 'backpack of manafluid', 'bp mf'}, 2001, 5891, 2000, 1, 'backpack of mana fluid')
shopModule:addBuyableItem({'great fireball', 'gfb'},                 2304, 2000,100,       'great fireball rune')
shopModule:addBuyableItem({'great hurball', 'ghb'},                 2276, 3000,100,       'great hurball rune')
shopModule:addBuyableItem({'destroy field', 'destroy field'},                 2261, 5000,100,       'destroy field rune')


shopModule:addSellableItem({'wand of vortex', 'vortex'}, 2190, 100, 'wand of vortex')
shopModule:addSellableItem({'wand of dragonbreath', 'dragonbreath'}, 2191, 200, 'wand of dragonbreath')
shopModule:addSellableItem({'wand of plague', 'plague'}, 2188, 1000, 'wand of plague')
shopModule:addSellableItem({'wand of cosmic energy', 'cosmic energy'}, 2189, 2000, 'wand of cosmic energy')
shopModule:addSellableItem({'wand of inferno', 'inferno'}, 2187, 3000, 'wand of inferno')

shopModule:addSellableItem({'snakebite rod', 'snakebite'}, 2182, 100, 'snakebite rod')
shopModule:addSellableItem({'moonlight rod', 'moonlight'}, 2186, 200, 'moonlight rod')
shopModule:addSellableItem({'volcanic rod', 'volcanic'}, 2185, 1000, 'volcanic rod')
shopModule:addSellableItem({'quagmire rod', 'quagmire'}, 2181, 2000, 'quagmire rod')
shopModule:addSellableItem({'tempest rod', 'tempest'}, 2183, 3000, 'tempest rod')

function creatureSayCallback(cid, type, msg)
    if(npcHandler.focus ~= cid) then
        return FALSE
    end
    if msgcontains(msg, 'runes') then
        selfSay("I sell heavy magic missiles runes, explosion runes, great fireball runes, ultimate healing runes, sudden death runes, mana runes and blank runes.")
        talk_state = 0
    elseif msgcontains(msg, 'heavy magic missile') or msgcontains(msg, 'hmm') and ShopModule:getCount(msg) <= 100 then
        charges = ShopModule:getCount(msg)
        price = 15*charges
        selfSay('Do you want a heavy magic missile rune with '..charges..' charges for '..price..' gold coins?')
        talk_state = 1
        itemid = 2311
    elseif msgcontains(msg, 'great fireball') or msgcontains(msg, 'gfb') and ShopModule:getCount(msg) <= 100 then
        charges = ShopModule:getCount(msg)
        price = 25*charges
        selfSay('Do you want a great fireball rune with '..charges..' charges for '..price..' gold coins?')
        talk_state = 1
        itemid = 2304
    elseif msgcontains(msg, 'great hurball') or msgcontains(msg, 'ghb') and ShopModule:getCount(msg) <= 100 then
        charges = ShopModule:getCount(msg)
        price = 25*charges
        selfSay('Do you want a great fireball rune with '..charges..' charges for '..price..' gold coins?')
        talk_state = 1
        itemid = 2276
    elseif msgcontains(msg, 'explosion') or msgcontains(msg, 'xpl') and ShopModule:getCount(msg) <= 100 then
        charges = ShopModule:getCount(msg)
        price = 40*charges
        selfSay('Do you want an explosion rune with '..charges..' charges for '..price..' gold coins?')
        talk_state = 1
        itemid = 2313
    elseif msgcontains(msg, 'ultimate healing') or msgcontains(msg, 'uh') and ShopModule:getCount(msg) <= 100 then
        charges = ShopModule:getCount(msg)
        price = 35*charges
        selfSay('Do you want an ultimate healing rune with '..charges..' charges for '..price..' gold coins?')
        talk_state = 1
        itemid = 2273
    elseif msgcontains(msg, 'sudden death') or msgcontains(msg, 'sd') and ShopModule:getCount(msg) <= 100 then
        charges = ShopModule:getCount(msg)
        price = 60*charges
        selfSay('Do you want a sudden death rune with '..charges..' charges for '..price..' gold coins?')
        talk_state = 1
        itemid = 2268
    elseif msgcontains(msg, 'manarune') or msgcontains(msg, 'mana rune') and ShopModule:getCount(msg) <= 100 then
        charges = ShopModule:getCount(msg)
        price = 700*charges
        selfSay('Do you want a mana rune with '..charges..' charges for '..price..' gold coins?')
        talk_state = 1
        itemid = 2281
    elseif msgcontains(msg, 'yes') and talk_state == 1 then
        if doPlayerRemoveMoney(cid, price) == TRUE then
            doPlayerGiveItem(cid, itemid, 1, charges)
            selfSay("You have bought this rune.")
            talk_state = 0
        else
            selfSay("You don't have enough money.")
            talk_state = 0
        end
    elseif msgcontains(msg, 'no') and talk_state == 1 then
        selfSay("Then not.")
        talk_state = 0
    end
    return TRUE
end

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