Jump to content

Recommended Posts

Posted
Spoiler

 

AutoPotions to l2jsunrice


package handlers.voicedcommandhandlers;

import l2r.gameserver.handler.IItemHandler;
import l2r.gameserver.handler.IVoicedCommandHandler;
import l2r.gameserver.handler.ItemHandler;
import l2r.gameserver.model.actor.instance.L2PcInstance;
import l2r.gameserver.model.items.instance.L2ItemInstance;

import java.util.HashMap;

/**
 * @author root
 * @date: 20/01/2021 at 23:15
 * Description : autocp / automp / autohp item use.
 */
public class AutoPotion implements IVoicedCommandHandler {

    //*******Config Section*****************/
    //    *********************** Potion ItemID
    private static final int ID_HEAL_CP = 5592;
    private static final int ID_HEAL_MP = 728;
    private static final int ID_HEAL_HP = 1539;
    //*********************** USE FULL
    //Enable/Disable voicecoomand
    private static final boolean ACP_ON = true;
    //    Min lvl for use ACP
    private static final int ACP_MIN_LVL = 0;
    private static final int ACP_HP_LVL = 70;
    private static final int ACP_CP_LVL = 70;
    private static final int ACP_MP_LVL = 70;
    private static final int ACP_MILI_SECONDS_FOR_LOOP = 1000;
    //Only for premium user?
    private static final boolean ACP_PREMIUM = false;
    // Automatic regen : Default ACP/MP/HP
    private static final boolean ACP_CP = true;
    private static final boolean ACP_MP = true;
    private static final boolean ACP_HP = true;
    private static final HashMap<String, Thread> userAcpMap = new HashMap<String, Thread>();

    private static String[] _voicedCommands = {
                    "acpon",
                    "acpoff"
    };

    @Override
    public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params) {
        if (activeChar == null) {
            return false;
        }

        if (command.equals("acpon")) {
            if (!ACP_ON) {
                activeChar.sendMessage("The function is disabled on the server!");
                return false;
            } else {
                if (userAcpMap.containsKey(activeChar.toString())) {
                    activeChar.sendMessage("Already included!");
                } else {
                    activeChar.sendMessage("Acp enabled!");
                    Thread t = new Thread(new AcpHealer(activeChar));
                    userAcpMap.put(activeChar.toString(), t);
                    t.start();
                    return true;
                }
            }
        } else if (command.equals("acpoff")) {
            if (!userAcpMap.containsKey(activeChar.toString())) {
                activeChar.sendMessage("Was not included");
            } else {
                userAcpMap.remove(activeChar.toString()) //here we get thread and remove it from map
                        .interrupt(); //and interrupt it
                activeChar.sendMessage("Disabled");
            }
        }
        return false;
    }

    @Override
    public String[] getVoicedCommandList() {
        return _voicedCommands;
    }

    private class AcpHealer implements Runnable {

        L2PcInstance activeChar;

        public AcpHealer(L2PcInstance activeChar) {
            this.activeChar = activeChar;
        }

        @Override
        public void run() {
            try {
                while (true) {
//                  Checking the level
                    if (activeChar.getLevel() >= ACP_MIN_LVL) {
//                        We check if we need a premium
                        if (!(activeChar.isPremium() && ACP_PREMIUM)) {
//                            Checking if we have at least one can of something
                            L2ItemInstance cpBottle = activeChar.getInventory().getItemByItemId(ID_HEAL_CP);
                            L2ItemInstance hpBottle = activeChar.getInventory().getItemByItemId(ID_HEAL_HP);
                            L2ItemInstance mpBottle = activeChar.getInventory().getItemByItemId(ID_HEAL_MP);

                            if (hpBottle != null && hpBottle.getCount() > 0) {
//                               Checking our health
                                if ((activeChar.getStatus().getCurrentHp() / activeChar.getMaxHp()) * 100 < ACP_HP_LVL && ACP_HP) {
                                    IItemHandler handlerHP = ItemHandler.getInstance().getHandler(hpBottle.getEtcItem());
                                    if (handlerHP != null) {
                                        handlerHP.useItem(activeChar, hpBottle, true);
                                        activeChar.sendMessage("ACP: Restored HP");
                                    }
                                }
//                               Checking our CP level
                                if (cpBottle != null && cpBottle.getCount() > 0) {
                                    if ((activeChar.getStatus().getCurrentCp() / activeChar.getMaxCp()) * 100 < ACP_CP_LVL && ACP_CP) {
                                        IItemHandler handlerCP = ItemHandler.getInstance().getHandler(cpBottle.getEtcItem());
                                        if (handlerCP != null) {
                                            handlerCP.useItem(activeChar, cpBottle, true);
                                            activeChar.sendMessage("ACP: Restored CP");
                                        }
                                    }
                                }
//                              Checking our MP level
                                if (mpBottle != null && mpBottle.getCount() > 0) {
                                    if ((activeChar.getStatus().getCurrentMp() / activeChar.getMaxMp()) * 100 < ACP_MP_LVL && ACP_MP) {
                                        IItemHandler handlerMP = ItemHandler.getInstance().getHandler(mpBottle.getEtcItem());
                                        if (handlerMP != null) {
                                            handlerMP.useItem(activeChar, mpBottle, true);
                                            activeChar.sendMessage("ACP: Restored MP");
                                        }
                                    }
                                }
                            } else {
                                activeChar.sendMessage("[ACP] Incorrect item count");
                                return;
                            }
                        } else {
                            activeChar.sendMessage("Available only to premium characters!");
                            return;
                        }
                    } else {
                        activeChar.sendMessage("Available only " + ACP_MIN_LVL + " level!");
                        return;
                    }
                    Thread.sleep(ACP_MILI_SECONDS_FOR_LOOP);
                }
            } catch (InterruptedException e) {
                //nothing
            } catch (Exception e) {
                _log.warn(e.getMessage(), e);
                Thread.currentThread().interrupt();
            } finally {
                userAcpMap.remove(activeChar.toString());
            }
        }
    }
}


 

 

 

  • Thanks 1
  • 1 month later...
Posted (edited)
On 2/8/2021 at 10:11 PM, L2JC-Developer said:
  Hide contents

 

AutoPotions to l2jsunrice





package handlers.voicedcommandhandlers;

import l2r.gameserver.handler.IItemHandler;
import l2r.gameserver.handler.IVoicedCommandHandler;
import l2r.gameserver.handler.ItemHandler;
import l2r.gameserver.model.actor.instance.L2PcInstance;
import l2r.gameserver.model.items.instance.L2ItemInstance;

import java.util.HashMap;

/**
 * @author root
 * @date: 20/01/2021 at 23:15
 * Description : autocp / automp / autohp item use.
 */
public class AutoPotion implements IVoicedCommandHandler {

    //*******Config Section*****************/
    //    *********************** Potion ItemID
    private static final int ID_HEAL_CP = 5592;
    private static final int ID_HEAL_MP = 728;
    private static final int ID_HEAL_HP = 1539;
    //*********************** USE FULL
    //Enable/Disable voicecoomand
    private static final boolean ACP_ON = true;
    //    Min lvl for use ACP
    private static final int ACP_MIN_LVL = 0;
    private static final int ACP_HP_LVL = 70;
    private static final int ACP_CP_LVL = 70;
    private static final int ACP_MP_LVL = 70;
    private static final int ACP_MILI_SECONDS_FOR_LOOP = 1000;
    //Only for premium user?
    private static final boolean ACP_PREMIUM = false;
    // Automatic regen : Default ACP/MP/HP
    private static final boolean ACP_CP = true;
    private static final boolean ACP_MP = true;
    private static final boolean ACP_HP = true;
    private static final HashMap<String, Thread> userAcpMap = new HashMap<String, Thread>();

    private static String[] _voicedCommands = {
                    "acpon",
                    "acpoff"
    };

