Jump to content

Question

Posted (edited)

Hi,

 

I want to make a chest "item"

 

that gives many things like EWS with chance to get (15%), EAS with chance to get (30%)

 

i need it really soon is there any code shared for it ?

 

i tried to find an item that has the same idea, i found "Great adventurer's treasure sack" so i copy the code and do the same

 

but this is the only thing i found, what means i couldn't find the drop of the item

 

image.png.c71bdd3f3d929f90b368f8e8615d2861.png

 

 

 

btw i'm using l2 ro team fandc

 

 

 

Edited by NaughtyGlad

6 answers to this question

Recommended Posts

  • 0
Posted

Did you try to open this sack in game? It might be one of the items that does not have any extractable items. You can copy the code from any other package-sack that actually gives you some items.

or

You could add your custom item handler to your item (something i like to do).

Take a look at this example (l2jServer high five):

 

Quote

<item id="21888" type="EtcItem" name="Attribute Crystal Box">
        <set name="icon" val="BranchSys.icon.br_lucky_bag_box_i00" />
        <set name="material" val="PAPER" />
        <set name="is_stackable" val="true" />
        <set name="handler" val="AttributeCrystalBox" />
    </item>

 

now in data\scripts\handlers\itemhandlers\AttributeCrystalBox.java:


 

Quote

 

public class AttributeCrystalBox implements IItemHandler
{
    private static final int[] CRYSTALS =
    { 

         9552,9553,9554,9555,9556,9557

    };
    
    @Override
    public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
    {
        if (item == null)
        {
            return false;
        }
        if (item.getId() != 21888) // Attribute crystal box id
        {
            return false;
        }
        L2PcInstance player = playable.getActingPlayer();
        if (player == null)
        {
            return false;
        }
        int cry = CRYSTALS[Rnd.get(CRYSTALS.length)]; //Pick a random cry, with same chance
        player.destroyItem("Attribute Box", item, 1, player, true);
        player.addItem("Attribute box", cry, 1, null, true);
        return true;
    }
}

 

 

 

In my example, all items have the same chance. You could make your own play with them, as you like.

  • 0
Posted
22 minutes ago, Solomun said:

Did you try to open this sack in game? It might be one of the items that does not have any extractable items. You can copy the code from any other package-sack that actually gives you some items.

or

You could add your custom item handler to your item (something i like to do).

Take a look at this example (l2jServer high five):

 

 

now in data\scripts\handlers\itemhandlers\AttributeCrystalBox.java:


 

 

 

In my example, all items have the same chance. You could make your own play with them, as you like.

Hi mister,

 

look what i did

 

<etcitem id="94322" name="Golden Chest">

    <set name="class" value="EXTRACTABLE"/>

    <set name="crystal_type" value="NONE"/>

    <set name="icon" value="icon.etc_treasure_sack_1_i00"/>

    <set name="stackable" value="true"/>

    <set name="type" value="OTHER"/>

    <capsuled_items>

      <capsuled_item id="6577" min_count="1" max_count="2" chance="15.0"/>

      <capsuled_item id="6578" min_count="5" max_count="5" chance="15.0"/>

      <capsuled_item id="14052" min_count="300" max_count="500" chance="15.0"/>

      <capsuled_item id="57" min_count="50000000" max_count="50000000" chance="100.0"/>

    </capsuled_items>

  </etcitem>

</list>
 

but i want to know how can i make a group of items

 

for example i want to put soul crystal 16 ( red blue green )

 

i want to put their chance 3% and get random one of them

 

how can i do that ?

  • 0
Posted

the structure of it does not allow you to do the thing you want. either you need custom code for the specific item or edit the way of parsing these type of boxes

  • 0
Posted (edited)
56 minutes ago, NaughtyGlad said:

Hi mister,

 

look what i did

 

<etcitem id="94322" name="Golden Chest">

    <set name="class" value="EXTRACTABLE"/>

    <set name="crystal_type" value="NONE"/>

    <set name="icon" value="icon.etc_treasure_sack_1_i00"/>

    <set name="stackable" value="true"/>

    <set name="type" value="OTHER"/>

    <capsuled_items>

      <capsuled_item id="6577" min_count="1" max_count="2" chance="15.0"/>

      <capsuled_item id="6578" min_count="5" max_count="5" chance="15.0"/>

      <capsuled_item id="14052" min_count="300" max_count="500" chance="15.0"/>

      <capsuled_item id="57" min_count="50000000" max_count="50000000" chance="100.0"/>

    </capsuled_items>

  </etcitem>

</list>
 

but i want to know how can i make a group of items

 

for example i want to put soul crystal 16 ( red blue green )

 

i want to put their chance 3% and get random one of them

 

how can i do that ?

 

Despite @melron's answer.

 

As far as i remember, this cannot be done they way you are trying do (even if it is a great approach).

 

So, you can go my way, with a custom item handler for each item (will be a pain in the ass if you want to use it for many items, but easy for 1-2 items so can play around with a lot of stuff).

 

Finally, the way i see things now, in order to make it generic and make it work for a lot of items, you would typically need:

-1 new object or edit L2ExtractableProduct and add it a kind of field "groupId", which will support the group.

-Then make the parser, parse the groups (in case of edit L2ExtractableProduct, you have to make it accept 4 arguments, in order not to screw the already existing capsuled items)

-A new handler for these items in order to group the items. (I would leave "ExtractableItems" handler as it is)

 

 

Since i gave you the example, i will give you an example how to make groups in the handler.

 

Check this SSCCE:

package test;

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

public class Maxcheaters {
    // @formatter:off
    private static final double[]GROUPS = {
            100, //Group 0, 100% chance
            50, //Group 1, 50% chance
            3.1, //Group 2, 3.1% chance
    };
    private static final Item[] ITEMS = {
            //Group 0: Adena or Ancient adena
            new Item(57, 100,120, 0), //Adena,  100-120 count, group 0
            new Item(5575,100,100,0), //Ancient adena, 100 count, group 0
            //Group 1: Knights Epaulette
            new Item(9912,500,1000,1), //Knight epaulette, 100% chance, 500-1k count, group 1
            new Item(9912,50011,100110,1), //Knight epaulette, 100% chance, 500-1k count, group 1
            //Group 2: Attribute crystals (9552,9553,9554,9555,9556,9557 )
            new Item(9552,1,1,2), //Holy Crystal,  1 count, group 2
            new Item(9553,1,1,2), //Dark Crystal,  1 count, group 2
            new Item(9554,1,1,2), //Wind Crystal,  1 count, group 2
     };
    private static Random random = new Random();
    // @formatter:on
    public static void main(String[] args) {
        for (int groupId = 0; groupId < GROUPS.length; groupId++) {
            double groupChance = GROUPS[groupId];
            double random = randomDouble();
            if (random >= groupChance) //Group did not succeed
                continue;
            List<Item> itemsInThisGroup = new ArrayList<>();
            for (Item i : ITEMS) {
                if (i.groupId == groupId)
                    itemsInThisGroup.add(i);
            }
            int randomItem = randomInt(0, itemsInThisGroup.size() - 1);
            Item item = itemsInThisGroup.get(randomItem);
            int count = randomInt(item.minCount, item.maxCount);
            System.out.println("ID=" + item.id + " - Count=" + count + " - Group=" + item.groupId);
        }

    }

    private static double randomDouble() {
        return Math.random() * 100;
    }

    private static int randomInt(int min, int max) {
        return random.nextInt(max + 1 - min) + min;
    }

    private static class Item {
        private int id;
        private int minCount;
        private int maxCount;
        private int groupId;

        public Item(int id, int minCount, int maxCount, int groupId) {
            super();
            this.id = id;
            this.minCount = minCount;
            this.maxCount = maxCount;
            this.groupId = groupId;
        }

    }
}

 

You can run it, and you will see that it does what you want.

 

Let's see it on handler though.

