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

    • wtf is your website lol ai slop
    • who have this files? or info about cached packets?
    • Hi maxcheaters, i am trying to bring back an old server ( L2Revenge) but with my own ideas, i only liked how it was and made the gameplay based on that just putting my own ideas.   So practicly is a PTS C6 with an extender that i work lately    Exp / SP is x45 adena is x200 and drops x5  so safe is +3 , max is unlimited and rate is 65% for both mage and fighter weapons I created a system that you can get on the levels the gear you need based on farm but for S grade theres a little farm to get some armor Tokens to unseal them. As you remember L2Revenge had olympiad / Tournament gear. So people abused them and had S grades that way just couldnt enchant them. So i made to be wearable only if u are nobless. That way i cancel this "exploit".  The server gives opportunity to solo and clans , epic gear ( epic weapons) or armors can be bought with raid tokens and you can craft them or get them with various ways Regarding Buffs: 24 buff slots no changes asked. Cov/Pony/Cat , siren - renewal - champion out of buffer , if u make the char as main roll u can use them or use the offline buffer system to sell them and get adenas. their time is 20 mins so that way we see again the " 1kk for rene/siren" or rec = song  Regarding armors: they are dropped ( parts ) from 3 only raids , rest lvl 76+ raids drop recipes , so crafting takes place (so if u are solo u can craft them )  there are 3 armors each armor have its purpose: Revenge Armors - Example for light ( its a glass cannon , high damage , less atk speed and less pdef ) - they mostly modify your base stats, so useable on sieges or off tank chars Titanium Armors - A little bit of balanced of all  Epic Armor - Daggers/Enchanters/Healers mostly but u can always combine your build    Regarding weapons: can be dropped from Monastery of Silence monsters or get them from NPC with Raid Tokens its like a 5% better than S grades and the S/A Activates at +4  Regarding retail gear: you need to unseal only S grades for a great amount of armor tokens all weapons on any grade need Soul crystals that are sold for adenas  stage 13 crystals are expensive or dropped from raids Regarding fun: There is a squash event a Fortress vs Fortress pvp event an RB Event at weekends and from Monday - Wednesday Tournament ( Olympiad is closed monday/tuesday/wednesday)  at tournament you can practice 1vs1 like olympiad but pots/ss allowed , gear allowed is only olympiad or tournament , each win of match gives u 5 glits at 100 glits u can be hero till restart Olympiad works the same way regarding gear allowance but works only thursday to friday and you win monthly hero Auction with Raid Tokens is activated Event medals from events can be exchanged for various items i try to make the oldschool with a little bit of new school systems Not planing to open it anytime soon as i still develop and make corrections to extender , looking forward to meet people that actually played this and are hyped to help on testing / development   P.S is c5 into interlude ( theres no akamanah / nor PI aswell , no lifestones) forgot to mention
    • Announcement – L2 Relic Server Opening Soon! We’re excited to share some great news! Our team has been working hard behind the scenes, and we’re nearly ready to launch our brand-new Lineage server this winter. The journey is just about to begin – so prepare yourselves! Gather your friends, sharpen your skills, and get ready to experience an epic adventure. Stay tuned for more details, updates, and the official beta-opening date. This winter, history will be written once again… are you ready?   Developed by https://dailyhost.eu/
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock