Jump to content
  • 0

Chests


MTJ

Question

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
Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

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.

Link to comment
Share on other sites

  • 0
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 ?

Link to comment
Share on other sites

  • 0

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

Link to comment
Share on other sites

  • 0
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
Link to comment
Share on other sites

  • 0
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

Link to comment
Share on other sites

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

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
Answer this question...

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