You're looping through all the sheeps, that's why.
|
Ok so I'm adding sheep shearing and this is my code
But when eve I shear a sheep it changes all of the npcs to npc 42. How would I make it where it only changes that one npc?Code:public static void shearSheep(Client c, int npcId) { switch (npcId) { case 43: c.startAnimation(893); for (int i = 1; i < NPCHandler.maxNPCs; i++) { if (NPCHandler.npcs[i] == null) { NPCHandler.npcs[i].requestTransform(42); return; } } return; } }
You're looping through all the sheeps, that's why.
I tryed this, still didn't work.
Code:case 43: c.startAnimation(893); NPCHandler.npcs[npcId].requestTransform(42); return;
Unless requestTransform(int) is a static method, that should throw a NullpointerException (it performs a method on the first null npc it encounters instead).
Either your problem is related to a static requestTransform(int) method or it has nothing to do with the shown method at all.
I also don't see anything that identifies that one particular npc (I except not only the npcId but also an index in the npcArray, which should be information received from the ObjectOnNpc packet).
EDIT: is npcId the place in the index or is it the npcType's id?
The changing of all the npcs isn't due to the method posted above then.
You're looking to do something like:
Other checks could be possible (to see if the sheep has been shorn already: check the current transform value).Code:if(npc[npcIndex].npcId == 43){ c.startAnimation(893); npc[npcIndex].requestTransform(42); }
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |