ID:2536181
 
(See the best response by Kaiochao.)
Code:
obj/Equipment
DblClick(atom/A)
if(src in istype(A,/mob/NPC/Shopkeeper))
src.Move(usr)
return


Problem description:
So I am trying to design a statpanel based shopping system like mystic journey did. I found a library on BYOND that helped me figure out how to display equipment in the statpanel when you are close to the mob.

Now I am trying to set it up so if the equipment in question is being carried by a shopkeeper NPC, double clicking it triggers the exchange. I am doing this because I also have double clicking linked to other features for equipment when you are carrying it.

I'm sure that there's other things I am doing wrong here, or even abusing usr, but right now I'd just like to figure out how to do this check properly. Thanks.

I haven't tested it, but you could reference the shopkeeper somewhere like so.

var mob/NPC/Shopkeeper/Shop1

obj/Equipment/DblClick()
if(src in Shop1.contents)
usr.contents += new src.type
Thanks, I gave that a go. But it's not working. Also, I don't want to make a new item, but actually transfer the item itself from the NPC to the player, so that NPCs can run out of stuff to sell over time.

I ended up just checking to see if it's in a player's inventory and if not, then transfers it to the player. Although since I am planning on having seperate pawn shops, I'd really like a way to differentiate between types of mobs.
When you're checking for a shop around you to display the shop, you could use that chance to set a reference for your mob to allow for DblClick() to know which shop that item belongs so that you can use src.Move(usr)
Best response
The "loc" variable is a direct reference to the object holding the item. You can use it in istype to check its type like so:
if(istype(loc, whatever))

Or if you want to check if it is inside a specific object, it's better to do this:
if(loc == Shop1)

The "A in B" operator involves a search for A inside the contents of B, which is slower than a simple equality check.