U3Games

Games | Desarrollo & Soporte => L2 | Implementaciones => L2 | Sección de Servidores => Lineage => L2 | Codes => Mensaje iniciado por: Swarlog en Jun 25, 2025, 09:28 PM

Título: Entregar objeto si no lo tienes
Publicado por: Swarlog en Jun 25, 2025, 09:28 PM
Lo que hace este script es que cuando le das a la opcion de "buy_item" en su html, si no tienes el objeto "CUSTOM_ITEM" puedes comprarlo y/u obtenerlo, pero si lo tienes no.

Añadi este script por que me lo pidieron por privado ;)

     
    import com.l2jserver.gameserver.model.actor.L2Npc;
    import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
    import com.l2jserver.gameserver.model.event.LongTimeEvent;
    import com.l2jserver.gameserver.model.itemcontainer.Inventory;
    import com.l2jserver.gameserver.model.quest.QuestState;
     
    public final class CustomItemSeller extends LongTimeEvent
    {
        // NPC
        private static final int NPC_SELLER = 32599;
        // Items
        private static final int CUSTOM_ITEM = 13539;
        private static final int ITEM_PRICE = 13539;
       
        private CustomItemSeller()
        {
            super(CustomItemSeller.class.getSimpleName(), "events");
            addStartNpc(NPC_SELLER);
            addFirstTalkId(NPC_SELLER);
            addTalkId(NPC_SELLER);
        }
       
        @Override
        public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
        {
            String htmltext = event;
            QuestState st = player.getQuestState(getName());
            if (event.equalsIgnoreCase("buy_item"))
            {
                if (!st.hasQuestItems(CUSTOM_ITEM) && (st.getQuestItemsCount(Inventory.ADENA_ID) > ITEM_PRICE))
                {
                    st.takeItems(Inventory.ADENA_ID, ITEM_PRICE);
                    st.giveItems(CUSTOM_ITEM, 1);
                }
                else
                {
                    htmltext = "<html><head></head><body>You already have item</body></html>";
                }
            }
            return htmltext;
        }
       
        @Override
        public String onFirstTalk(L2Npc npc, L2PcInstance player)
        {
            return "<html><body>Seller:"
                + "<a action=\"bypass -h Quest CustomItemSeller buy_item\">Take the item for" + ITEM_PRICE + "price</a><br"
                    + "<br></body></html>";
        }
       
        public static void main(String[] args)
        {
            new CustomItemSeller();
        }
    }
     

By Zealar