• 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 HELP TFS 1.4 NPC CHRISTMAS TOKEN

VagosClubTM

Active Member
Joined
Aug 16, 2019
Messages
219
Reaction score
32
Location
Chile
Hello friends I would like to know if you have or can modify this script so that I can trade objects for a specific currency that can be configured. I will leave the npc script.

thank you very much in advance <3


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 voices = { {text = "Dime buy mana rune o mana vida!"} }
npcHandler:addModule(VoiceModule:new(voices))

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

keywordHandler:addKeyword({'stuff'}, StdModule.say, {npcHandler = npcHandler, text = 'Just ask me for a {trade} to see my offers.'})
keywordHandler:addAliasKeyword({'wares'})
keywordHandler:addAliasKeyword({'offer'})

shopModule:addBuyableItem({'spellbook'}, 2175, 150, 'spellbook')
shopModule:addBuyableItem({'aol'}, 2173, 15000, 'aol')
shopModule:addBuyableItem({'magic lightwand'}, 2162, 400, 'magic lightwand')

shopModule:addBuyableItem({'mana rune'}, 2296, 5000, 70, 'mana rune')
shopModule:addBuyableItem({'mana vida'}, 2296, 5000, 70, 'mana vida')
shopModule:addBuyableItem({'sd'}, 2268, 3000, 100, 'sd')
shopModule:addBuyableItem({'transformacion'}, 2295, 10000, 20, 'transformacion')

shopModule:addSellableItem({'picoro legs', 'picoro leg'}, 5091, 150000, 'picoro legs')

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)
    local vocationId = player:getVocation():getId()
    local items = {
        [1] = 2190,
        [2] = 2182,
        [5] = 2190,
        [6] = 2182
    }

    if msgcontains(msg, 'first rod') or msgcontains(msg, 'first wand') then
        if table.contains({1, 2, 5, 6}, vocationId) then
            if player:getStorageValue(PlayerStorageKeys.firstRod) == -1 then
                selfSay('So you ask me for a {' .. ItemType(items[vocationId]):getName() .. '} to begin your adventure?', cid)
                npcHandler.topic[cid] = 1
            else
                selfSay('What? I have already gave you one {' .. ItemType(items[vocationId]):getName() .. '}!', cid)
            end
        else
            selfSay('Sorry, you aren\'t a druid either a sorcerer.', cid)
        end
    elseif msgcontains(msg, 'yes') then
        if npcHandler.topic[cid] == 1 then
            player:addItem(items[vocationId], 1)
            selfSay('Here you are young adept, take care yourself.', cid)
            player:setStorageValue(PlayerStorageKeys.firstRod, 1)
        end
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
        selfSay('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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

function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
local shopWindow = {}
local t = {
          [2195] = {price = 1, price2 = 10}, -- [ITEMID TO SELL] = {Buy cost (0 = not buyable), sell cost (0 = not sellable)}
          [2493] = {price = 1, price2 = 0},
          [2361] = {price = 3, price2 = 0},
          [8851] = {price = 20, price2 = 0},
          [8925] = {price = 30, price2 = 0},
          [2640] = {price = 50, price2 = 0},
          [2494] = {price = 100, price2 = 0},
          [9932] = {price = 50, price2 = 0},
          [2472] = {price = 70, price2 = 0},
          [8931] = {price = 100, price2 = 0}
          }
local TradeItem = 12662
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
    if getPlayerItemCount(cid, TradeItem) < t[item].price*amount then
        selfSay("You don't have enough tokens.", cid)
    else
        doPlayerAddItem(cid, item, amount)
        doPlayerRemoveItem(cid, TradeItem, t[item].price*amount)
        doPlayerSendTextMessage(cid, 20, "You have bought " .. amount .. "x " .. getItemName(item) .. " for " .. t[item].price*amount .. " tokens.")
    end
    return true
end
local onSell = function(cid, item, subType, amount)
    doPlayerRemoveItem(cid, item, amount)
    doPlayerAddItem(cid, TradeItem, t[item].price2*amount)
    doPlayerSendTextMessage(cid, 20, "You have sold " .. amount .. "x " .. getItemName(item) .. " for " .. t[item].price*amount .. " tokens.")
    --selfSay("Here your are!", cid)
    return true
end
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
    for var, ret in pairs(t) do
        table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = ret.price2, name = getItemName(var)})
    end
    openDonateShopWindow(cid, shopWindow, onBuy, onSell) end
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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

function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
local shopWindow = {}
local t = {
          [2195] = {price = 1, price2 = 10}, -- [ITEMID TO SELL] = {Buy cost (0 = not buyable), sell cost (0 = not sellable)}
          [2493] = {price = 1, price2 = 0},
          [2361] = {price = 3, price2 = 0},
          [8851] = {price = 20, price2 = 0},
          [8925] = {price = 30, price2 = 0},
          [2640] = {price = 50, price2 = 0},
          [2494] = {price = 100, price2 = 0},
          [9932] = {price = 50, price2 = 0},
          [2472] = {price = 70, price2 = 0},
          [8931] = {price = 100, price2 = 0}
          }
local TradeItem = 12662
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
    if getPlayerItemCount(cid, TradeItem) < t[item].price*amount then
        selfSay("You don't have enough tokens.", cid)
    else
        doPlayerAddItem(cid, item, amount)
        doPlayerRemoveItem(cid, TradeItem, t[item].price*amount)
        doPlayerSendTextMessage(cid, 20, "You have bought " .. amount .. "x " .. getItemName(item) .. " for " .. t[item].price*amount .. " tokens.")
    end
    return true
end
local onSell = function(cid, item, subType, amount)
    doPlayerRemoveItem(cid, item, amount)
    doPlayerAddItem(cid, TradeItem, t[item].price2*amount)
    doPlayerSendTextMessage(cid, 20, "You have sold " .. amount .. "x " .. getItemName(item) .. " for " .. t[item].price*amount .. " tokens.")
    --selfSay("Here your are!", cid)
    return true
end
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
    for var, ret in pairs(t) do
        table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = ret.price2, name = getItemName(var)})
    end
    openDonateShopWindow(cid, shopWindow, onBuy, onSell) end
    return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Hi bro, the system works but I need it to be for version 7.72 where it does not have the option of sales window, but you must speak specifically what you want. Example: hi buy holy scarab and the npc says will you get 1 holy scarab for 5 token?

I will leave an NPC that does work in this version but does not have the token currency working.

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 voices = { {text = "Runes, wands, rods, health and mana potions! Have a look!"} }
npcHandler:addModule(VoiceModule:new(voices))

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

keywordHandler:addKeyword({'stuff'}, StdModule.say, {npcHandler = npcHandler, text = 'Just ask me for a {trade} to see my offers.'})
keywordHandler:addAliasKeyword({'wares'})
keywordHandler:addAliasKeyword({'offer'})

shopModule:addBuyableItem({'spellbook'}, 2175, 150, 'spellbook')
shopModule:addBuyableItem({'magic lightwand'}, 2162, 400, 'magic lightwand')

shopModule:addBuyableItem({'mana rune'}, 2296, 100, 100, 'mana rune')
shopModule:addBuyableItem({'uh'}, 2273, 100, 100, 'uh')

shopModule:addSellableItem({'wand of vortex', 'vortex'}, 2190, 250, 'wand of vortex')

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)
    local vocationId = player:getVocation():getId()
    local items = {
        [1] = 2190,
        [2] = 2182,
        [5] = 2190,
        [6] = 2182
    }

    if msgcontains(msg, 'primera rod') or msgcontains(msg, 'primera wand') then
        if table.contains({1, 2, 5, 6}, vocationId) then
            if player:getStorageValue(PlayerStorageKeys.firstRod) == -1 then
                selfSay('Entonces me pides un {' .. ItemType(items[vocationId]):getName() .. '} para comenzar tu aventura? (dime "si")', cid)
                npcHandler.topic[cid] = 1
            else
                selfSay('¿Qué? Ya te di uno {' .. ItemType(items[vocationId]):getName() .. '}!', cid)
            end
        else
            selfSay('Lo siento, no eres un druida ni un hechicero.', cid)
        end
    elseif msgcontains(msg, 'si') then
        if npcHandler.topic[cid] == 1 then
            player:addItem(items[vocationId], 1)
            selfSay('Aquí eres joven adepto, cuídate.', cid)
            player:setStorageValue(PlayerStorageKeys.firstRod, 1)
        end
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, 'no') and npcHandler.topic[cid] == 1 then
        selfSay('Ok then.', cid)
        npcHandler.topic[cid] = 0
    end

    return true
end

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

@liqeen @Xikini @Znote please help me bros <3
 
Back
Top