public class AttributeCrystalBox implements IItemHandler
{
    // @formatter:off
    private static final double[]GROUPS = {
            100, //Group 0, 100% chance
            50, //Group 1, 50% chance
            93.1, //Group 2, 3.1% chance
    };
    private static final Item[] ITEMS = {
            //Group 0: Adena or Ancient adena
            new Item(57, 100,120, 0), //Adena, 80% chance, 100-120 count, group 1
            new Item(5575,100,100,0), //Ancient adena, 50%chance, 100 count, group 1
            //Group 1: Knights Epaulette
            new Item(9912,500,1000,1), //Knight epaulette, 100% chance, 500-1k count, group 2
            new Item(9912,50011,100110,1), //Knight epaulette, 100% chance, 500-1k count, group 2
            //Group 2: Attribute crystals (9552,9553,9554,9555,9556,9557 )
            new Item(9552,1,1,2), //Holy Crystal, 3%chance, 1 count, group 3
            new Item(9553,1,1,2), //Dark Crystal, 3%chance, 1 count, group 3
            new Item(9554,1,1,2), //Wind Crystal, 3%chance, 1 count, group 3
     };
    
    @Override
    public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
    {
        if (item == null)
        {
            return false;
        }
        if (item.getId() != 21888) // Attribute crystal box id
        {
            return false;
        }
        L2PcInstance player = playable.getActingPlayer();
        if (player == null)
        {
            return false;
        }
        giveItems();
        player.destroyItem("Attribute Box", item, 1, player, true);
        return true;
    }
    private void giveItems(L2PcInstance player)
    {
        for (int groupId = 0; groupId < GROUPS.length; groupId++) {
            double groupChance = GROUPS[groupId];
            double random = randomDouble();
            if (random >= groupChance) //Group did not succeed
                continue;
            List<Item> itemsInThisGroup = new ArrayList<>();
            for (Item i : ITEMS) {
                if (i.groupId == groupId)
                    itemsInThisGroup.add(i);
            }
            int randomItem = randomInt(0, itemsInThisGroup.size() - 1);
            Item item = itemsInThisGroup.get(randomItem);
            int count = randomInt(item.minCount, item.maxCount);
            player.addItem("Attribute box", item.id, count, null, true);
        }
    }
    /* Replace these with Rnd.get() */
    private static double randomDouble() {
        return Math.random() * 100;
    }

    private static int randomInt(int min, int max) {
        return random.nextInt(max + 1 - min) + min;
    }
    private static class Item {
        private int id;
        private int minCount;
        private int maxCount;
        private int groupId;

        public Item(int id, int minCount, int maxCount, int groupId) {
            super();
            this.id = id;
            this.minCount = minCount;
            this.maxCount = maxCount;
            this.groupId = groupId;
        }

    }
}

 

So now you are able to add whatever you want.

 

P.S: Please ignore any syntax errors, everything made in notepad :P

 

 

Edited by Solomun
  • 0
Posted
8 hours ago, Solomun said:

 

Despite @melron's answer.

 

As far as i remember, this cannot be done they way you are trying do (even if it is a great approach).

 

So, you can go my way, with a custom item handler for each item (will be a pain in the ass if you want to use it for many items, but easy for 1-2 items so can play around with a lot of stuff).

 

Finally, the way i see things now, in order to make it generic and make it work for a lot of items, you would typically need:

-1 new object or edit L2ExtractableProduct and add it a kind of field "groupId", which will support the group.

-Then make the parser, parse the groups (in case of edit L2ExtractableProduct, you have to make it accept 4 arguments, in order not to screw the already existing capsuled items)

-A new handler for these items in order to group the items. (I would leave "ExtractableItems" handler as it is)

 

 

Since i gave you the example, i will give you an example how to make groups in the handler.

 

Check this SSCCE:


package test;

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

public class Maxcheaters {
    // @formatter:off
    private static final double[]GROUPS = {
            100, //Group 0, 100% chance
            50, //Group 1, 50% chance
            3.1, //Group 2, 3.1% chance
    };
    private static final Item[] ITEMS = {
            //Group 0: Adena or Ancient adena
            new Item(57, 100,120, 0), //Adena,  100-120 count, group 0
            new Item(5575,100,100,0), //Ancient adena, 100 count, group 0
            //Group 1: Knights Epaulette
            new Item(9912,500,1000,1), //Knight epaulette, 100% chance, 500-1k count, group 1
            new Item(9912,50011,100110,1), //Knight epaulette, 100% chance, 500-1k count, group 1
            //Group 2: Attribute crystals (9552,9553,9554,9555,9556,9557 )
            new Item(9552,1,1,2), //Holy Crystal,  1 count, group 2
            new Item(9553,1,1,2), //Dark Crystal,  1 count, group 2
            new Item(9554,1,1,2), //Wind Crystal,  1 count, group 2
     };
    private static Random random = new Random();
    // @formatter:on
    public static void main(String[] args) {
        for (int groupId = 0; groupId < GROUPS.length; groupId++) {
            double groupChance = GROUPS[groupId];
            double random = randomDouble();
            if (random >= groupChance) //Group did not succeed
                continue;
            List<Item> itemsInThisGroup = new ArrayList<>();
            for (Item i : ITEMS) {
                if (i.groupId == groupId)
                    itemsInThisGroup.add(i);
            }
            int randomItem = randomInt(0, itemsInThisGroup.size() - 1);
            Item item = itemsInThisGroup.get(randomItem);
            int count = randomInt(item.minCount, item.maxCount);
            System.out.println("ID=" + item.id + " - Count=" + count + " - Group=" + item.groupId);
        }

    }

    private static double randomDouble() {
        return Math.random() * 100;
    }

    private static int randomInt(int min, int max) {
        return random.nextInt(max + 1 - min) + min;
    }

    private static class Item {
        private int id;
        private int minCount;
        private int maxCount;
        private int groupId;

        public Item(int id, int minCount, int maxCount, int groupId) {
            super();
            this.id = id;
            this.minCount = minCount;
            this.maxCount = maxCount;
            this.groupId = groupId;
        }

    }
}

 

You can run it, and you will see that it does what you want.

 

Let's see it on handler though.


public class AttributeCrystalBox implements IItemHandler
{
    // @formatter:off
    private static final double[]GROUPS = {
            100, //Group 0, 100% chance
            50, //Group 1, 50% chance
            93.1, //Group 2, 3.1% chance
    };
    private static final Item[] ITEMS = {
            //Group 0: Adena or Ancient adena
            new Item(57, 100,120, 0), //Adena, 80% chance, 100-120 count, group 1
            new Item(5575,100,100,0), //Ancient adena, 50%chance, 100 count, group 1
            //Group 1: Knights Epaulette
            new Item(9912,500,1000,1), //Knight epaulette, 100% chance, 500-1k count, group 2
            new Item(9912,50011,100110,1), //Knight epaulette, 100% chance, 500-1k count, group 2
            //Group 2: Attribute crystals (9552,9553,9554,9555,9556,9557 )
            new Item(9552,1,1,2), //Holy Crystal, 3%chance, 1 count, group 3
            new Item(9553,1,1,2), //Dark Crystal, 3%chance, 1 count, group 3
            new Item(9554,1,1,2), //Wind Crystal, 3%chance, 1 count, group 3
     };
    
    @Override
    public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
    {
        if (item == null)
        {
            return false;
        }
        if (item.getId() != 21888) // Attribute crystal box id
        {
            return false;
        }
        L2PcInstance player = playable.getActingPlayer();
        if (player == null)
        {
            return false;
        }
        giveItems();
        player.destroyItem("Attribute Box", item, 1, player, true);
        return true;
    }
    private void giveItems(L2PcInstance player)
    {
        for (int groupId = 0; groupId < GROUPS.length; groupId++) {
            double groupChance = GROUPS[groupId];
            double random = randomDouble();
            if (random >= groupChance) //Group did not succeed
                continue;
            List<Item> itemsInThisGroup = new ArrayList<>();
            for (Item i : ITEMS) {
                if (i.groupId == groupId)
                    itemsInThisGroup.add(i);
            }
            int randomItem = randomInt(0, itemsInThisGroup.size() - 1);
            Item item = itemsInThisGroup.get(randomItem);
            int count = randomInt(item.minCount, item.maxCount);
            player.addItem("Attribute box", item.id, count, null, true);
        }
    }
    /* Replace these with Rnd.get() */
    private static double randomDouble() {
        return Math.random() * 100;
    }

