Jump to content

.combinetalismans (High Five)


Recommended Posts

Hello guys. Last night i found some time to spend in Lineage coding. After a while i decided that i would like to share something with you but i didn't know what, so i figured that there is not a .combinetalismans command shared. I know it is not something special, or hard to do, but since it hasn't been shared before, why not? :) It is coded for L2J HighFive but it can easily be adapted for any pack.

 

I will give full guide on how to install it, in order to avoid future posts like "i have this error" or "how do i fix that?" and bla bla.

 

It is very easy to install it. You need to make small changes to core and add a new .java file to your datapack. Read the steps below:

 

1. Head to com.l2jserver.gameserver.model.items.instance.L2ItemInstance and add the following lines anywhere to your code (just not in any other method).

 

 

/**
  * Method used by .combinetalismans.
  * @param value
  */
public void setMana(int value)
{
  _mana = value;
}

 

 

2. Create  CombineTalismans.java file to game\data\scripts\handlers\voicedcommandhandlers and add the following code in it.

 

 

/*
* Copyright © 2004-2017 L2J Server
*
* This file is part of L2J Server.
*
* L2J Server is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* L2J Server is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package handlers.voicedcommandhandlers;

import java.util.ArrayList;
import java.util.List;

import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
import com.l2jserver.gameserver.network.serverpackets.ItemList;

/**
* @author Solomun
* @see www.MaxCheaters.com
*/
public class CombineTalismans implements IVoicedCommandHandler
{
private static final String[] VOICED_COMMANDS =
{
  "combinetalismans"
};

@Override
public boolean useVoicedCommand(String command, L2PcInstance activeChar, String args)
{
  List<int[]> _sameIds = new ArrayList<>();
 
  for (L2ItemInstance item : activeChar.getInventory().getItems())
  {
   // Getting talisman
   if ((item.getMana() > 0) && item.getName().contains("Talisman"))
   {
    addTalisman(_sameIds, item.getId());
   }
  }
  int newCount = 0;
  for (int[] idCount : _sameIds)
  {
   // Item Count > 1
   if (idCount[1] > 1)
   {
    int lifeTime = 0;
    List<L2ItemInstance> existingTalismans = activeChar.getInventory().getItemsByItemId(idCount[0]);
    for (L2ItemInstance existingTalisman : existingTalismans)
    {
     // Take remaining mana of this talisman.
     lifeTime += existingTalisman.getMana();
     // Destroy all talismans from this ID.
     activeChar.getInventory().destroyItem("Combine Talismans", existingTalisman, activeChar, null);
    }
   
    L2ItemInstance newTalisman = activeChar.addItem("Combine talismans", idCount[0], 1, null, false);
    // Add the total mana to the new talisman.
    newTalisman.setMana(lifeTime);
    // store in DB
    newTalisman.updateDatabase();
   
    newCount++;
   }
  }
 
  if (newCount > 0)
  {
   activeChar.sendMessage("You have combined " + newCount + " talismans.");
   activeChar.sendPacket(new ItemList(activeChar, false));
  }
  else
  {
   activeChar.sendMessage("You don't have Talismans to combine!");
  }
  return true;
}

private static void addTalisman(List<int[]> sameIds, int itemId)
{
  for (int i = 0; i < sameIds.size(); i++)
  {
   if (sameIds.get(i)[0] == itemId)
   {
    sameIds.get(i)[1] = sameIds.get(i)[1] + 1;
    return;
   }
  }
  sameIds.add(new int[]
  {
   itemId,
   1
  });
}

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

}

 

 

3.(Final Step) Add the following(yellow) lines to game\data\scripts\handlers\MasterHandler.java

 

 

import handlers.voicedcommandhandlers.StatsVCmd;
import handlers.voicedcommandhandlers.CombineTalismans;
import handlers.voicedcommandhandlers.Wedding;

.

.

.

(Config.L2JMOD_ALLOW_CHANGE_PASSWORD ? ChangePassword.class : null),
   CombineTalismans.class,

 

 

 

If you have any problems involving this to your pack, send me a private message and i will answer it as fast as i can in order to help you.

Edited by Solomun
Link to comment
Share on other sites

Topic updated. I forget to involve the import in MasterHandler.java.

 

import handlers.voicedcommandhandlers.StatsVCmd;
+import handlers.voicedcommandhandlers.CombineTalismans;
import handlers.voicedcommandhandlers.Wedding;

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

×
×
  • Create New...