Page 1 of 2
Dear Guru's: Global drop with Params
Posted: Fri Jun 06, 2014 7:27 am
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
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!

add things like Drop animal bone to all mobs 1-40 or something.
Any help would be much appreciated tyvm.
Re: Dear Guru's: Global drop with Params
Posted: Fri Jun 06, 2014 9:15 am
by UnAfraid
Re: Dear Guru's: Global drop with Params
Posted: Fri Jun 06, 2014 9:32 am
by St3eT
Re: Dear Guru's: Global drop with Params
Posted: Fri Jun 06, 2014 10:57 am
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
Re: Dear Guru's: Global drop with Params
Posted: Fri Jun 06, 2014 11:12 am
by UnAfraid
That can register drops to all monsters he wants for specific levels
Re: Dear Guru's: Global drop with Params
Posted: Fri Jun 06, 2014 2:13 pm
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

, however like UnAfraid stated I would be unable to to set specific Parameters to it like Mob Level.
UnAfraid wrote:Here's an example
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

would you just make multiples of that script per item, or is there a easier way to have multiple drops within the one script?
Re: Dear Guru's: Global drop with Params
Posted: Fri Jun 06, 2014 3:20 pm
by UnAfraid
Example script updated.
You must put it on data/scripts/ai/npc/DropExample.java
Re: Dear Guru's: Global drop with Params
Posted: Fri Jun 06, 2014 3:34 pm
by St3eT
Ah i forgot ;( i have it edited for my server and there i can define lvls too. Nothing then.
Re: Dear Guru's: Global drop with Params
Posted: Fri Jun 06, 2014 6:31 pm
by mattjanes
UnAfraid wrote:Example script updated.
You must put it on data/scripts/ai/npc/DropExample.java
Heavy with comments I love it!

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

Re: Dear Guru's: Global drop with Params
Posted: Sat Jun 07, 2014 1:03 am
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

)
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
Re: Dear Guru's: Global drop with Params
Posted: Sat Jun 07, 2014 7:29 am
by UnAfraid
You are writing over same variables which means the latest item you add will be the only one to be dropped..
Re: Dear Guru's: Global drop with Params
Posted: Sat Jun 07, 2014 2:56 pm
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.
Re: Dear Guru's: Global drop with Params
Posted: Sun Jun 08, 2014 11:52 pm
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?
Re: Dear Guru's: Global drop with Params
Posted: Mon Jun 09, 2014 3:53 pm
by jurchiks
Yes.
Re: Dear Guru's: Global drop with Params
Posted: Sun Jun 29, 2014 5:20 am
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 ?