Jump to content

Question

Posted

Hello! So i adapted devlins code for l2jfrozen 



                if (itemId == 728 || itemId == 1539 || itemId == 5592)
                    {
                        switch (itemId)
                        {
                            case 728: // mana potion
                            {
                                if (activeChar.isAutoPot(728))
                                {
                                    activeChar.sendPacket(new ExAutoSoulShot(728, 0));
                                    activeChar.sendMessage("Deactivated auto mana potions.");
                                    activeChar.setAutoPot(728, null, false);
                                }
                                else
                                {
                                    if (activeChar.getInventory().getItemByItemId(728) != null)
                                    {
                                        if (activeChar.getInventory().getItemByItemId(728).getCount() > 1)
                                        {
                                            activeChar.sendPacket(new ExAutoSoulShot(728, 1));
                                            activeChar.sendMessage("Activated auto mana potions.");
                                            activeChar.setAutoPot(728, ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoPot(728, activeChar), 1000, MANA_POT_CD*1000), true);
                                        }
                                        else
                                        {
                                            MagicSkillUser msu = new MagicSkillUser(activeChar, activeChar, 2279, 2, 0, 100);
                                            activeChar.broadcastPacket(msu);
                                            
                                            Potions is = new Potions();
                                            is.useItem(activeChar, activeChar.getInventory().getItemByItemId(728));
                                        }
                                    }
                                }
                                
                                break;
                            }
                            case 1539: // greater healing potion
                            {
                                if (activeChar.isAutoPot(1539))
                                {
                                    activeChar.sendPacket(new ExAutoSoulShot(1539, 0));
                                    activeChar.sendMessage("Deactivated auto healing potions.");
                                    activeChar.setAutoPot(1539, null, false);
                                }
                                else
                                {
                                    if (activeChar.getInventory().getItemByItemId(1539) != null)
                                    {
                                        if (activeChar.getInventory().getItemByItemId(1539).getCount() > 1)
                                        {
                                            activeChar.sendPacket(new ExAutoSoulShot(1539, 1));
                                            activeChar.sendMessage("Activated auto healing potions.");
                                            activeChar.setAutoPot(1539, ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoPot(1539, activeChar), 1000, HEALING_POT_CD*1000), true);
                                        }
                                        else
                                        {
                                            MagicSkillUser msu = new MagicSkillUser(activeChar, activeChar, 2037, 1, 0, 100);
                                            activeChar.broadcastPacket(msu);
            
                                            Potions is = new Potions();
                                            is.useItem(activeChar, activeChar.getInventory().getItemByItemId(1539));
                                        }
                                    }
                                }
                                
                                break;
                            }
                            case 5592: // greater cp potion
                            {
                                if (activeChar.isAutoPot(5592))
                                {
                                    activeChar.sendPacket(new ExAutoSoulShot(5592, 0));
                                    activeChar.sendMessage("Deactivated auto cp potions.");
                                    activeChar.setAutoPot(5592, null, false);
                                }
                                else
                                {
                                    if (activeChar.getInventory().getItemByItemId(5592) != null)
                                    {
                                        if (activeChar.getInventory().getItemByItemId(5592).getCount() > 1)
                                        {
                                            activeChar.sendPacket(new ExAutoSoulShot(5592, 1));
                                            activeChar.sendMessage("Activated auto cp potions.");
                                            activeChar.setAutoPot(5592, ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoPot(5592, activeChar), 1000, CP_POT_CD*1000), true);
                                        }
                                        else
                                        {
                                            MagicSkillUser msu = new MagicSkillUser(activeChar, activeChar, 2166, 2, 0, 100);
                                            activeChar.broadcastPacket(msu);
                                            
                                            Potions is = new Potions();
                                            is.useItem(activeChar, activeChar.getInventory().getItemByItemId(5592));
                                        }
                                    }
                                }
                                
                                break;
                            }
                        }
                        
                        return;
                    }

