Skip to content

AutoPotion for l2jsunrice

Featured Replies

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());
            }
        }
    }
}


 

 

 

  • 1 month later...

Hi, a question, do I have to add all these lines in the direction of the first line ( package handlers.voicedcommandhandlers; ) ?

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...

OK, many thanks for your response.
And would you have the code auto potion functional? use l2jsunrise h5

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.