PDA

View Full Version : [562 rs2hd] Require an item to attack NPCS



Lukedawesome
January 22nd, 2011, 17:57
What this does: Makes you require an item to attack ALL npcs.

What it's good for: GOD....IDK? don't hate.

in playervsnpc.java right under:

public void Attack(NPC n) {

add this:



if(p.getInventory().contains(*ITEM ID*, 1)) {
} else {
p.getActionSender().sendMessage("You need a *ITEM HERE* to attack.");
p.getActionSender().sendMessage("Type ::*ITEM HERE* to get one");
n.Attacking = false;
p.resetAttack();
return;
}

You'll have to create a command that gives you that item, or you can make an NPC do it. But, i recommend you give one in your starter package.

Now...if you have Noszscape, and your item on death drops don't work, you need to add this in your deathevent.java

Right under:

p.getActionSender().sendMessage("Oh dear, you have died.");

Put:

p.getInventory().deleteItem(*ITEM ID HERE*, 1);

I don't think I left anything out, but if i did, just comment

Emily
January 22nd, 2011, 17:59
More of a snippet then a tutorial...

Lukedawesome
January 22nd, 2011, 18:05
More of a snippet then a tutorial...

teaching 'them' how to edit the death event? Eh, could be. Oh, well. Mods can move if they want

crezzy
January 22nd, 2011, 20:56
This could be done with just


if(n.getId() == Npcid && !p.getEquipment().contains(ItemId) ) {
p.sm("You can only attack this NPC with w.e item!");
n.Attacking = true;
p.resetAttack();
return;
}

:D You should still make theNPC attack even if you can not. Where in your tut its set to false which means its not attacking.
Anyway this is extremely easy... Why would people need a tut for this :s lol

tedhead2
January 22nd, 2011, 21:14
corruption-x has this lol....

good, might use when i un-quit rsps.

Steve
January 22nd, 2011, 21:53
I luv if statement tutorials.

axter
February 3rd, 2012, 12:48
how do i change the npc? there is no way to change the npc D:

Hash
February 3rd, 2012, 13:06
Change 'Npcid' by the ID of your NPC.

axter
February 3rd, 2012, 23:12
thanks, i did this for the death part,
Player p = (Player) entity;
p.getActionSender
p.getInventory().deleteItem(16909, 1);

and got this error


Preparing...
Compiling core...
src\com\rs2hd\content\DeathEvent.java:233: ';' expected
p.getInventory().deleteItem(16909, 1);
^
src\com\rs2hd\content\DeathEvent.java:232: package p does not exist
p.getActionSender
^
src\com\rs2hd\content\DeathEvent.java:233: p is already defined in execute()
p.getInventory().deleteItem(16909, 1);
^
src\com\rs2hd\content\DeathEvent.java:233: cannot find symbol
symbol: method getInventory()
p.getInventory().deleteItem(16909, 1);
^
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
4 errors
Press any key to continue . . .