• TibiaFace

    Tibiaface | Una comunidad Open Tibia donde encontras : mapas, scripts, Otserver, npc y amigos etc ...

    .
    demo menumenu

    Afiliados



    Votar:

    [Ayuda] Npc Venta x cargas

    Compartir:

    Ver el tema anterior Ver el tema siguiente Ir abajo  Mensaje (Página 1 de 1.)

    1default [Ayuda] Npc Venta x cargas Vie Sep 10, 2021 5:58 pm

    Dfsuno

    Dfsuno
    Miembro
    Miembro
    Descripcion escribió:Buena dia comunidad de tibiaface, me podrian ayduar con un npc necesito que venda los item x items no por dinero, y que de 50 cargas de ese item por compra actualmente solo da 1 carga por compra.

    les dejor el script

    Código:
    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 keys = {
            {id = 7869, buy = 500, name = "knight sword training ", actionid = 1443},
            {id = 7880, buy = 200, name = "knight club training ", actionid = 1443},
            {id = 7875, buy = 500, name = "knight axe training ", actionid = 1443},
           {id = 7864, buy = 500, name = "Paladin training ", actionid = 1443},
           {id = 7773, buy = 500, name = "Druid training ", actionid = 1443},
           {id = 7754, buy = 500, name = "Sorcerer training ", actionid = 1443},

        }

        local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
            if doPlayerRemoveMoney(cid, shopWindow[item].Price) then
                local thing = doPlayerAddItem(cid, shopWindow[item].ID, 1)
                doItemSetAttribute(thing, 'aid', shopWindow[item].Actionid)
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have bought a "..shopWindow[item].KeyName.." for "..shopWindow[item].Price.." gold.")
            else
                selfSay("You don't have enough money.", cid)
            end
            return true
        end


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

            if msgcontains(msg, 'trade') then
                for var, item in pairs(keys) do
                    shopWindow[item.id] = {ID = item.id, Price = item.buy, KeyName = item.name, Actionid = item.actionid}
                end
                openShopWindow(cid, keys, onBuy, onSell)
            end
            return true
        end

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


    Gracias por tomarse la molestia quedo en espera Surprised
    Captura del Error escribió:Imagen del error: [Ayuda] Npc Venta x cargas Empty
    El error radica en: Npc

    2 participantes

    2default Re: [Ayuda] Npc Venta x cargas Dom Sep 12, 2021 3:18 pm

    poncex

    poncex
    Miembro
    Miembro
    solo de casualidad, trataste de cambiar esta linea? local thing = doPlayerAddItem(cid, shopWindow[item].ID, 1)

    2 participantes

    3default Re: [Ayuda] Npc Venta x cargas Dom Sep 12, 2021 4:38 pm

    Dfsuno

    Dfsuno
    Miembro
    Miembro
    Me funciono para cambiar las cargas, me podrias ayudar para que enves de dinero me pida un item?

    NPC
    Código:
    <?xml version="1.0" encoding="UTF-8"?>
    <npc name="Training Weapons" script="data/npc/scripts/training.lua" walkinterval="2000" floorchange="0">
        <health now="100" max="100"/>
        <look type="131" head="7" body="87" legs="7" feet="87" addons="2"/>
        <parameters>
            <parameter key="message_greet" value="Hola |PLAYERNAME|! You can buy training weapons, say {trade}!" />
        </parameters>
    </npc>

    NPC/SCRIPS
    Código:
    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 keys = {
             {id = 7869, buy = 500, name = "knight sword training ", actionid = 1443},
             {id = 7880, buy = 200, name = "knight club training ", actionid = 1443},
             {id = 7875, buy = 500, name = "knight axe training ", actionid = 1443},
           {id = 7864, buy = 500, name = "Paladin training ", actionid = 1443},
           {id = 7773, buy = 500, name = "Druid training ", actionid = 1443},
           {id = 7754, buy = 500, name = "Sorcerer training ", actionid = 1443},

        }

        local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
             if doPlayerRemoveMoney(cid, shopWindow[item].Price) then
                 local thing = doPlayerAddItem(cid, shopWindow[item].ID, 60)
                 doItemSetAttribute(thing, 'aid', shopWindow[item].Actionid)
                 doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have bought a "..shopWindow[item].KeyName.." for "..shopWindow[item].Price.." gold.")
             else
                 selfSay("You don't have enough money.", cid)
             end
             return true
        end


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

             if msgcontains(msg, 'trade') then
                 for var, item in pairs(keys) do
                     shopWindow[item.id] = {ID = item.id, Price = item.buy, KeyName = item.name, Actionid = item.actionid}
                 end
                 openShopWindow(cid, keys, onBuy, onSell)
             end
             return true
        end

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

    Esta es la otra parte

    2 participantes

    4default Re: [Ayuda] Npc Venta x cargas Dom Sep 12, 2021 5:10 pm

    poncex

    poncex
    Miembro
    Miembro
    if doPlayerRemoveMoney(cid, shopWindow[item].Price) then (donde dice price intenta cambiarlo por el id de algun item que quieres que te quite)


    if msgcontains(msg, 'trade') then
    for var, item in pairs(keys) do
    shopWindow[item.id] = {ID = item.id, Price = item.buy, KeyName = item.name, Actionid = item.actionid} (aca has lo mismo)

    2 participantes

    5default Re: [Ayuda] Npc Venta x cargas Dom Sep 12, 2021 5:19 pm

    Dfsuno

    Dfsuno
    Miembro
    Miembro
    [Ayuda] Npc Venta x cargas Npc10


    Me dio error en consola y no funciona;S

    2 participantes

    6default Re: [Ayuda] Npc Venta x cargas Dom Sep 12, 2021 5:32 pm

    poncex

    poncex
    Miembro
    Miembro
    Código:
    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 = 'Hum hum, huhum' },
    { text = 'Silly lil\' human' }
    }

    npcHandler:addModule(FocusModule:new())

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

    local player = Player(cid)
    if msgcontains(msg, "blade") then
    npcHandler:say("Do you want to exchange the items? {Yes} or {no}?", cid)
    npcHandler.topic[cid] = 10
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 10 then
    if player:removeItem(25959, 1) then
    player:removeItem(25879, 1)
    player:removeItem(25919, 1)
    npcHandler:say("congratulations, you already have your item destruction", cid)
    player:addItem(30684, 1)
    else
    npcHandler:say("You no have the necessary items.", cid)
    end
    npcHandler.topic[cid] = 0
    end

    if msgcontains(msg, "crossbow") then
    npcHandler:say("Do you want to exchange the items? {Yes} or {no}?", cid)
    npcHandler.topic[cid] = 8
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 8 then
    if player:removeItem(25987, 1) then
    player:removeItem(25886, 1)
    player:removeItem(25947, 1)
    npcHandler:say("congratulations, you already have your item destruction", cid)
    player:addItem(30691, 1)
    else
    npcHandler:say("You no have the necessary items.", cid)
    end
    npcHandler.topic[cid] = 0
    end

    if msgcontains(msg, "bow") then
    npcHandler:say("Do you want to exchange the items? {Yes} or {no}?", cid)
    npcHandler.topic[cid] = 11
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 11 then
    if player:removeItem(25983, 1) then
    player:removeItem(25885, 1)
    player:removeItem(25943, 1)
    npcHandler:say("congratulations, you already have your item destruction", cid)
    player:addItem(30690, 1)
    else
    npcHandler:say("You no have the necessary items.", cid)
    end
    npcHandler.topic[cid] = 0
    end

    if msgcontains(msg, "hammer") then
    npcHandler:say("Do you want to exchange the items? {Yes} or {no}?", cid)
    npcHandler.topic[cid] = 12
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 12 then
    if player:removeItem(25979, 1) then
    player:removeItem(25884, 1)
    player:removeItem(25939, 1)
    npcHandler:say("congratulations, you already have your item destruction", cid)
    player:addItem(30689, 1)
    else
    npcHandler:say("You no have the necessary items.", cid)
    end
    npcHandler.topic[cid] = 0
    end

    if msgcontains(msg, "rod") then
    npcHandler:say("Do you want to exchange the items? {Yes} or {no}?", cid)
    npcHandler.topic[cid] = 13
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 13 then
    if player:removeItem(25995, 1) then
    player:removeItem(25888, 1)
    player:removeItem(25955, 1)
    npcHandler:say("congratulations, you already have your item destruction", cid)
    player:addItem(30693, 1)
    else
    npcHandler:say("You no have the necessary items.", cid)
    end
    npcHandler.topic[cid] = 0
    end

    if msgcontains(msg, "wand") then
    npcHandler:say("Do you want to exchange the items? {Yes} or {no}?", cid)
    npcHandler.topic[cid] = 14
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 14 then
    if player:removeItem(25991, 1) then
    player:removeItem(25887, 1)
    player:removeItem(25951, 1)
    npcHandler:say("congratulations, you already have your item destruction", cid)
    player:addItem(30692, 1)
    else
    npcHandler:say("You no have the necessary items.", cid)
    end
    npcHandler.topic[cid] = 0
    end

    if msgcontains(msg, "slayer") then
    npcHandler:say("Do you want to exchange the items? {Yes} or {no}?", cid)
    npcHandler.topic[cid] = 15
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 15 then
    if player:removeItem(25963, 1) then
    player:removeItem(25880, 1)
    player:removeItem(25923, 1)
    npcHandler:say("congratulations, you already have your item destruction", cid)
    player:addItem(30685, 1)
    else
    npcHandler:say("You no have the necessary items.", cid)
    end
    npcHandler.topic[cid] = 0
    end

    if msgcontains(msg, "chopper") then
    npcHandler:say("Do you want to exchange the items? {Yes} or {no}?", cid)
    npcHandler.topic[cid] = 16
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 16 then
    if player:removeItem(25971, 1) then
    player:removeItem(25882, 1)
    player:removeItem(25931, 1)
    npcHandler:say("congratulations, you already have your item destruction", cid)
    player:addItem(30687, 1)
    else
    npcHandler:say("You no have the necessary items.", cid)
    end
    npcHandler.topic[cid] = 0
    end

    if msgcontains(msg, "mace") then
    npcHandler:say("Do you want to exchange the items? {Yes} or {no}?", cid)
    npcHandler.topic[cid] = 17
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 17 then
    if player:removeItem(25975, 1) then
    player:removeItem(25883, 1)
    player:removeItem(25935, 1)
    npcHandler:say("congratulations, you already have your item destruction", cid)
    player:addItem(30688, 1)
    else
    npcHandler:say("You no have the necessary items.", cid)
    end
    npcHandler.topic[cid] = 0
    end

    if msgcontains(msg, "axe") then
    npcHandler:say("Do you want to exchange the items? {Yes} or {no}?", cid)
    npcHandler.topic[cid] = 9
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 9 then
    if player:removeItem(25967, 1) then
    player:removeItem(25881, 1)
    player:removeItem(25927, 1)
    npcHandler:say("congratulations, you already have your item destruction", cid)
    player:addItem(30686, 1)
    else
    npcHandler:say("You no have the necessary items.", cid)
    end
    npcHandler.topic[cid] = 0

    end
    return true
    end

    keywordHandler:addKeyword({'job'}, StdModule.say, {npcHandler = npcHandler, text = "I am smith."})
    keywordHandler:addKeyword({'smith'}, StdModule.say, {npcHandler = npcHandler, text = "Working steel is my profession."})
    keywordHandler:addKeyword({'steel'}, StdModule.say, {npcHandler = npcHandler, text = "Manny kinds of. Like {Mesh Kaha Rogh'}, {Za'Kalortith}, {Uth'Byth}, {Uth'Morc}, {Uth'Amon}, {Uth'Maer}, {Uth'Doon}, and {Zatragil}."})
    keywordHandler:addKeyword({'zatragil'}, StdModule.say, {npcHandler = npcHandler, text = "Most ancients use dream silver for different stuff. Now ancients most gone. Most not know about."})
    keywordHandler:addKeyword({'uth\'doon'}, StdModule.say, {npcHandler = npcHandler, text = "It's high steel called. Only lil' lil' ones know how make."})
    keywordHandler:addKeyword({'za\'kalortith'}, StdModule.say, {npcHandler = npcHandler, text = "It's evil. Demon iron is. No good cyclops goes where you can find and need evil flame to melt."})
    keywordHandler:addKeyword({'mesh kaha rogh'}, StdModule.say, {npcHandler = npcHandler, text = "Steel that is singing when forged. No one knows where find today."})
    keywordHandler:addKeyword({'uth\'byth'}, StdModule.say, {npcHandler = npcHandler, text = "Not good to make stuff off. Bad steel it is. But eating magic, so useful is."})
    keywordHandler:addKeyword({'uth\'maer'}, StdModule.say, {npcHandler = npcHandler, text = "Brightsteel is. Much art made with it. Sorcerers too lazy and afraid to enchant much."})
    keywordHandler:addKeyword({'uth\'amon'}, StdModule.say, {npcHandler = npcHandler, text = "Heartiron from heart of big old mountain, found very deep. Lil' lil ones fiercely defend. Not wanting to have it used for stuff but holy stuff."})
    keywordHandler:addKeyword({'lil\' lil\''}, StdModule.say, {npcHandler = npcHandler, text = "Lil' lil' ones are so fun. We often chat."})
    keywordHandler:addKeyword({'tibia'}, StdModule.say, {npcHandler = npcHandler, text = "One day I'll go and look."})
    keywordHandler:addKeyword({'teshial'}, StdModule.say, {npcHandler = npcHandler, text = "Is one of elven family or such thing. Me not understand lil' ones and their business."})
    keywordHandler:addKeyword({'cenath'}, StdModule.say, {npcHandler = npcHandler, text = "Is one of elven family or such thing. Me not understand lil' ones and their business."})
    keywordHandler:addKeyword({'name'}, StdModule.say, {npcHandler = npcHandler, text = "I called Bencthyclthrtrprr by me people. Lil' ones me call Big Ben."})
    keywordHandler:addKeyword({'god'}, StdModule.say, {npcHandler = npcHandler, text = "You shut up. Me not want to hear."})
    keywordHandler:addKeyword({'fire sword'}, StdModule.say, {npcHandler = npcHandler, text = "Do lil' one want to trade a fire sword?"})
    keywordHandler:addKeyword({'dragon shield'}, StdModule.say, {npcHandler = npcHandler, text = "Do lil' one want to trade a dragon shield?"})
    keywordHandler:addKeyword({'sword of valor'}, StdModule.say, {npcHandler = npcHandler, text = "Do lil' one want to trade a sword of valor?"})
    keywordHandler:addKeyword({'warlord sword'}, StdModule.say, {npcHandler = npcHandler, text = "Do lil' one want to trade a warlord sword?"})
    keywordHandler:addKeyword({'minotaurs'}, StdModule.say, {npcHandler = npcHandler, text = "They were friend with me parents. Long before elves here, they often made visit. No longer come here."})
    keywordHandler:addKeyword({'elves'}, StdModule.say, {npcHandler = npcHandler, text = "Me not fight them, they not fight me."})
    keywordHandler:addKeyword({'excalibug'}, StdModule.say, {npcHandler = npcHandler, text = "Me wish I could make weapon like it."})
    keywordHandler:addKeyword({'cyclops'}, StdModule.say, {npcHandler = npcHandler, text = "Me people not live here much. Most are far away."})

    npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
    npcHandler:setMessage(MESSAGE_GREET, "Welcome |PLAYERNAME|, I exchange items carving, mayhem and remedy for items destruction to change tell me {blade}, {crossbow}, {bow}, {hammer}, {rod}, {wand}, {slayer}, {chopper}, {mace} or {axe}.")
    npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye lil' one.")
    npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye lil' one.")
    npcHandler:addModule(FocusModule:new())


    donde dice player:removeItem colocas la id del item que quieres que te quite (en este caso el doll)

    y en player:addItem el id del item que quieres que te de, cabe destacar que el 1 que sale al lado de la id es la cantidad de items que te quitara o te dara, ej la id del doll, 5 (al colocar 5 te deberia quitar 5 dolls)

    2 participantes

    7default Re: [Ayuda] Npc Venta x cargas Lun Sep 13, 2021 1:53 am

    Dfsuno

    Dfsuno
    Miembro
    Miembro
    Código:
    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 msg = string.lower(msg)
    local moeda = 9020 ----id del item que pedirá
    local t = {
      ["knight sword training "] = {1, 7869, 1443}, -- ["nombre del item, con minuscula] = {precio, iid del item que venderá}
      ["knight club training "] = {1, 7880, 1443},
      ["knight axe training "] = {1, 7875, 1443},
      ["paladin training"] = {1, 7864, 1443},
      ["druid training"] = {1, 7773, 1443},
      ["sorcerer training"] = {1, 7754, 1443}
      }

    if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
    local str = ""
    str = str .. "I sell training weapons: "
    for name, pos in pairs(t) do
    str = str.." {"..name.."} = "..pos[1].." training coins /"
    end
    str = str .. "."
    npcHandler:say(str, cid)
    elseif t[msg] then
     if doPlayerRemoveItem(cid,moeda,t[msg][1]) then
     local thing = doPlayerAddItem(cid,t[msg][2],70)
     doItemSetAttribute(thing, 'aid', t[msg][3])
     npcHandler:say("I give him his".. getItemNameById(t[msg][2]) .."!", cid)
     else
     npcHandler:say("you do not have"..t[msg][1].." ".. getItemNameById(moeda), cid)
     end
    end
    return TRUE
    end
        npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
        npcHandler:addModule(FocusModule:new())

    Very Happy Resuelto Gracias Very Happy

    2 participantes

    Contenido patrocinado


    2 participantes

    Ver el tema anterior Ver el tema siguiente Volver arriba  Mensaje (Página 1 de 1.)

    Permisos de este foro:
    No puedes responder a temas en este foro.

     

    BienvenidosTibiaFace es una comunidad de Open Tibia. Para participar debes estar registrado (click para Regístrate).