    @Override
    public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params) {
        if (activeChar == null) {
            return false;
        }

        if (command.equals("acpon")) {
            if (!ACP_ON) {
                activeChar.sendMessage("The function is disabled on the server!");
                return false;
            } else {
                if (userAcpMap.containsKey(activeChar.toString())) {
                    activeChar.sendMessage("Already included!");
                } else {
                    activeChar.sendMessage("Acp enabled!");
                    Thread t = new Thread(new AcpHealer(activeChar));
                    userAcpMap.put(activeChar.toString(), t);
                    t.start();
                    return true;
                }
            }
        } else if (command.equals("acpoff")) {
            if (!userAcpMap.containsKey(activeChar.toString())) {
                activeChar.sendMessage("Was not included");
            } else {
                userAcpMap.remove(activeChar.toString()) //here we get thread and remove it from map
                        .interrupt(); //and interrupt it
                activeChar.sendMessage("Disabled");
            }
        }
        return false;
    }

    @Override
    public String[] getVoicedCommandList() {
        return _voicedCommands;
    }

    private class AcpHealer implements Runnable {

        L2PcInstance activeChar;

        public AcpHealer(L2PcInstance activeChar) {
            this.activeChar = activeChar;
        }

        @Override
        public void run() {
            try {
                while (true) {
//                  Checking the level
                    if (activeChar.getLevel() >= ACP_MIN_LVL) {
//                        We check if we need a premium
                        if (!(activeChar.isPremium() && ACP_PREMIUM)) {
//                            Checking if we have at least one can of something
                            L2ItemInstance cpBottle = activeChar.getInventory().getItemByItemId(ID_HEAL_CP);
                            L2ItemInstance hpBottle = activeChar.getInventory().getItemByItemId(ID_HEAL_HP);
                            L2ItemInstance mpBottle = activeChar.getInventory().getItemByItemId(ID_HEAL_MP);

                            if (hpBottle != null && hpBottle.getCount() > 0) {
//                               Checking our health
                                if ((activeChar.getStatus().getCurrentHp() / activeChar.getMaxHp()) * 100 < ACP_HP_LVL && ACP_HP) {
                                    IItemHandler handlerHP = ItemHandler.getInstance().getHandler(hpBottle.getEtcItem());
                                    if (handlerHP != null) {
                                        handlerHP.useItem(activeChar, hpBottle, true);
                                        activeChar.sendMessage("ACP: Restored HP");
                                    }
                                }
//                               Checking our CP level
                                if (cpBottle != null && cpBottle.getCount() > 0) {
                                    if ((activeChar.getStatus().getCurrentCp() / activeChar.getMaxCp()) * 100 < ACP_CP_LVL && ACP_CP) {
                                        IItemHandler handlerCP = ItemHandler.getInstance().getHandler(cpBottle.getEtcItem());
                                        if (handlerCP != null) {
                                            handlerCP.useItem(activeChar, cpBottle, true);
                                            activeChar.sendMessage("ACP: Restored CP");
                                        }
                                    }
                                }
//                              Checking our MP level
                                if (mpBottle != null && mpBottle.getCount() > 0) {
                                    if ((activeChar.getStatus().getCurrentMp() / activeChar.getMaxMp()) * 100 < ACP_MP_LVL && ACP_MP) {
                                        IItemHandler handlerMP = ItemHandler.getInstance().getHandler(mpBottle.getEtcItem());
                                        if (handlerMP != null) {
                                            handlerMP.useItem(activeChar, mpBottle, true);
                                            activeChar.sendMessage("ACP: Restored MP");
                                        }
                                    }
                                }
                            } else {
                                activeChar.sendMessage("[ACP] Incorrect item count");
                                return;
                            }
                        } else {
                            activeChar.sendMessage("Available only to premium characters!");
                            return;
                        }
                    } else {
                        activeChar.sendMessage("Available only " + ACP_MIN_LVL + " level!");
                        return;
                    }
                    Thread.sleep(ACP_MILI_SECONDS_FOR_LOOP);
                }
            } catch (InterruptedException e) {
                //nothing
            } catch (Exception e) {
                _log.warn(e.getMessage(), e);
                Thread.currentThread().interrupt();
            } finally {
                userAcpMap.remove(activeChar.toString());
            }
        }
    }
}

 

 

 

 

 

 

