Code:
package ardi.model.npcs;
import ardi.model.npcs.NPCHandler;
import ardi.model.players.Client;
import ardi.event.*;
public class NPCTransform {
public static void TransformNPC(final Client c, final int i, final int newId, int anim, final String forceChat, final String msg, final int addItem, final int timer , final int timer2) {
if (c == null || i < 0 || NPCHandler.npcs[i].lastTransformed < 0)
return;
NPCHandler.npcs[i].transformTime = timer2*1000;
//int npcId = NPCHandler.npcs[i].npcId;
//final int x = NPCHandler.npcs[i].getX(), y = NPCHandler.npcs[i].getY();
if (anim != -1)
c.startAnimation(anim);
CycleEventHandler.getSingleton().addEvent(c, new CycleEvent() {
@Override
public void execute(CycleEventContainer container) {
if (addItem != -1)
c.getItems().addItem(addItem, 1);
if (forceChat.length() > 1)
NPCHandler.npcs[i].forceChat(forceChat);
if (msg.length() > 1)
c.sendMessage(msg);
NPCHandler.npcs[i].requestTransform(newId);
container.stop();
}
@Override
public void stop() {
NPCHandler.npcs[i].lastTransformed = (int) System.currentTimeMillis();
}
}, timer);
}
}
Originally provided here:
http://www.rune-server.org/runescape...nsformnpc.html
Here's my firstclick:
Code:
case FIRST_CLICK:
c.npcClickIndex = c.inStream.readSignedWordBigEndian();
c.npcType = NPCHandler.npcs[c.npcClickIndex].npcType;
int id = NPCHandler.npcs[c.npcClickIndex].npcId;
if (c.goodDistance(NPCHandler.npcs[c.npcClickIndex].getX(),
NPCHandler.npcs[c.npcClickIndex].getY(), c.getX(),
c.getY(), 2)) {
c.turnPlayerTo(NPCHandler.npcs[c.npcClickIndex].getX(),
NPCHandler.npcs[c.npcClickIndex].getY());
NPCHandler.npcs[c.npcClickIndex].facePlayer(c.playerId);
c.getActions().firstClickNpc(c.npcType);
switch(c.npcType){
case 43:
NPCTransform.TransformNPC(c,id,42, 893,"Baa!", "You obtain some wool.", 1737, 0 , 5);
break;
}
c.sendMessage("List Id: " + Integer.toString(id));
c.sendMessage("NPC Id: " + Integer.toString(c.npcType));
c.sendMessage("NPC Id2: " + Integer.toString(NPCHandler.npcs[id].npcType));
} else {
The issue is, the code isn't working as expected. I suppose timer is for how long it should take for the sheep to revert back to woolen state and timer2 is the delay from click to transformation?
This is what happens:
a) The sheep can only be shorn once, even after reverting to its wooly state b)The sheep always returns to wooly state very rapidly
I've tried playing around with the timer values but I can't seem to make sense of it.
In addition can someone please clearly explain how this cycleevent/timing/container stuff works? Something tells me I'll be needing to use this a lot, but I just cant wrap my head around it right now.
THANKS!