Page 1 of 1

&ISCARRIED

Posted: Mon Jul 09, 2007 8:57 pm
by Zyx
I'd need a function like &ISCARRIED (char# ID_item TYPE_item)
that would return how many targeted items are carried by a character, including chest's content.

char#: 0-3 to choose one of the character, 4 for the leader, 5 for the whole party

ID_item: if non-zero, look for a specific item
TYPE_item: if non-zero, scan for a type of item. The return value may thus be greater than 1.

Posted: Mon Jul 09, 2007 9:45 pm
by Paul Stevens
How about this:

Code: Select all

&ISCARRIED   ( CHAR#  ID  . . . num )

Searches a character's inventory. The search is
recursive. That is chests are searched and any
monsters found in the chests are searched and
any possessions of those monsters are searched, etc.
The search includes the cursor if the leader is
included in the search.

char#: 0-3 to choose one of the character, 4 for the leader, 5 for the whole party

Non-negative ID is the identifier for a particular object.
For example, a particular apple....the one found
in the northern corner of the supplies area.

If ID is non-negative then the return value is
-1 or the character number and the location on
that character where the item is carried. These
are encoded as 256*char + pos. If the object is
found in the cursor then the position is 255.

If ID is negative then it represents an object type.
For examplem any apple. The return value is the
number of items of type -ID being carried by that
character.

See "enum OBJECTTYPE" and
"BODY POSITIONS" at:
http://www.dianneandpaul.net/CSBwin/doc ... tants.html

Posted: Mon Jul 09, 2007 10:31 pm
by Zyx
It would be perfect.

Posted: Tue Jul 10, 2007 3:27 pm
by Paul Stevens
CSBuild 252.exe
CSBwin10_008.exe

Posted: Wed Jul 18, 2007 1:54 pm
by Adamo
&ISCARRIED L5 L-50002 L0 L1 L0||1

would that look if the whole party (5) carries a torch (negative ID num 2 /torch/ + 50000 /weapontype/) either in left or right hand (0||1) ?

Posted: Wed Jul 18, 2007 4:17 pm
by Paul Stevens
THere appears to be a lot of confusion in your
example.

&ISCARRIED needs two parameters. You provided
none. Perhaps you meant to put the 'L5' before
the '&ISCARRIED'.

L5 &ISCARRIED L-50002 L0 L1 L0||1

The '5' is to search the entire party.
Now we are only one parameter short.

You meant the 'L-50002' to be the type
so let us move that before the '&ISCARRIED'.

L5 L-50002 &ISCARRIED L0 L1 L0||1

You mention torches. If you look at the
'enum OBJECTTYPE' in the documentation
as noted above, you will see that torches
have types:

Code: Select all

  obj_Torch_a,        //4  4
  obj_Torch_b,        //5  5
  obj_Torch_c,        //6  6
  obj_Torch_d,        //7  7
What the documentation does not say is that
when there are several options (such as for
torches) only the first is useful. It is what the
code refers to as the 'basic object type'. All
others are converted to this 'basic' type' for the
purposes of '&ISCARRIED'. So you can only
determine if a torch is carried, not whether a
particular type of torch is carried. So let us use
'torch' as the object type in your example.

L5 L-4 &ISCARRIED L0 L1 L0||1

Of course, th 'L-4' will not work. But we
can put a positiv number there and negate it.

L5 L4 &NEG &ISCARRIED L0 L1 L0||1

After the '&ISCARRIED' The stack will contain
the number of torches carried by the party.
It appears that you wanted to determine whether
the torches were in the hands of the characters
rather than in, for example, the backpacks. But,
as the discussion above reveals, when you ask
about a general class of objects (torches, screamer
slices, daggers, etc., for example), the function
returns the number of such objects. It does not
provide the location of those objects. And, if you
think about it, how could it -- since there could be
dozens of the objects in various locations. So, whatever
your code was intended to accomplish, it cannot
determine if the torches were in the character's
hands by using this method.

I think you had better simply look in each
character's two hands to see if there is a torch
there. That is only 8 very quick operations
every couple of seconds and will not contribute
much overhead.

Another problem that you may have overlooked:
What if the torch is in a chest and the chest is
in the character's hand. '&ISCARRIED' will report
the position of the torch as the character's hand.

Posted: Wed Jul 18, 2007 5:19 pm
by Paul Stevens

Posted: Wed Jul 18, 2007 6:39 pm
by Adamo
whoops! :oops: I`m learning DSAs very slowly, sorry for the confusion! :oops:
how many targeted items are carried by a character
ooh, I just realized Zyx wanted to know the number of items of one type carried by a character..! My goal is to get know if the character carries object X on location Y (here: search handL and handR positions for the torches).. It seems I missunderstood a &ISCARRIED function a bit..
I think you had better simply look in each
character's two hands to see if there is a torch
there. That is only 8 very quick operations
every couple of seconds and will not contribute
much overhead.
so the &ISCARRIED woundn`t fit here?
it seems &CHPOSS looks for object ID, not for the object type in general..

Code: Select all

  &CHPOSS(<char num> <index> ...<objectID>)
            <char num> = 0 to 3; <index = 0 to 29>
            <char num> == 4 means 'Active Character'
            <char num> == -1 means object in cursor
can I use enumOBJECTTYPE value like this:
L0 L0 &CHPOSS L4
L0 L1 &CHPOSS L4
L1 L0 &CHPOSS L4
...etc ?

Posted: Wed Jul 18, 2007 8:10 pm
by Zyx
L0 L0 &CHPOSS &DUP &TYPE L4 &= ?GC0
L0 L1 &CHPOSS &DUP &TYPE L4 &= ?GC0
L1 L0 &CHPOSS &DUP &TYPE L4 &= ?GC0
L1 L1 &CHPOSS &DUP &TYPE L4 &= ?GC0
L2 L0 &CHPOSS &DUP &TYPE L4 &= ?GC0
etc.

would execute line C0 each time a torch is found, with the ID of the torch as the last value of the stack

Posted: Wed Jul 18, 2007 10:30 pm
by Paul Stevens
Or, noticing that the last several instructins on
each line are identical:

0S0:
L0 L0 &GC0
L0 L0 &GC0
L1 L0 &GC0
L1 L1 &GC0
L2 L0 &GC0
etc.

0C0: &CHPOSS &DUP &TYPE L4 &= ?GT0

0T0: ( torch id )

would execute line T0 each time a torch is found, with the ID of the torch as the last value of the stack