Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @filename ItemMover.js
- * @author kolton
- * @desc Easy item management that uses screenhook events
- */
- function ItemMover() {
- var i, activeAction, item, items,
- hooks = [];
- // Storage override
- Storage.Stash.MoveTo = function (item) {
- var i, spot, tick;
- if (Packet.itemToCursor(item)) {
- for (i = 0; i < 15; i += 1) {
- spot = Storage.Stash.FindSpot(item); // Returns inverted coords...
- if (spot) {
- // 18 [DWORD id] [DWORD xpos] [DWORD ypos] [DWORD buffer]
- sendPacket(1, 0x18, 4, item.gid, 4, spot.y, 4, spot.x, 4, 0x4);
- }
- tick = getTickCount();
- while (getTickCount() - tick < Math.max(1000, me.ping * 2 + 200)) {
- if (!me.itemoncursor) {
- return true;
- }
- delay(10);
- }
- }
- }
- return false;
- };
- function hookHandler(click, x, y) {
- // Get the hook closest to the clicked location
- function sortHooks(h1, h2) {
- return Math.abs(h1.y - y) - Math.abs(h2.y - y);
- }
- if (click === 0) { // Left click
- // Sort hooks
- hooks.sort(sortHooks);
- switch (hooks[0].text) {
- case "Click on action to start/stop:":
- return true; // Do nothing
- default:
- // Don't start new action until the current one finishes
- if (activeAction && activeAction !== hooks[0].text) {
- return true;
- }
- // Toggle current action on/off
- activeAction = activeAction ? false : hooks[0].text;
- break;
- }
- hooks[0].color = hooks[0].color === 2 ? 1 : 2;
- return true; // Block click
- }
- return false;
- }
- function sortPickList(a, b) { // Sort items by size to pick biggest first
- if (b.sizex === a.sizex && b.sizey === a.sizey) { // Same size - sort by distance
- return getDistance(me, a) - getDistance(me, b);
- }
- return b.sizex * b.sizey - a.sizex * a.sizey;
- }
- hooks.push(new Text("Click on action to start/stop:", 25, 190, 4, 1, 0, false, hookHandler));
- hooks.push(new Text("Empty Inventory", 25, 200 + hooks.length * 17, 2, 1, 0, false, hookHandler));
- hooks.push(new Text("Empty Stash", 25, 200 + hooks.length * 17, 2, 1, 0, false, hookHandler));
- hooks.push(new Text("Empty Cube", 25, 200 + hooks.length * 17, 2, 1, 0, false, hookHandler));
- hooks.push(new Text("Inventory to Stash", 25, 200 + hooks.length * 17, 2, 1, 0, false, hookHandler));
- hooks.push(new Text("Pick Items", 25, 200 + hooks.length * 17, 2, 1, 0, false, hookHandler));
- while (true) {
- switch (activeAction) {
- case "Empty Inventory":
- items = me.findItems(-1, 0, 3);
- if (items) {
- while (activeAction && items.length > 0) {
- Packet.dropItem(items.shift());
- }
- }
- activeAction = false;
- break;
- case "Empty Stash":
- case "Empty Cube":
- if (!me.inTown || !Town.openStash()) {
- me.overhear("Failed to open stash");
- activeAction = false;
- break;
- }
- items = me.findItems(-1, 0, activeAction === "Empty Stash" ? 7 : 6);
- if (items) {
- while (activeAction && items.length > 0) {
- item = items.shift();
- if (item.classid !== 549) { // Don't drop the cube
- Packet.dropItem(item);
- }
- }
- }
- me.cancel();
- activeAction = false;
- break;
- case "Inventory to Stash":
- items = me.findItems(-1, 0, 3);
- if (items) {
- while (activeAction && items.length > 0) {
- item = items.shift();
- if (Storage.Stash.CanFit(item)) {
- Storage.Stash.MoveTo(item);
- }
- }
- }
- activeAction = false;
- break;
- case "Pick Items":
- item = getUnit(4, -1, 3);
- items = [];
- if (item) {
- do {
- items.push(copyUnit(item));
- } while (item.getNext());
- }
- while (activeAction && items.length > 0) {
- items.sort(sortPickList);
- item = items.shift();
- if (Town.ignoredItemTypes.indexOf(item.itemType) === -1 && Storage.Inventory.CanFit(item)) {
- Pickit.pickItem(item);
- }
- }
- activeAction = false;
- break;
- default:
- for (i = 0; i < hooks.length; i += 1) {
- if (hooks[i].color === 1) {
- hooks[i].color = 2;
- }
- }
- break;
- }
- delay(100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement