SRL Archive - OSR Help

DTM to item slot locating


Flight

2011-02-25 09:34:01

This is kinda hard for me to explain so I'll give an example.

In my script, I use FindDTM to determine if I have a certain item within my inventory tab. I want to use that information to determine in which inventory slot it's in in order to use "Dropitem(i)", and "i" being the item's DTM that was located.

I haven't looked into how SRL determines inventory slots, maybe it's based on a set X/Y parameter, if so then could you not grab the x/y coords of the DTM and match it to the inventory's slot x/y parameter to determine which slot it's in?

Also, same question but for bitmaps as well.

TomTuff

2011-02-25 09:45:00

procedure DropIt;
var
TheDTM, i: Integer;
Box: TBox;
begin
TheDTM := DTMFromString('asdfhiosd');
for i := 1 to 28 do
begin
Box := InvBox(i);
if FindDTM(TheDTM, Box.X1, Box.Y1, Box.X2, Box.Y2) then
Break;
end;
FreeDTM(TheDTM);
DropItem(i);
end;

Flight

2011-02-25 09:54:57

Nice, I've never heard of TBox. Thanks bud.

Edit: "Invalid number of parameters at line 81"
This is line 81:
if FindDTM(TheDTM, Box.X1, Box.Y1, Box.X2, Box.Y2) then
I don't get it :/ Am I missing something?

Frement

2011-02-25 10:21:12

Possibly tolerance?

WT-Fakawi

2011-02-25 10:29:44

We also have the function InvBox. It Returns TBox of surrounding Inventory SlotBox
1-2-3-4
5-6-7-8
etc.

check out inventory.scar located in SRL/core

Flight

2011-02-25 10:38:42

From: WT-Fakawi
We also have the function InvBox. It Returns TBox of surrounding Inventory SlotBox
1-2-3-4
5-6-7-8
etc.

check out inventory.scar located in SRL/core


Yeah TomTuff had used it to define the "Box" parameters, but why would that be an invalid number of parameters when they're defined already? My logic tells me at the point "Box := InvBox(i);" then the Box.X1,Y1, ect… should be defined already.

Gu3st...

2011-02-25 10:45:17

You are missing 2 parameters, the X and Y variable is missing.

FindDTM(TheDTM, X, Y, Box.X1, Box.Y1, Box.X2, Box.Y2)

Flight

2011-02-25 10:50:51

Ha, leave it to Zyt3x to save the day. Although, that's not the error I'd expect for lack of variables. I thought it would return something like "Type mismatch". Thanks everyone for the help, and I apologize for the stupid questions.

WT-Fakawi

2011-02-25 10:52:03

From: Flight
I apologize for the stupid questions.
there are no stupid questions when you are stuck.

Gu3st...

2011-02-25 10:58:09

From: Flight
Ha, leave it to Zyt3x to save the day. Although, that's not the error I'd expect for lack of variables. I thought it would return something like "Type mismatch". Thanks everyone for the help, and I apologize for the stupid questions.
Haha, there's nothing to apologize for :)

In Simba you can do CTRL + Space to show information about what parameters you need ;)

I.E typing FindDTM + CTRL + Space will show "function FindDTM(DTM : Integer; var X, Y : Integer; xs, ys, xe, ye : Integer);" (or something similar to that)

Flight

2011-02-25 11:08:07

I wish I knew that a long time ago. :S To find out what parameters I need for a function I just go delete the first "(" following, then retype it to bring up the popup box that shows what variables the function is composed up, and that's what I've been relying on.

Flight

2011-02-25 12:48:03