It has bugs.
 1st of all: thread.sleep is for all potions.
if loop=1000 then your hp pots (which need 15sec) will be like you trying t activated over and over as result if many char uses ".acpon" server will glitch.
And if loop=15000 then this code is useless for cp and mp pots

Edited by Irrelevant
  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • Server owners, Top.MaxCheaters.com is now live and accepting Lineage 2 server listings. There is no voting, no rankings manipulation, and no paid advantages. Visibility is clean and equal, and early listings naturally appear at the top while the platform grows. If your server is active, it should already be listed. Submit here https://Top.MaxCheaters.com This platform is part of the MaxCheaters.com network and is being built as a long-term reference point for the Lineage 2 community. — MaxCheaters.com Team
    • ⚙️ General Changed “No Carrier” title to “Disconnected” to avoid confusion after abnormal DC. On-screen Clan War kill notifications will no longer appear during Sieges, Epics, or Events. Bladedancer or SwordSinger classes can now log in even when Max Clients (2) is reached, you cannot have both at the same time. The max is 3 clients. Duels will now be aborted if a monster aggros players during a duel (retail-like behavior). Players can no longer send party requests to blocked players (retail-like). Fixed Researcher Euclie NPC dialogue HTML error. Changed Clan leave/kick penalty from 12 hours to 3 hours. 🧙 Skills Adjusted Decrease Atk. Spd. & Decrease Speed land rates in Varka & FoG. Fixed augmented weapons not getting cooldown when entering Olympiad. 🎉 Events New Team vs Team map added. New Save the King map added (old TvT map). Mounts disabled during Events. Letter Collector Event enabled Monsters drop letters until Feb. 13th Louie the Cat in Giran until Feb. 16th Inventory slots +10 during event period 📜 Quests Fixed “Possessor of a Precious Soul Part 1” rare stuck issue when exceeding max quest items. Fixed Seven Signs applying Strife buff/debuff every Monday until restart. 🏆 Milestones New milestone: “Defeat 700 Monsters in Varka” 🎁 Rewards: 200 Varka’s Mane + Daily Coin 🌍 NEW EXP Bonus Zones Hot Springs added Varka Silenos added (hidden spots excluded) As always, thank you for your support! L2Elixir keeps evolving, improving, and growing every day 💙   Website: https://l2elixir.org/ Discord: https://discord.gg/5ydPHvhbxs
    • https://sms.pro/ — we are an SMS activation platform  seeking partners  mobile number providers  mobile number owners  owners of GSM modems  SIM card owners We process 1,000,000 activations every day.  寻找合作伙伴  手机号码提供商  手机号码持有者  GSM调制解调器持有者  SIM卡持有者 我们每天处理1,000,000次激活。  Ищем партнеров  Владельцы сим карт  провайдеров  владельцев мобильных номеров  владельцев модемов  Обрабатываем от 1 000 000 активаций в день ⚡️ Fast. Reliable.   https://sms.pro/ Support: https://t.me/alismsorg_bot
    • "WHAT I WILL SEE ON NEW SEASON ? *More easy farm and augment than ever before ! *Free VIP characters for everyone for first 2 days after opening ! Improved olympiad engine to work more correctly. 3 New skins / outfits. Fixed raid boss spawns. Fixed olympiad crit errors. New farming Ivory Tower area. Fixed augmentation rate. Increased all mob drops rate by +20%. And much more..."   1. I have clicked VIP 23.01.2026 20:00 a few second after open server. 2 Days is 48h. Now 24.01.2026 I have 17 hours left, so my VIP will expire 08:00 25.01.2026. Where is 12h? SCAM.   2. Where is ivory tower area?   3. When next wipe?   
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..