part 2 of soulshots.java


    private class AutoPot implements Runnable
        {
            private int id;
            private L2PcInstance activeChar;
            
            public AutoPot(int id, L2PcInstance activeChar)
            {
                this.id = id;
                this.activeChar = activeChar;
            }
            
            @Override
            public void run()
            {
                if (activeChar.getInventory().getItemByItemId(id) == null)
                {
                    activeChar.sendPacket(new ExAutoSoulShot(id, 0));
                    activeChar.setAutoPot(id, null, false);
                    return;
                }
                
                switch (id)
                {
                    case 728:
                    {
                        if (activeChar.getCurrentMp() < 0.70*activeChar.getMaxMp())
                        {
                            MagicSkillUser msu = new MagicSkillUser(activeChar, activeChar, 2279, 2, 0, 100);
                            activeChar.broadcastPacket(msu);
                            
                            Potions is = new Potions();
                            is.useItem(activeChar, activeChar.getInventory().getItemByItemId(728));
                        }
                        
                        break;
                    }
                    case 1539:
                    {
                        if (activeChar.getCurrentHp() < 0.95*activeChar.getMaxHp())
                        {
                            MagicSkillUser msu = new MagicSkillUser(activeChar, activeChar, 2037, 1, 0, 100);
                            activeChar.broadcastPacket(msu);
                            
                            Potions is = new Potions();
                            is.useItem(activeChar, activeChar.getInventory().getItemByItemId(1539));
                        }
                        
                        break;
                    }
                    case 5592:
                    {
                        if (activeChar.getCurrentCp() < 0.95*activeChar.getMaxCp())
                        {
                            MagicSkillUser msu = new MagicSkillUser(activeChar, activeChar, 2166, 2, 0, 100);
                            activeChar.broadcastPacket(msu);
                            
                            Potions is = new Potions();
                            is.useItem(activeChar, activeChar.getInventory().getItemByItemId(5592));
                        }
                        
                        break;
            }
                }
                
                if (activeChar.getInventory().getItemByItemId(id) == null)
                {
                    activeChar.sendPacket(new ExAutoSoulShot(id, 0));
                    activeChar.setAutoPot(id, null, false);
                }
            }
        }

Now L2PcInstance

 

private HashMap<Integer, Future<?>> _autoPotTasks = new HashMap<>();
        
        public boolean isAutoPot(int id)
        {
            return _autoPotTasks.keySet().contains(id);
        }
        
        public void setAutoPot(int id, Future<?> task, boolean add)
        {
            if (add)
                _autoPotTasks.put(id, task);
            else
            {
                _autoPotTasks.get(id).cancel(true);
                _autoPotTasks.remove(id);
            }
        }

and part 2 


    // Add karma to attacker and increase its PK counter
        setPvpKills(getPvpKills() + 1);
                
                if (isAutoPot(728))
                    {
                        sendPacket(new ExAutoSoulShot(728, 0));
                        setAutoPot(728, null, false);
                    }
                    if (isAutoPot(1539))
                    {
                        sendPacket(new ExAutoSoulShot(1539, 0));
                        setAutoPot(1539, null, false);
                    }
                    if (isAutoPot(5592))
                    {
                        sendPacket(new ExAutoSoulShot(5592, 0));
                        setAutoPot(5592, null, false);
                    }

 

i am stuck why it doesnt work?

mana is type shot on skill i removed the isPotion=true.. what i am doing wrong???

it is seems that the threadpooltask never run because i do not even get the message ingame

2 answers to this question

Recommended Posts

  • 0
Posted (edited)

there is a piece in united-extreme forum that says about this

i hope it gives you a clue  cause im not really good at core java design

plus i could find a dirty way to make it work as example of mortal blow playsound i did b4

Inside L2PcInstace.java, you need to specify what the "isAutoPot" value is and of course its default state.

 

private boolean isAutoPot = False;

 

 

yours is 

 public boolean isAutoPot(int id)


i dont get it know this i started to hate java when learning about private and public shits  lol

******


on the other hand

why you cannot just make item mana potion operation type toggle 
and edit the item skill for consume on % mana drop  

 

Edited by etherian
  • 0
Posted

i changed to private and error :) so the problem is it doesnt really do something ingame not even the sendmessages so i assume its something with map/future task / threadpool

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


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