SRL Archive - SRL Suggestions

GetBankItemAmount


Daniel

2011-12-23 04:18:26

{*******************************************************************************
function GetBankIndexItemAmount(const Index: Integer): Integer;
By: Daniel (Mayazcherquoi)
Description: Returns the amount of an item in the bank at bank index, Index.
*******************************************************************************}
function GetBankIndexItemAmount(const Index: Integer): Integer;
begin
Result := getAmountBox(BankIndexToMSBox(Index));
end;

{*******************************************************************************
function GetBankItemAmount(const x, y: Integer): Integer;
By: Daniel (Mayazcherquoi)
Description: Returns the amount of an item in the bank at bank screen
coordinates (Row, Col).
*******************************************************************************}
function GetBankItemAmount(const Row, Col: Integer): Integer;
begin
Result := GetBankIndexItemAmount(BankPointToBankIndex(Point(Row, Col)));
end;

{*******************************************************************************
function GetMSBankItemAmount(const x, y: Integer): Integer;
By: Daniel (Mayazcherquoi)
Description: Returns the amount of an item in the bank at main screen
coordinates x, y.
*******************************************************************************}
function GetMSBankItemAmount(const x, y: Integer): Integer;
begin
Result := GetBankIndexItemAmount(BankPointToBankIndex(MSTPointToBankPoint(Point(x, y))));
end;

Self-explanatory, DemiseScythe needed this and there was one for the inventory (getAmount), so I decided to make this. Can be very useful.

Add to core/Bank.scar.

EDIT: It works, btw :p

Regards,
Daniel. :)

darklordnd

2011-12-24 16:17:41

i used it but the getbankitemamount returned to zero all the time. could you help me figure out what's wrong? I was doing fletching, and wanted to know the amount of materials left by finding whichever material (unstrung bow or bow string) are fewer in the bank.

function GetBankIndexItemAmount(const Index: Integer): Integer;
begin
Result := getAmountBox(BankIndexToMSBox(Index));
end;

function bankamount(const x, y: Integer): Integer;
begin
Result := GetBankIndexItemAmount(BankPointToBankIndex(Point(x,y)));
end;


inside the main loop I have this:

 if (bankamount(col1,row1)<bankamount(col2,row2)) then
amount:=bankamount(col1,row1)
else
amount:=bankamount(col2,row2);

when it didn't work I added a writeln to know the bankamount(col1,row1), but it was zero.

Daniel

2011-12-25 02:04:19

From: darklordnd
i used it but the getbankitemamount returned to zero all the time. could you help me figure out what's wrong? I was doing fletching, and wanted to know the amount of materials left by finding whichever material (unstrung bow or bow string) are fewer in the bank.

Simba Code:
[LEFT]function GetBankIndexItemAmount(const Index: Integer): Integer;
begin
Result := getAmountBox(BankIndexToMSBox(Index));
end;

function bankamount(const x, y: Integer): Integer;
begin
Result := GetBankIndexItemAmount(BankPointToBankIndex(Point(x,y)));
end;
[/LEFT]


inside the main loop I have this:

Simba Code:
[LEFT]if (bankamount(col1,row1)<bankamount(col2,row2)) then
amount:=bankamount(col1,row1)
else
amount:=bankamount(col2,row2);
[/LEFT]


when it didn't work I added a writeln to know the bankamount(col1,row1), but it was zero.

It doesn't go by columns. It goes either by the main screen coordinates or the bank screen coordinates. I might create one for column's/rows if SRL offers the conversion methods. I will do that soon though.

In order to use it, just find the DTM of your item in the bank, and use GetMSBankItemAmount to return the value.


EDIT: My mistake, Bank Point is expressed in row's and column's.

To fix your issue, switch your column variable and row variable around. It's in the format (Row, Col), not (Col, Row) [Which is what you were doing]. :)

Swatarianess

2011-12-25 02:24:09

Cool thanks needed very much ^^ theres also one for Pouch somewhere right? hmm

darklordnd

2011-12-25 05:51:54

are you sure it's row - col and not col - row? I think everything on pascal are x - y, which are col number - row number.
Anyway, I tried swapping those around and the result is still the same - just zero. I think the problem is not there, because even when I mistake row for col, the result should be something else (amount of a different slot) and not zero. Please help me, I'm a noob :D

Daniel

2011-12-25 06:21:00

From: darklordnd
are you sure it's row - col and not col - row? I think everything on pascal are x - y, which are col number - row number.
Anyway, I tried swapping those around and the result is still the same - just zero. I think the problem is not there, because even when I mistake row for col, the result should be something else (amount of a different slot) and not zero. Please help me, I'm a noob :D


It wouldn't just be pascal, it's general mathematics. I apologise for the misnaming of my initial parameters (as I had thought those coordinates were relative bank screen coordinates). Please refer to the latest update (thread edit) for a revised version reflecting the parameter name changes.

P.S: Don't forget, row's and columns start at 0, 0 (NOT 1, 1!). :)

darklordnd

2011-12-25 06:53:10

From: Daniel
Please refer to the latest update (thread edit) for a revised version reflecting the parameter name changes.

sorry, but I don't understand what you're saying. where is the thread you talked about? could you make it clear for me as what to do? thank you very much.

Jhangir

2011-12-25 12:25:17

Nice this could be a substitute for DTM's

Wizzup?

2011-12-25 20:07:41

Looks good to me.

darklordnd

2011-12-26 02:00:39

yeah, i'd say this is what I really want simba to include in the library. but anyone help me with the problem yet…

Daniel

2011-12-26 04:56:09

From: darklordnd
sorry, but I don't understand what you're saying. where is the thread you talked about? could you make it clear for me as what to do? thank you very much.


A forum is divided into categories and sub-forums. Within each sub-forum are threads (a.k.a topics) which initiate different areas/aspects of conversation. By "the thread", I was referring to this thread, that is, the original (first) post of this thread.

In my first post, you will notice that I had edited the code within [simba] tags, specifically the second function. I had replaced the parameters (values) x and y, to Row and Col, which is more appropriate and prevents further confusion.

Now you will see that instead of x and y, it is Row and Col. So, please use that format to find your item's amount in the bank. And don't forget, the first slot in the bank is 0, 0 (that is, row 0 and column 0).

If you are having any more troubles, please let me know. :)

darklordnd

2011-12-26 08:33:20

as I say, I tried swapping those, but the result is still zero. If it's a mistake of row and col, it should return some other value instead. So I still can't find out why my script doesn't work.

darklordnd

2011-12-30 07:22:19

anyone come up with a solution to help me yet?

Daniel

2011-12-30 08:20:09

From: darklordnd
anyone come up with a solution to help me yet?


Have you tried initially finding the object in the bank via a DTM and parsing those coordinates to the other function?

It could be a problem in converting a bank point into a main screen point now that tabbing exists. :-/

EDIT: If you don't want to do the above, switch to the tab (not the main one) where the item you are searching for exists.

DemiseScythe

2011-12-30 09:04:21

From: Jhangir
Nice this could be a substitute for DTM's


You still need to find the coordinates of the item. I totally love this method and it is key on one of my most precious scripts.

Thank you Daniel for developing this and it works great ^.^

This does not replace DTMs, you need to use Item finding method to get x and y of the item, then do something like this

Integer := GetMSBankItemAmount(x, y);

and it should work. That above is how to correctly set up this method in case anyone is wondering =)

Coh3n

2011-12-30 22:37:26

Added to my commit list. :) Will edit when committed.

E: Committed to SRL5. Will push later tonight.