Now I'm having trouble with this error:
** Warning in InvBox: Incorrect index: 29**
Warning! You passed a wrong xs to a finder function: -1. That is below 0, thus out of bounds. Setting the value to 0 for now.
Warning! You passed a wrong ys to a finder function: -1. That is below 0, thus out of bounds. Setting the value to 0 for now.
Here's the bit of code that's throwing the error:
if (Clicked = True) then
begin
for i := 1 to 28 do
begin
Box := InvBox(i);
if FindDTM(DTM,x,y,Box.X1,Box.Y1,Box.X2,Box.Y2) then
Break;
end;
FreeDTM(DTM);
if(DropItem(i)) then
Clicked := False;
end;
Any ideas of why it's trying to search for outside the 1-28 parameters for #29? Any ways the script works fine minus this error. If you have ideas please lemme know. I'll check back on this in the morning, I've had enough for one night.

Echo_

2011-02-25 13:41:33

You could try using this function instead:
{*******************************************************************************
function ExistsItemDTM(dtm: Integer; var x, y: Integer): Boolean;
By: NCDS
Description: Checks if the item with dtm is in the inventory. Returns the item's
coordinates.
*******************************************************************************}

MylesMadness

2011-02-25 13:50:26


if FindDTM(TheDTM, x, y, Box.X1, Box.Y1, Box.X2, Box.Y2) then
Item:=CoordsToItem(x, y);
FreeDTM(TheDTM);
DropItem(Item);

Gu3st...

2011-02-25 16:49:27

From: Flight
Now I'm having trouble with this error:
** Warning in InvBox: Incorrect index: 29**
Warning! You passed a wrong xs to a finder function: -1. That is below 0, thus out of bounds. Setting the value to 0 for now.
Warning! You passed a wrong ys to a finder function: -1. That is below 0, thus out of bounds. Setting the value to 0 for now.
Here's the bit of code that's throwing the error:
if (Clicked = True) then
begin
for i := 1 to 28 do
begin
Box := InvBox(i);
if FindDTM(DTM,x,y,Box.X1,Box.Y1,Box.X2,Box.Y2) then
Break;
end;
FreeDTM(DTM);
if(DropItem(i)) then
Clicked := False;
end;
Any ideas of why it's trying to search for outside the 1-28 parameters for #29? Any ways the script works fine minus this error. If you have ideas please lemme know. I'll check back on this in the morning, I've had enough for one night.
The reason why it goes to 29 is because it didn't find the dtm in any of those boxes. Doing what MylesMadness said with a tiny failsafe added to it would work:
if FindDTM(TheDTM, x, y, Box.X1, Box.Y1, Box.X2, Box.Y2) then
Item:=CoordsToItem(x, y);
FreeDTM(TheDTM);
if Item <> 0 then
DropItem(Item)
else
WriteLn('Didn''t find DTM');

Flight

2011-02-25 20:42:20

I'm not really sure why, but having adjusted it like you'd gave in your example it's dropping "all" my items. Never mind, I give up with using conventional methods, I'll create my own dtm locate/drop method. Thanks anyways :/

TomTuff

2011-02-25 21:03:14

From: Flight
I'm not really sure why, but having adjusted it like you'd gave in your example it's dropping "all" my items. Never mind, I give up with using conventional methods, I'll create my own dtm locate/drop method. Thanks anyways :/


It's because you don't break from the loop after you drop the item.

Flight

2011-02-25 21:17:04

Yeah I had forgotten about the Break; you used in your earlier example script, that's probably why, but I've used some other methods to make this world correctly now and it works perfectly now if I do say so myself. :P

Boreas

2011-02-26 01:23:16

If you search for something in the whole inventory and want to know which slot it is in, there should be something like CoordToItemSlot., kinda like the reverse of InvBox.

Flight

2011-02-26 01:34:20

Yes Boreas I found that function and that's what I'm using now, it works very well, thank you. :)

I noticed you're the one who wrote it to. :P

cycrosism

2011-02-26 01:47:38

Or you can just right click the DTM and ChooseOption('drop');

Boreas

2011-02-26 02:02:03

From: Flight
Yes Boreas I found that function and that's what I'm using now, it works very well, thank you. :)

I noticed you're the one who wrote it to. :P


No problem, I just noticed that Myles already mentioned it heh.