Hi guys, I'm trying to make a Gift box who give newbies some items but I'm facing a problem.
- It doesn't let me add more than 1 item with chance 100%
- I can only add items like this: Item 1 with 50% and Item 2 with 50% = 100%
- If I try to add 2 items like this: Item 1 with 100% and item 2 with 100% chance it doesn't work.
/*
* L2jFrozen Project - www.l2jfrozen.com
*
* This program 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 2, or (at your option)
* any later version.
*
* This program 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* http://www.gnu.org/copyleft/gpl.html
*/
package com.l2jfrozen.gameserver.handler.itemhandlers;
import org.apache.log4j.Logger;
import com.l2jfrozen.gameserver.cache.HtmCache;
import com.l2jfrozen.gameserver.datatables.csv.ExtractableItemsData;
import com.l2jfrozen.gameserver.datatables.sql.ItemTable;
import com.l2jfrozen.gameserver.handler.IItemHandler;
import com.l2jfrozen.gameserver.model.L2ExtractableItem;
import com.l2jfrozen.gameserver.model.L2ExtractableProductItem;
import com.l2jfrozen.gameserver.model.actor.instance.L2ItemInstance;
import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
import com.l2jfrozen.gameserver.model.actor.instance.L2PlayableInstance;
import com.l2jfrozen.gameserver.network.SystemMessageId;
import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jfrozen.gameserver.network.serverpackets.SystemMessage;
import com.l2jfrozen.util.random.Rnd;
/**
* @author FBIagent 11/12/2006
*/
public class ExtractableItems implements IItemHandler
{
private static Logger LOGGER = Logger.getLogger(ItemTable.class);
public void doExtract(final L2PlayableInstance playable, final L2ItemInstance item, int count)
{
if (!(playable instanceof L2PcInstance))
return;
final L2PcInstance activeChar = (L2PcInstance) playable;
final int itemID = item.getItemId();
if (count > item.getCount())
return;
while (count-- > 0)
{
L2ExtractableItem exitem = ExtractableItemsData.getInstance().getExtractableItem(itemID);
if (exitem == null)
return;
int createItemID = 0, createAmount = 0;
final int rndNum = Rnd.get(100);
int chanceFrom = 0;
for (final L2ExtractableProductItem expi : exitem.getProductItems())
{
final int chance = expi.getChance();
if (rndNum >= chanceFrom && rndNum <= chance + chanceFrom)
{
createItemID = expi.getId();
createAmount = expi.getAmmount();
break;
}
chanceFrom += chance;
}
exitem = null;
if (createItemID == 0)
{
activeChar.sendMessage("Nothing happened.");
return;
}
if (createItemID > 0)
{
if (ItemTable.getInstance().createDummyItem(createItemID) == null)
{
LOGGER.warn("createItemID " + createItemID + " doesn't have template!");
activeChar.sendMessage("Nothing happened.");
return;
}
if (ItemTable.getInstance().createDummyItem(createItemID).isStackable())
{
activeChar.addItem("Extract", createItemID, createAmount, item, false);
}
else
{
for (int i = 0; i < createAmount; i++)
{
activeChar.addItem("Extract", createItemID, 1, item, false);
}
}
SystemMessage sm;
if (createAmount > 1)
{
sm = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
sm.addItemName(createItemID);
sm.addNumber(createAmount);
}
else
{
sm = new SystemMessage(SystemMessageId.EARNED_ITEM);
sm.addItemName(createItemID);
}
activeChar.sendPacket(sm);
sm = null;
}
else
{
activeChar.sendMessage("Item failed to open"); // TODO: Put a more proper message here.
}
activeChar.destroyItemByItemId("Extract", itemID, 1, activeChar.getTarget(), true);
}
}
// by Azagthtot
@Override
public void useItem(final L2PlayableInstance playable, final L2ItemInstance item)
{
if (!(playable instanceof L2PcInstance))
return;
if (item.getCount() > 1)
{
String message = HtmCache.getInstance().getHtm("data/html/others/extractable.htm");
if (message == null)
{
doExtract(playable, item, 1);
}
else
{
message = message.replace("%objectId%", String.valueOf(item.getObjectId()));
message = message.replace("%itemname%", item.getItemName());
message = message.replace("%count%", String.valueOf(item.getCount()));
playable.sendPacket(new NpcHtmlMessage(5, message));
}
}
else
{
doExtract(playable, item, 1);
}
}
@Override
public int[] getItemIds()
{
return ExtractableItemsData.getInstance().itemIDs();
}
}
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.
❖Items that are sent by physical delivery are sent using someone else's data. That is, if you are not able to accept the parcel, we will not be able to return it. Please keep this in mind.
READY IN STOCK
PAYMENT SYSTEMS
4x4 io, Weststein, Paysafecard, Paysend, Genome, Conotoxia, Mybrocard, Payz Silver, Pockit UK, NagaPay, Volet com, SpectroCoin, SwissMoney, Yuh, Lydia / Sumeria, Ka.App, Wittix, Western Union, MyGuava, Xapo Bank, Bunq on emulator (DE, NL, FR, ES, IE ibans), Revolut on emulator (UK/EU), ICard, BlackCatCard, Vivid DE, Bankera, Bitsa, Wise EU/UK, N26 DE/ES on emulator, Skrill, Neteller, Trasta, Wirex, Lama, Paysera, Moneyjar
CRYPTOEXCHANGE
BINGX com, Bybit LVL 2, KuCoin, Binance LVL 2, Mexc, Latoken, Poloniex, Bitmart, Kraken, WhiteBit, Quppy, Nexo, Gate, OKX, Paybis, Paxful, Huobi (HTX), xcoins com, Bit2Me
BUSINESS ACCOUNTS
Stripe, Payoneer EU, Wise Business UK/EU, Revolut Business EU/UK, N26 Business DE, Wallester Business EU, Kraken Business Pro, Monzo Business, Vivid Business, Zen Business EU, Millennium Business PL, AirWallex EU/UK, Finom business, PayPal business, Payset business
NATIONAL BANKS / BANKS
BBVA, CommerzBank, ING, Santander, Kaspi Bank, Sberbank, AlfaBank, Tbank, Raiffeisen, mBank, Paribas, Bereke Bank, Kapital Bank
DISCORD :
utchiha_market
telegram :
https://t.me/utchiha_market
SELLIX STORE :
https://utchihamkt.mysellix.io/
Join our server for more products :
https://discord.gg/hood-services
https://campsite.bio/utchihaamkt
Question
ton3
Hi guys, I'm trying to make a Gift box who give newbies some items but I'm facing a problem.
- It doesn't let me add more than 1 item with chance 100%
- I can only add items like this: Item 1 with 50% and Item 2 with 50% = 100%
- If I try to add 2 items like this: Item 1 with 100% and item 2 with 100% chance it doesn't work.
anyone can help?
Edited by ton31 answer to this question
Recommended Posts
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.