Dear Guru's: Global drop with Params

Support for the latest build of L2J Server, get help here with installations, upgrades, problems.
Do not post bugs reports here, use viewforum.php?f=77 instead.
There is no support for other server builds than the official provided by l2jserver.com
Forum rules
READ NOW: L2j Forums Rules of Conduct
mattjanes
Posts: 30
Joined: Sun Jan 07, 2007 2:26 am

Dear Guru's: Global drop with Params

Post by mattjanes »

Server Rev: 5937
Datapack Rev: 9641

Dear Guru's I'm wondering what your thoughts on the best way of adding something like this to a server, please ignore my poor sudo scrip cause I am not a scripter and know just enough of the coding world to get by :P

What I'm looking to do is erase my total server drop list and add a basic drop script/event/mod that would cover most of my basics with a few params needing to be met. Now for the SUDO SPEAK!

Example A:

if NPCLvl is between ValueA(1) and ValueB(10) then DropItem Adena(57) with MinValue(100) and MaxValue(1000) at Chance(700000) and SetDropType(0)

Theoretically this would allow any mob thats lvls 1-10 have a 70% chance to drop 100-1000a to a player upon death, and the drop-type would b 0 so it can split between party members. Of course could change this to -1 for Spoil or 2 for regular items.

Now within this script/mod/whatever you want to call it, I can add multiple items not just adena of course! :P add things like Drop animal bone to all mobs 1-40 or something.

Any help would be much appreciated tyvm.
User avatar
UnAfraid
L2j Veteran
L2j Veteran
Posts: 4199
Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:

Re: Dear Guru's: Global drop with Params

Post by UnAfraid »

Here's an example
Gist by: UnAfraid
Image
User avatar
St3eT
Posts: 961
Joined: Sun Mar 07, 2010 6:50 pm

Re: Dear Guru's: Global drop with Params

Post by St3eT »

If i should be black sheep for sure no as punishment
Image
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Dear Guru's: Global drop with Params

Post by jurchiks »

Something is wrong with the forum, it doesn't accept the contents of my post.
Here's the original text:
http://pastebin.com/JYzRtB5e
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
User avatar
UnAfraid
L2j Veteran
L2j Veteran
Posts: 4199
Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:

Re: Dear Guru's: Global drop with Params

Post by UnAfraid »

That can register drops to all monsters he wants for specific levels
Image
mattjanes
Posts: 30
Joined: Sun Jan 07, 2007 2:26 am

Re: Dear Guru's: Global drop with Params

Post by mattjanes »

This would be awesome to be able to use something similar to this, it's much more on my skill level of understanding/editing it for multiple uses :P, however like UnAfraid stated I would be unable to to set specific Parameters to it like Mob Level.
UnAfraid wrote:Here's an example
Gist by: UnAfraid
This looks really cool, How would I go about implementing something like this? I haven't touched Eclipse or anything like that (yet) just download the pre-compiled files and run it that way. Is this something that I could put into

Data/Scripts/Mods/Custom Drops/CustomDrop.java ?

Also I was trying to decode the script myself to understand how it works, I used to know like entry level Java from First Year University but its been a few years :P would you just make multiples of that script per item, or is there a easier way to have multiple drops within the one script?
User avatar
UnAfraid
L2j Veteran
L2j Veteran
Posts: 4199
Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:

Re: Dear Guru's: Global drop with Params

Post by UnAfraid »

Example script updated.
You must put it on data/scripts/ai/npc/DropExample.java
Image
User avatar
St3eT
Posts: 961
Joined: Sun Mar 07, 2010 6:50 pm

Re: Dear Guru's: Global drop with Params

Post by St3eT »

Ah i forgot ;( i have it edited for my server and there i can define lvls too. Nothing then.
If i should be black sheep for sure no as punishment
Image
mattjanes
Posts: 30
Joined: Sun Jan 07, 2007 2:26 am

Re: Dear Guru's: Global drop with Params

Post by mattjanes »

UnAfraid wrote:Example script updated.
You must put it on data/scripts/ai/npc/DropExample.java
Heavy with comments I love it! :D I can't look at it too much now being at work but gonna jump all over this tonight. Only thing I don't see in the script (I may have missed the line of code) is where you establish the drop chance.

Also if I wanted to add multiple drops within the same event script would I just add new methods like OnCreatureKill1, 3 etc.?

Thanks so much, very helpful community :)

also you sir have made it to my monument of fame (a statue npc I'll have in giran/Aden that list all contributers/helpers in the servers development as a sign of respect for their hand work) :)

@Ste3T ooh you should share how you did that :P
mattjanes
Posts: 30
Joined: Sun Jan 07, 2007 2:26 am

Re: Dear Guru's: Global drop with Params

Post by mattjanes »

Ok so here is my Hack-Job at editing the scrip to allow multiple drops/level ranges (Please excuse my noob-level coding skills)(I am also sure there is a much more efficient way to do this, especially if mine probably has syntax and coding flaws :P)

The 2 things that I cant seem to figure out how to add either are Setting Drop Chance (value within 1000000 like other drops) and Setting Drop Type (0 Aden, 2 Regular Items, -1 Spoil).

Anyways I attached my mess of a code attempt please let me know whats wrong and how I can fix it :)
Gist by: yulrun
You do not have the required permissions to view the files attached to this post.
User avatar
UnAfraid
L2j Veteran
L2j Veteran
Posts: 4199
Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:

Re: Dear Guru's: Global drop with Params

Post by UnAfraid »

You are writing over same variables which means the latest item you add will be the only one to be dropped..
Image
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Dear Guru's: Global drop with Params

Post by jurchiks »

Your code will never work because the syntax is absolutely broken. You should use an IDE if you're just learning, it will automatically tell you when something is wrong with your code syntax.

Using this core patch to add more flexible filtering options:
[pastebin]68F6RMCD[/pastebin]
and this script:
[pastebin]BkZHeTiC[/pastebin]

You will achieve what you want.
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
mattjanes
Posts: 30
Joined: Sun Jan 07, 2007 2:26 am

Re: Dear Guru's: Global drop with Params

Post by mattjanes »

Sorry for the lack of a reply work has been busy lately, not ignoring your guys help :), if I add a variable for dropChance to the DropItem method, and change your line 96 to:

if (getRandom(0,1000000) <= di.dropChance)
{
monster.dropItem(event.getAttacker().getActingPlayer(), new ItemHolder(di.itemId, getRandom(di.minCount, di.maxCount)));
}

Would that still work out properly?
User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Dear Guru's: Global drop with Params

Post by jurchiks »

Yes.
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
mattjanes
Posts: 30
Joined: Sun Jan 07, 2007 2:26 am

Re: Dear Guru's: Global drop with Params

Post by mattjanes »

Finally got around to modifying what you gave me in a IDE (i'm liking netbeans) and still taking a my java courses so I'm still very much a noob but I'm definitely starting to understand things quite a bit more than when i first made this post.

If the code is indeted weird I noticed toggling 'Line Numbers' corrects this.

Code: Select all

     package ai.npc;         import java.util.List;    import java.util.ArrayList;    import java.util.Set;    import java.util.HashSet;    import java.util.Optional;         import com.l2jserver.gameserver.datatables.NpcData;    import com.l2jserver.gameserver.model.actor.L2Attackable;    import com.l2jserver.gameserver.model.events.impl.character.OnCreatureKill;    import com.l2jserver.gameserver.model.holders.ItemHolder;         /**     * @author jurchiks     */    public final class DropExample extends AbstractNpcAI    {            private static final List<DropDetails> DROP_DATA = new ArrayList<>();            static            {                    DROP_DATA.add(new DropDetails(1, 10, new DropItem(57, 100, 1000, 1000000), new DropItem(1206, 1, 1, 5000, false)));                    DROP_DATA.add(new DropDetails(11, 20, new DropItem(57, 1000, 2600, 1000000)));                    // and so on...            }                       private static class DropDetails            {                    public final int minLevel;                    public final int maxLevel;                    private final List<DropItem> itemDrops;                                       public DropDetails(int minLevel, int maxLevel, DropItem... drops)                    {                            this.minLevel = minLevel;                            this.maxLevel = maxLevel;                                                       for (drop : drops)                            {                                    if (drop != null)                                    {                                            itemDrops.add(drop);                                    }                            }                    }                                       public List<DropItem> getDrops()                    {                            return this.itemDrops;                    }            }                       private static class DropItem            {                    public final int itemId;                    public final int minCount;                    public final int maxCount;                    public final int dropChance;                    public final boolean isSpoil;                                       public DropItem(int itemId, int minCount, int maxCount, int dropChance)                    {                            this.itemId = itemId;                            this.minCount = minCount;                            this.maxCount = maxCount;                            this.dropChance = dropChance;                            this.isSpoil = false;                    }                    public DropItem(int itemId, int minCount, int maxCount, int dropChance, boolean isSpoil)                    {                            this.itemId = itemId;                            this.minCount = minCount;                            this.maxCount = maxCount;                            this.dropChance = dropChance;                            this.isSpoil = isSpoil;                    }                    public boolean dropBySpoil(){                        return this.isSpoil;                    }            }                       private DropExample()            {                    super(DropExample.class.getSimpleName(), "ai/npc");                                       final Set<Integer> npcIds = new HashSet<>();                                       for (DropDetails details : DROP_DATA)                    {                            NpcData.getInstance().findTemplates(t -> (t.getLevel() >= details.minLevel) && (t.getLevel() <= details.maxLevel))                                    .forEach(t -> npcIds.add(t.getId()));                    }                                       setCreatureKillId(this::OnCreatureKill, npcIds);            }                       public void OnCreatureKill(OnCreatureKill event)            {                    // Make sure a player killed this monster.                    if ((event.getAttacker() != null) && event.getAttacker().isPlayable() && event.getTarget().isAttackable())                    {                            final L2Attackable monster = (L2Attackable) event.getTarget();                            // find drop data based on monster's level, can't do it any other way since drop data is stored in a list, not a map                            final Optional<DropDetails> dd = DROP_DATA.stream().filter(dd -> monster.getLevel() >= dd.minLevel && monster.getLevel() <= dd.maxLevel)                                    .findFirst();                            // drop details for NPC's level were found, use them                            if (dd.isPresent())                            {                                    for (DropItem di : dd.get().getDrops())                                    {                                        // Drops the item normally if drop chance is achieved and not a spoil type drop.                                        if (getRandom(0,1000000) <= di.dropChance &! di.dropBySpoil())                                        {                                            monster.dropItem(event.getAttacker().getActingPlayer(), new ItemHolder(di.itemId, getRandom(di.minCount, di.maxCount)));                                        }                                        // Changes drop type if the spoil condition is true                                        else if (di.dropBySpoil() && getRandom(0,1000000) <= di.dropChance)                                               monster.dropItem(event.getAttacker().getActingPlayer(), new ItemHolder(di.itemId, getRandom(di.minCount, di.maxCount)));                                    }                            }                    }            }                       public static void main(String[] args)            {                    new DropExample();            }    } 
Only question I got now, Is on my line 118 (I guess its 119 on here since line 1 is blank.) what would I have to modify in that statement to change it to a spoil drop type instead of a regular drop ?
Last edited by mattjanes on Sun Jun 29, 2014 7:11 am, edited 2 times in total.
Post Reply