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

    • Update M54: Global HP/MP/CP consumable handling expanded beyond combat-only usage. Offensive mage idle recovery with learned skill Battle Heal. Spellhowler/Storm Screamer prioritizes Hurricane, using Vampiric Claw mostly below 90% HP. Major structural refactor initialized: Added category/class organization such as Archer, Dagger, Tank, Mage, Healer, Support and Specialized class files. Further structural cleanup. Extracted combat memory/state and more class-policy logic from the main controller. Added global stuck/inactivity watchdog for bots blocked by terrain/geodata. Added unreachable dropped ground-item timeout/temporary blacklist. Reworked Necromancer/Soultaker PvP: Dominator level 78+ maintains learned Arcane Power toggle on. Overlord/Dominator level 44+ maintains learned Soul Guard toggle automatically. Stability/scalability update: Bot controller ticks staggered instead of all starting in the same phase: Same 350 ms update rate retained Reduces simultaneous AI workload bursts. Removed the old manual aggressive-monster EVT_AGGRESSION bridge. Phantoms now use native Lucera setActive() behavior so monsters aggro them naturally. Reduced unnecessary NPC scans and native AI event pressure. Added saved-bot equipment overrides using a separate database table:         lucera_autobots_items Existing lucera_autobots remains the main saved-bot identity/state table. Equipment rows are linked to saved bots through bot_id. Added optional convenience view to show bot name together with equipment overrides:         lucera_autobots_items_view Added editable equipment slots in columns: Weapon Shield Helmet Chest Legs Gloves Boots Necklace Left/Right Earrings Left/Right Rings Equipment override values: 0 = use normal class/level profile item -1 = force slot empty >0 = equip that Item ID Custom equipment works only for saved database bots. Default class/level equipment profiles remain unchanged. Supports custom equipment from No Grade to S Grade, regardless of the bot's current level. Added validation for invalid item IDs and incompatible equipment slots. Added handling for: Two-handed weapons vs shields Full-body armor vs separate leggings Added all-grade Soulshots and Spiritshots to bot inventory/replenishment so custom lower-grade weapons still use the correct shots. Mage profiles that already use Blessed Spiritshots keep that behavior with all relevant grades available. First save the bot normally so it exists in table:         lucera_autobots Then open:         lucera_autobots_items Find the row with the same bot_id and edit only the equipment slots you want. Example: weapon_id = 6608 shield_id = -1 helmet_id = 0 chest_id = 0 legs_id = 0 gloves_id = 0 boots_id = 0 This means: weapon_id 6608 → custom weapon shield_id -1 → no shield all 0 values → keep normal default profile equipment After editing the DB, despawn and respawn the saved bot so M54 reloads its equipment overrides. Do not edit bot_id. Use it only to identify which saved bot the equipment row belongs to.   DOWNLOAD
    • It will be multi client so it will detect the client from the files and adapt the packets and asset loading. I am aiming for C4 and H5 after IL
    • this is just to simplify your life, time, and can be done for free by yourself just watch some tutorials, in case you don't wanna waste time check it out!   https://l2getwork.art   https://l2getwork.art/showcase.html  
    • Good job! Any chance for it to be downgradeable or at least compatible with older chronicles?
    • Fermata now runs in a web browser too. Try it here: https://web.fermata.gg/    
  • 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..