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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Posts

    • Hello, I'm working with custom Icons and noticed that you can use 64x64 icons and the client will handle them without problems in the Inventory and when you Drag them, they look HD so it's really cool, the problem starts when you move them to the shortcut bar, when they're placed there instead of rescaling the icon it just show the upper left corner (so it's 32x32 but showing only the part that fits in that space). I tried checking interface.u but can't find the line where the size for the icons in the shortcut bar are handled.   When in Inventory the item shows in a 32x32 size, if I use a 64x64 icon it re-scales so the icon looks great When dragging the item the image becomes 64x64 which looks pretty big, but it works good When placing the item in the shortcut bar only the top left of the icon is visible   Is there a way I can adjust the shortcut bar so that it re-scales the icon?
    • If you want to edit a large amount of entries in the L2 File-edit I recommend using excel, since both work with columns you can copy the entire file or just a few lines and paste it in excel and it will copy without problems, after you're done with editing you just select the cells and paste them in the .dat file making sure you're formatting correctly. I'm currently doing a massive edit on all gear and that's how i'm handling the .dat work
    • the logic is the "stacking" that is a filter if you use it then the item cannot co-exist (stack)
    • [Exclusive L2Gold Weekend Server] Available ONLY on Saturdays & Sundays – nowhere else, no other time ! Custom Armors (Dynasty, Apella) Custom Weapons (L2Gold Weapons) Custom Jewelry (L2Gold Jewelry) Custom Teleport System Custom AIO Buffer Custom Zones & NPCs Custom Raidboss … and much more waiting for you every weekend! This is not just another private server – it’s a limited-time battleground. When the weekend comes, everyone gathers in one place for the ultimate L2 experience. 👉 Online: Saturday–Sunday only 👉 Contact / Info: [https://www.facebook.com/profile.php?id=61578869175323]
    • ⏳ The price drops like sand slipping down in an hourglass.   📉 USA numbers are already at the lowest 💸 🌍 Next in line: Europe, Asia, and dozens of other countries.     All next week we’ll be actively working on lowering prices. The process has already started  soon costs will be much cheaper. 🔥 Get ready: the price drop will affect every country!   Website link — https://vibe-sms.net/ Our Telegram channel — https://t.me/vibe_sms
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock