PDA

View Full Version : Inventory Sorter



Dissimulo
05-22-2016, 12:07 PM
Wanted to make something move gems to the bottom of the inventory for my Powerminer, this is what I came up with.

Also uses recursion, which took a while to wrap my head around.

http://i.imgur.com/jp5xNN3.gif

program InventorySorting;

{$DEFINE SMART}
{$i Aerolib/Aerolib.simba}
{$i Reflection/Reflection.simba}

{
Inventory Sorting
Author: Dissimulo (https://villavu.com/forum/member.php?u=160877)
Last Update: 23/05/2016
Version: 2.0
Category: Utility
Description: Moves Items to the bottom of the backpack
Includes: Reflection and AeroLib
Features:
- Aerolib (https://villavu.com/forum/showthread.php?t=108953)
- Reflection (https://villavu.com/forum/showthread.php?t=111662)
- Simple SMART paint
Versions:
- 2.0 (22/05/2016)
Reworked functions into Color and Reflection
Rewrote functions (thanks to Turpinator and Le Jingle
Using proper wrappers for Reflection (thanks Harrier)
- 1.0 (22/05/2016)
Cleaned up for public release
Credits:
- Flight (Aerolib)
- Kyle (Lape Reflection)
}

var
MyGuy: TReflectLocalPlayer;

function InventorySorterColor: Boolean;
var
i, j: Integer;
begin
for i := 28 downto 1 do
if (not itemInSlot(i)) then
begin
for j := 1 to i do
if (itemInSlot(j)) then
begin
dragMouseBox(invBox(j), invBox(i));
wait(RandomRange(400, 550));
Break;
end;
end;
Result := not isInvFull;
end;

function InventorySorterReflect: Boolean;
var
i, j: Integer;
begin
if Reflect.Gametab.Current <> 55 then
Reflect.Gametab.Open(55);
for i := 28 downto 1 do
if (not Reflect.Inv.ItemInSlot(i)) then
begin
for j := 1 to i do
if (Reflect.Inv.ItemInSlot(j)) then
begin
dragMouseBox(Reflect.Inv.InvBox(j), Reflect.Inv.InvBox(i));
wait(RandomRange(400, 550));
Break;
end;
end;
Result := not Reflect.Inv.IsFull;
end;

begin
initAL();
Reflect.Setup;
MyGuy.Username := 'USERNAME';
MyGuy.Password := 'PASSWORD';
MyGuy.Active := True;
MyGuy.Login;
wait(RandomRange(1000, 1550));
if not InventorySorterReflect then
Writeln('Inventory full');
end.

Harrier
05-22-2016, 12:25 PM
Don't call funcs directly like TReflectionInventory.WhatEver call them via the wrapper (Which I think is) Reflect.Inventory.WhatEver. Calling them directly is bad practice and the newer versions of lape stops you from doing this and will break your script.

rj
05-22-2016, 04:19 PM
Don't call funcs directly like TReflectionInventory.WhatEver call them via the wrapper (Which I think is) Reflect.Inventory.WhatEver. Calling them directly is bad practice and the newer versions of lape stops you from doing this and will break your script.

I didn't even know you could do that lol

Olly
05-22-2016, 05:10 PM
I didn't even know you could do that lol

You can't if it access anything from it's self (self.something) but you shouldn't really be doing it in the Lape that Simba has, also if you turn assertions on {$assertions on} it will error on compile.

Harrier
05-22-2016, 05:14 PM
You can't if it access anything from it's self (self.something) but you shouldn't really be doing it in the Lape that Simba has, also if you turn assertions on {$assertions on} it will error on compile.

With the current lape version in simba it wont error on compile, but it should during run time.
[14:09:15] <niels> newer lape version should catch it at compile tie
[14:09:17] <niels> time*

Turpinator
05-22-2016, 05:45 PM
I feel like the use of recursion is excessive and unneeded.
Procedure InvSort();
begin
for i := 1 to 28 do
if isiteminslot(i) then
for j := 28 downto 1 do
begin
if i = j then
exit();
if not isiteminslot(j) then
begin
moveitemtoslot(i, j);
break();
end;
end;
end;

Something as simple as this should work, i think.

Olly
05-22-2016, 06:23 PM
With the current lape version in simba it wont error on compile, but it should during run time.
[14:09:15] <niels> newer lape version should catch it at compile tie
[14:09:17] <niels> time*

That's why I said in the Lape version Simba has, the newer Lape has real support for static methods (which is what this is). But that's nice to know this mistake cant happen in the future.

Le Jingle
05-22-2016, 06:25 PM
well done OP @ learning

also my input: (not test)



procedure InvyItemMover();
var i, j: Integer;
begin
for i := 28 downto 1 do
if (not TReflectionInventory.ItemInSlot(i)) then
for j := 1 to i do
if (TReflectionInventory.ItemInSlot(j)) then
dragMouseBox(TReflectionInventory.InvBox(j), TReflectionInventory.InvBox(i));
end;

Dissimulo
05-23-2016, 09:53 AM
Don't call funcs directly like TReflectionInventory.WhatEver call them via the wrapper (Which I think is) Reflect.Inventory.WhatEver. Calling them directly is bad practice and the newer versions of lape stops you from doing this and will break your script.
I see what meant when I asked on IRC, thanks for the heads up.



I feel like the use of recursion is excessive and unneeded.
snip

Something as simple as this should work, i think.


well done OP @ learning

also my input: (not test)



snip

After looking at these 2 examples, I get why you say that Turp. I've been trying to learn about more intermediate programming concepts, and while thinking about how to write this function, recursion just popped into my head.



I've also rewritten the snippet, as well as added a color only version (didn't know Aerolib was so versatile).

honeyhoney
05-23-2016, 02:49 PM
Am I being as blind as a bat as well as a dumb as a donkey? Where's the recursion in this? Looks like I was late to the party?

Cool function. Looks like you learned a fair bit. Now you just need it to work on gems only :) (and potentially swap them with ore rather than having to drop the ore first?)