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.

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.

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.

  • Posts

    • Server mid rate craft PvP   CLIENTE INTERLUDE Website server Discord olympus x25 &nbsp;server 🇧🇷🇦🇷🇨🇱🇬🇷🇲🇽🇵🇪🇸🇰🇪🇸🇺🇾 Server mid rate craft PvP 🔱CLIENTE INTERLUDE🔱 🔅xpx25 🔅Sp x25 🔅Adena x15 🔅Droop x2 🔅Spoil x2 🔅Raidboss xp x2 🔅Raidboss sp x2 🔅Raidboss droop x1 🔅All Rate quest reward  x1 ⚠️All Quest drop reward. x1 🔅Manor x 3 🔅Seal stone x1 🛡️🗡️INFO GRADO S🗡️🛡️ ⚠️Inicia desabilitado drop/spoil/quest. 🔱PROFESIONES/SUBCLASS🔱 🛡️1st profession - 50medal 🛡️2nd profession - 500 medal 🛡️3rd profession - 1k medal +30kk adena 🛡️Sub class - Quest. No necesita matar raids. ⚙️Configuraciones⚙️ 🛡️Gmshop  grade - B. 🛡️Grade A-S Craft - yes x1 chance 🛡️Globlal teleport - yes 🛡️Buffer 1hora. 🛡️Buffer slot 24(+4divine)+12 dances-song 🛡️Auto learn skils - yes 🛡️Autoloot - yes 🛡️Mana potion recarga 1000 ,9segundos delay. 🛡️Champions system:     ▫️lvl 30 - 76     ▫️chance respawn 0.5%.     ▫️adena x20 🛡️Max lvl party 14 lvl. 🛡️Festive sweeper on. 🛡️Max client pc 2. 🛡️Raid boss respawn retail. 🛡️Nobleza quest - yes. 🛡️Barakiel respawn 6 horas + -30 min. 🛡️Olimpiada duracion 14 dias. 🛡️Olimpiada de 18:00 a 00:00 🛡️Safe enchant +3 🛡️Normal enchant scroll 50% ⚠️+11-16 chance 30% 🛡️Bleesed enchant scroll 55% ⚠️+11-16 chance 35% 🛡️Rate dinamico x1 lvl 77-80   🛡️🗡️CLANES INFO🗡️🛡️ 🔅Crear clan min. level 20 🔅Max Alianzas 1 🔅Duracion penalidades clan / alianzas 8 horas. 🔅Cambio de lider 24 horas. 🛡️⚔️ ASEDIOS ⚔️🛡️ 🔅Cada 2 semanas. 🔅Proteccion hwid 1 pc. 🔅Clanes registrados. acceden a zona de asedio. 🔅Castillo asediable Aden. 🔅Reward 1000 FA 🔅Horario 16:00 GMT-3 🎊PACK DE INICIO🎊 🔅Start set - armor\weapon no grade. 🔅Level 20  - 5 shadow cuppon grado D 🔅Level 40 - 5 shadow cuppon grado C 🔅Free Autofarm 24 horas. 💰 INFO PREMIUM 💰 🔅Free autofarm. 🔅xp x30 🔅sp x30 🔅adena x17 🔅drop x4 🔅spoil x4 🔅enchant +2% 🔅seal stone x1 🔅Altb Gk-Gmshop/buffe ⚔️ RAID  BOSS INFO ⚔️ 🔅Raid boss 70 ++ respawn 5 días despues. 🔅Raid boss 75 ++ respawn 15 días despues 🔅Drop LETTER L2DAY para tradear en GMshop. ⚔️ INFO SEVEN SING ⚔️ 🔅Inicio del drop Seal stones dia 5 de iniciado el server. 🎊 EPIC RAID INFO 🎊 🔅Queen Ant (lvl 40)respawn Lunes a Viernes 22:00 GMT-3 drop chance 30%. 🔅Core (lvl 80)respawn Martes-miercoles 20:20 GMT-3 drop chance 100%. 🔅Orfen (lvl 80)respawn Martes-miercoles 21:00 GMT-3 drop chance 100%. 🔅Zaken (lvl 80)respawn Jueves 23:00 GMT-3 drop chance 100%. 🔅Frintezza (lvl 80)respawn Viernes 23:00 GMT-3 drop chance 100%. 🔅Baium (lvl 80)respawn Sabado 22:00 GMT-3 drop chance 100%. 🔅Valakas (lvl 80)respawn Domingo 20:00 GMT-3 drop chance 100%. 🔅Antharas (lvl 80)respawn Domingo 22:00 GMT-3 drop chance 100%.
    • The server is running in l2house.com.ar with C4 mode and in L2Tekila within the same login you can also test it in C5, if you want me to raise another chronicle to test, just let me know.
    • video nice song TopGear  gaming 1990    ....  
    • I have a system where Accounts are saved on login screen for fast login. I am playing a server where this feature is not on the logic screen. How I can try to add this feature to the system? I don't know what files I would have to touch.   Thanks!!
  • Topics

×
×
  • Create New...