I know there's bound to be an error because I made this like 1 month ago, and I feel like I'm forgetting something. So if you have any problems adding just tell me.
Description: Make your NPC drop things with a java file, instead of cfg, or instead of crappy czar version.
Difficulty: 2/10
Assumed Knowledge: Copy and Paste, How to remove stuff
Tested Server: Devolution v7
Files/Classes Modified: server.java, NPCDrops.java, NPCHandler.java, client.java
Procedure
Step 1: MAKE A FRICKEN BACKUP. Then delete ANYTHING to do with NPCDrops including the NPCDrops class, and if you have it, the npc drops cfg file!
Step 2: In server.java, if you haven't already, declare:
Code:
public static NPCDrops NPCDrops = new NPCDrops();
Step 3: Now in client.java in the method 'initialize' add this at the top:
Code:
server.npcHandler.plazID = playerId;
(I used a playerId on purpose. Not public client c or something.)
Step 4: Open up NPCHandler.java
Declare:
Code:
public int plazID = -1;
By now, you have deleted anything to do with drops in the NPCHandler too. Search for this:
Code:
} else if ((npcs[i].actionTimer == 0)
&& (npcs[i].DeadApply == true)
&& (npcs[i].NeedRespawn == false)
&& (npcs[i] != null)) {
Add this:
Code:
server.NPCDrops.main(npcs[i].npcType, plazID, npcs[i].absX, npcs[i].absY);
In this area (look at where I added at bottom):
Code:
if ((temp != null) && !temp.disconnected) {
if (npcs[i].npcType == 936) {
server.playerHandler
.yell("San Tojalon has been slain by "
+ temp.playerName + " (level-"
+ temp.combatLevel + ")");
} else if (npcs[i].npcType == 221) {
server.playerHandler
.yell("The Black Knight Titan has been slain by "
+ temp.playerName
+ " (level-"
+ temp.combatLevel + ")");
} else if (npcs[i].npcType == 1613) {
server.playerHandler
.yell("Nechryael has been slain by "
+ temp.playerName + " (level-"
+ temp.combatLevel + ")");
} else if (npcs[i].npcType == 1158) {
temp.SummonNewNPC(1160);
}
server.NPCDrops.main(npcs[i].npcType, plazID, npcs[i].absX, npcs[i].absY);
temp.attackedNpc = false;
temp.attackedNpcId = -1;
}
I added it there, see.
Step 5: Replace your NPCDrops.java (if you don't have, just add this class):
Code:
/*
* Npc Drops
* Made by Filth
*/
public class NPCDrops {
public int dropAmount = -1;
public int drops = -1;
public int drop[] = new int[15];
public int amount[] = new int[15];
public boolean used[] = new boolean[15];
public void main(int thanpc, int thaplr, int npcX, int npcY) {
dropAmount = -1;
drops = -1;
for (int x = 0; x < 15; x++) {
used[x] = false;
drop[x] = -1;
amount[x] = 1;
}
client c = (client) server.playerHandler.players[thaplr];
if (c != null) {
switch(thanpc) {
/* HERES WHERE YOU PUT NPC DROPS
SAY CASE (NPCID): THEN PUT
THE DROPS YOU WANT */
case 7:
/* Farmer - Level 7 */
if (chance(87)) {
drop[0] = 995;
amount[0] = misc.random(324);
//drop[1] = server.Clues.dropClue(1);
}
break;
case 35:
/* Soldier - Level 28 */
if (chance(68)) {
drop[0] = 995;
amount[0] = misc.random(1394);
//} else if (chance(3)) { you don't have clues :p
//drop[0] = server.Clues.dropClue(1);
}
break;
}
drops = 0;
Bones(thanpc, thaplr);
for (int y = 0; y < 15; y++) {
if (drop[y] > -1 && dropAmount == -1) {
if (amount[y] <= 0) {
amount[y] = 1;
}
ItemHandler.addItem(drop[y], npcX, npcY, amount[y], thaplr, false);
} else if (dropAmount != -1) {
if (drops < dropAmount) {
DropRandoms(thaplr);
drops++;
}
}
}
}
}
public void DropRandoms(int thaplr) {
int random = misc.random(15);
if (drop[random] > -1 && used[random] == false) {
used[random] = true;
ItemHandler.addItem(drop[random], npcX, npcY, amount[random], thaplr, false);
} else {
loop(thaplr);
}
}
public void loop(int thaplr) {
DropRandoms(thaplr);
}
public void Bones(int NPC, int plr) {
if (NPC == 3200) {
} else {
ItemHandler.addItem(526, npcX, npcY, 1, plr, false);
}
}
public boolean chance(int percent) {
if (percent > 100) {
percent = 100;
}
int prob = misc.random(100);
for (int x = 0; x < percent; x++) {
if (x == prob) {
return true;
}
}
return false;
}
}
HOW TO USE:
In the switch of 'thanpc' put the npc id, then put what it drops.
Here's how you drop:
Code:
drop[0] = ITEMID;
amount[0] = AMOUNT (DEFAULT IS 1, SO YOU DON'T ALWAYS HAVE TO ADD);
That will drop 1 item, which you choose amount of. So here's an example of an NPC dropping 1 item:
Code:
case 1:
drop[0] = 995;
amount[0] = misc.random(500);
break;
This npc with the id of '1' will drop a random amount of gold. (It will NOT drop 0 gold. If the random amount turns out to be 0, it will make it 1) In this case, it will ALWAYS drop gold.
If you want to change the percent of drop add:
Code:
case 1:
if (chance(80)) {
drop[0] = 995;
amount[0] = misc.random(500);
}
break;
Now it will dorp a random amount of gold 80% of the time.
If you want it drop more than 1 item make it:
Code:
case 1:
drop[0] = 995;
amount[0] = misc.random(500);
drop[1] = 1000;
break;
Now it will drop both gold, and the item '1000' 100% of the time. Since you didn't put the amount of the item '1000', it will drop 1 of it.
If you want it to only drop ONE of these items, put:
Code:
case 1:
drop[0] = 995;
amount[0] = misc.random(500);
drop[1] = 1000;
dropAmount = 1;
break;
Now the drop amount is '1', which means its going to drop 1 item at random.
Reason I made it a class instead of a cfg, is so you can do things like:
Code:
case 1:
if (questLevel == 1) {
drop[0] = 995;
amount[0] = misc.random(500);
}
break;
For example, if you're getting keys from a rat for the Demon Slayer quest, you don't want someone to keep getting keys, so you'd put:
Code:
case 1:
if (!playerHasKey(KEY)) {
if (chance(20)) {
drop[0] = KEY;
}
}
break;
And you want to change method bones to drop correct bones.