    private static int randomInt(int min, int max) {
        return random.nextInt(max + 1 - min) + min;
    }
    private static class Item {
        private int id;
        private int minCount;
        private int maxCount;
        private int groupId;

        public Item(int id, int minCount, int maxCount, int groupId) {
            super();
            this.id = id;
            this.minCount = minCount;
            this.maxCount = maxCount;
            this.groupId = groupId;
        }

    }
}

 

So now you are able to add whatever you want.

 

P.S: Please ignore any syntax errors, everything made in notepad :P

 

 

Hi,

 

tbh, i didn't start to do it like you did. i want to test something so i did it the same way i did at first time

so look what i did >

 

image.thumb.png.34632a4a4bf958d099f2e8610666b7ed.png

 

when i create the item it works well but i can't open it, like if i click million of times nothing happens

  • 0
Posted
27 minutes ago, NaughtyGlad said:

Hi,

 

tbh, i didn't start to do it like you did. i want to test something so i did it the same way i did at first time

so look what i did >

 

 

when i create the item it works well but i can't open it, like if i click million of times nothing happens

 

Check the console for any errors. The attribute "chance" might be incorrect value.

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


  • Posts

    • Need Discord with rare badge? VISIT US AND SHOP WITH US! NEW STOCK Aged, Early Supporter Discord Accounts I sell HQ Aged and Early, Discord Accounts that are inactive and not flagged by discord at cheap prices If you want to contact me, you can add me on discord: worldcoldwar Features: Format - age : email : pass : token Not flagged and undetected by discord HQ % With OGE Emails, password etc can be changed Unverified Early Supporter 24M Boost Badge HypeSquad Events Early Verified Bot Developer Early Supporters SHOP LINK: disvault1.mypaylix.gg/ For PayPal payments, please open a ticket. If you experience any problems with cryptocurrency payments, please open a ticket as well.
    • Tired of frantically switching between windows trying to find that specific Warlock who should be casting saves? Forgot which server you left your Warsmith on? This mod solves these problems! What it does: Turns the boring window title into an information panel: Server Name - Character Name [Class] Real-life examples: - ServerName - HardcoreFarm [Spoilerr] (who's been spoiling for 3 months already) - ServerName - ClericHelper [Buffer] (eternal buffer on standby) - ServerName - MainChar [Gladiator] (main character who's always AFK) Why you need this: For multiboxers - to avoid confusing where the DD is and where the healer is For the forgetful - if your memory is like a goldfish For streamers - viewers immediately see who's on screen For adults - when playing at work and need to quickly hide the window DLL only - no Interface files needed Installation (more complicated than making tea): 1. Download the DLL 2. Drop it into the System folder 3. Launch the client 4. Be amazed how you lived without this before!   Purchase Conditions: Price: 100$ Payment Method: USDT. How to Buy: Contact me on Telegram: @kiselevwv for a quick response. I will answer all your questions and provide additional information if needed. I guarantee functionality at the moment of sale and prompt assistance with setup after purchase.    
    • Hello Everyone   Wts adena  L2 REBORN C5 FRANZ x1 50kk stock 😉   Contact Discord :  topseller4081  
    • tratando de crear un GvE tengo problemas con el scripts como no se mucho de esto me estoy ayudando con IA pero no puedo salir de este bache      [06:19:43]  WARN Quest GvE_AI not found! [06:19:45]  WARN Quest GvE_AI not found! [06:19:50]  WARN Quest GvE_AI not found! [06:25:51]  WARN Quest GvE_AI not found!
    • ## [1.5.5] - 2026-02-02   ### ✨ New Features - **Discord Login**: You can now sign in with your Discord account. Admins enable and configure Discord login in **cpadmin → Users** (Discord auth settings: Client ID, Client Secret, Redirect URI). If you already have an account with the same email (e.g. forum, Google, or legacy), signing in with Discord links to that account so you keep one profile. Discord login is available on Add Server, My Servers, Vote page, and Premium Ads booking. - **Setup Links**: In **cpadmin → Users**, both Google and Discord login settings now include direct links to their official developer portals (Google Cloud Console and Discord Developer Portal) for easier OAuth app setup.   ### 🔒 Security - **Email Required for Registration**: New user registration via OAuth (Forum, Google, Discord) now requires a valid email address. If the OAuth provider doesn't provide an email (e.g. unverified Discord email), registration is rejected with a clear message. This prevents anonymous accounts and ensures all users can receive important notifications.   ### 🔄 Improvements - **User Auth Badges**: In **cpadmin → Users**, the Registered Members table now shows auth method badges: **Forum**, **Google**, **Discord**, or **Legacy**. Users can have multiple badges if they've linked multiple login methods. - **Server Info Labels**: Translated server info labels (Owner Name, Language, Server Location) are now properly localized in all 5 languages (English, Spanish, Portuguese, Greek, Russian).   ---   ## [1.5.4] - 2026-02-01   ### ✨ New Features - **Google Login**: You can now sign in with your Google account. Admins enable and configure Google login in **cpadmin → Users** (Google auth settings: Client ID, Client Secret, Redirect URI). If you already have an account with the same email (e.g. forum or legacy), signing in with Google links to that account so you keep one profile. The login menu (navbar and login prompts) offers **Login with Forum Account**, **Login with Google** (when enabled), and **Create Forum Account**. Google login is available on Add Server, My Servers, Profile Settings, Vote page, and Premium Ads booking. - **Ban/Unban Members**: In **cpadmin → Users**, admins can ban or unban registered members. Banned users see a full-page message: "Sorry, you are banned from using this site." When a user is banned, all their servers are set to inactive. - **Moderator Activity Log**: **cpadmin → Moderators** now records when a moderator or admin enters the CPAdmin panel (e.g. "Moderator X entered CPAdmin panel at &lt;time&gt;") and when they change any cpadmin settings (only write actions are logged; read-only use is not). - **Clear Moderator Logs**: Admins can clear all moderator activity log entries via a **Clear logs** button with confirmation. Logs are shown at 100 per page with pagination. - **Filter by Moderator**: In the Moderator Activity Log, a **Filter by moderator** dropdown lets you view activity for a specific moderator or "All moderators." - **cpadmin → Users Tab**: New **Users** tab in the admin panel with Registered Members list (paginated), Google auth settings card, and per-user Ban/Unban and server links.   ### 🔄 Improvements - **cpadmin → Servers**: Each server name in the servers table is now clickable and opens that server’s info page. - **cpadmin → Users – Servers column**: The servers count/list is clickable and opens a small modal listing that user’s servers; each server name in the modal links to the server info page. - **cpadmin → Users – Search**: A search bar above the Registered Members table lets you search by **username**, **email**, or **server name**. Results are filtered on the server (paginated); clearing the search resets the list. - **Moderator Activity Log**: Pagination shows "Showing X–Y of Z" and "Page N of M" with Previous/Next when there are more than 100 entries. - **Login UI**: Login options (Forum, Google, Create account) are shown in a consistent dropdown and in modals (Add Server, My Servers, Vote, Premium Ads) for a clearer sign-in experience. - **Vote Page – Unauthenticated**: When you must log in to vote, the page now shows "Vote for [Server Name]" as the main heading and presents login options in a compact section.   ---   ## [1.5.3] - 2026-01-30   ### ✨ New Features - **File Logs in Admin Panel**: Admins can now view CodeIgniter PHP logs (api/writable/logs) directly in **cpadmin → Logs**. Select a date to view the log file, refresh to reload, or delete all log files to free up space.   ### 🔄 Improvements - **Cache System**: Full cache audit and improvements — when you clear cache in cpadmin, both backend and frontend caches are cleared. Server listings, My Servers, pricing, ad config, and chronicles all refresh with fresh data. New paid servers now appear in listings and My Servers immediately. - **Admin Panel – Server Rates**: Server rates in the admin servers table now display in compact format (e.g. x10000 → x10k, x100000 → x100k, x1000000 → x1m) for easier scanning. Hover to see the full value.
  • Topics

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