ID:1517439
 
(See the best response by Ter13.)
Code:
mob/verb/Inventory()
winshow(src,"Inventory",1) //Show the inventory window!
var/Position = winget(src, "default", "pos") // Get the position of the "default" window and assign it to a var called "Position"
winset(src,"Inventory","pos='[Position]'") // Set the position of the "Inventory" window to the same position as our main window.
src.client.screen = null //Clear the inventory before generating everything inside.
for(var/Column = 1 to 5) for(var/Row = 1 to 7) //Create a grid composed of 5 columns and 5 rows.
var/Grid/G = new
G.screen_loc = "inv:[Row],[Column]"
src.client.screen += G
for(var/obj/I in src.contents) src.AddItems(I) //Generate the items on slots.
for(var/Column = 1 to 3) for(var/Row = 1 to 3) //Create a grid composed of 5 columns and 5 rows.
var/Grid/G = new
G.screen_loc = "eqp:[Row],[Column]"
src.client.screen += G




mob/proc/AddItems(obj/I)
for(var/Grid/G in src.client.screen)
if(G.used) continue
if(!I.screen_loc) //only set if it doesn't have a screen location.
//if picking up a new object, you'll want to set it to null
I.screen_loc = G.screen_loc
src.client.screen+=I
G.used =1
return




obj/items
MouseDrag()// When we drag it...
var/obj/O = src

var/icon/I = new(src.icon,src.icon_state)//this is so the cursor icon transforms into the item itself...cool little effect.
mouse_drag_pointer = I // now lets set the mouse cursor to that.
if(O.screen_loc=="inv:1,1")
usr << "Testing"


Problem description:
I'm having troubles trying to figure out how to refer to an objects original location when using the MouseDrag(). I'd like to get it to be able to change a variable once the object has been moved, dependant on what the frst location of the object was. Such as in the example above, "inv:1,1" being the start.

(I did not write all of this code, and in no way claim it to my self.)
You should take a second look at what MouseDrag() actually does.

Dragging the object doesn't change the object's original position. Nor does dropping it. In other words, the item's original location will be the same location as when it started, when MouseDrop() is called.
Thanks. After looking it up, I found two things upon which I can refer to for the previous location on the grid.
src_location
//and
src_control
Now when I try using either, I cannot seem to figure out how to "Correctly" use it.
    MouseDrop(over_object=src,src_location,over_location, src_control,over_control,params)




for(var/obj/I in src.contents) usr.AddItems(I) //Generate the items on slots.




var/obj/O = over_object
var/obj/L = src_control//I think I may have made an error here
if(over_control == "Inventory.inv")

if(O.screen_loc=="inv:1,1")
if (usr.s1_1==0)
src.screen_loc = O.screen_loc
usr.s1_1+=1
if(L.screen_loc=="inv:1,2")//Or I may have made an error here
usr << "Something is working?"
Any Idea of what I am doing wrong? I greatly appreciate the help by the way.
Best response
You are mixing up client/MouseDrop and atom/MouseDrop. In addition, you are abusing the arguments badly.

obj/item
MouseDrop(atom/over_object,src_location,over_location,src_control,over_control,params)
if(over_object)
//this object is being dropped over another atom
if(istype(over_object,/turf))
//this object is being dropped on the ground somewhere on the map
else if(istype(over_object,/atom/movable))
//this object is being dropped on top of another mob or object... MIGHT be on the map. Not sure yet.
if(istype(over_location,/turf))
//this object is being dropped onto the map
else
//this object is being dropped onto an interface control somewhere.
else
//this object is being dropped into the interface somewhere


Okay, so now we know how to check out the data involved in a MouseDrop operation.

These are pretty much all of the possible scenarios (Unless you have areas visible for some reason or another.) that could arise from a MouseDrop action.

We can start to set up rules for our mousedrags/drops now:

1) When dragging an item over a turf on the map, we drop the item on the ground.

2) When dragging an item over a mob on the map, we throw the item at the mob.

3) When dragging an item over an obj on the map, we allow the object to decide what to do with it.

4) When dragging an item from the ground into the inventory panel, or over an item in the inventory panel, we move the item into the first empty space in the inventory, or an empty space the item was dropped into.

5) When dragging an item from the inventory panel over another item in the inventory panel, we swap the items' positions.


var
obj/hud/inventorybg/inventorybg = new()

atom
proc
ItemDropped(mob/combatant/player/p,obj/item/i)
movable
proc
Moved(atom/oldloc,odir=0)
Move(atom/nloc,dir=0,sx=0,sy=0)
var/atom/oloc = src.loc
var/odir = src.dir
. = ..()
if(.)
Moved(oloc,odir)

mob/combatant/player
var
list/inventory[20]
Login()
. = ..()
buildInventory()
proc
buildInventory()
src.screen += inventorybg

for(var/pos=1;pos<=src.inventory.len;pos++)
i.slot = pos
i.screen_loc = "InventoryMap:[(pos-1)%5 + 1],[4 - round((pos - 1) / 5)]"
src.client.screen += i

ThrowItem(obj/item/i,atom/target)
missile(i.icon,src,target)
i.Move(null)
spawn(get_dist(src,target))
i.Move(locate(target.x,target.y,target.z))

GetItem(obj/item/i,pos=null)
if(pos==null)
for(pos=1;pos<=inventory.len;pos++)
if(inventory[pos]==null)
break
if(inventory[pos]!=null) return 0

i.Move(src)
i.slot = pos
i.screen_loc = "InventoryMap:[(pos-1)%5 + 1],[4 - round((pos - 1) / 5)]"
src.client.screen += i

CanTouch(obj/item/i)
if(get_dist(i,src)<=2)
return 1
return 0

DropItem(obj/item/i,turf/t)
if(get_dist(t,src)<=2)
i.Drop(src,t)

ItemDropped(mob/combatant/player/p,obj/item/i)
if(p==src)
GetItem(i)
else
p.ThrowItem(i,src)

obj
hud
inventorybg
screen_loc = "InventoryMap:1,1 to 5,4"

ItemDropped(mob/combatant/player/p,obj/item/i,sloc)
sloc = copytext(sloc,length("InventoryMap:")+1,0)
var/sx = text2num(copytext(sloc,1,findtext(sloc,":",1,0)))
. = findtext(sloc,",",1,0)
var/sy = text2num(copytext(sloc,. + 1,findtext(sloc,":",. + 1,0)))
var/ipos = (4 - sy) * 4 + sx

if(p.inventory[ipos]==null) //pick up item and put in specific empty slot
p.GetItem(i,ipos)
else if(i.loc != p) //pick up the item and put in first empty slot
p.GetItem(i)
else if(p.inventory[ipos]!=i) //swap the items
var/obj/item/oi = p.inventory[ipos]
p.inventory[ipos] = i
p.inventory[i.slot] = oi
sloc = oi.screen_loc
oi.screen_loc = i.screen_loc
i.screen_loc = sloc
oi.slot = i.slot
i.slot = ipos

turf
ItemDropped(mob/combatant/player/p,obj/item/i)
p.DropItem(i,src)


obj
item
var
slot = 0
MouseDrop(atom/over_object,src_location,over_location,src_control,over_control,params)
if(over_object)
if(over_object==inventorybg||(over_location=="InventoryMap" && istype(over_object,/obj/item))
if(inRange(usr))
var/list/l = params2list(params)
inventorybg.ItemDropped(usr,src,l["screen-loc"])
else if(istype(over_location,/turf)||(over_location=="map1"&&istype(over_object,/turf)))
src.DropOn(usr,over_object)
proc
Drop(mob/combatant/player/p,turf/dloc)
src.Move(dloc)

DropOn(mob/combatant/player/p,atom/movable/o)
if(get_dist(p,o) <= 6)
o.ItemDropped(p,src)

inRange(mob/combatant/player/p)
if(p.canTouch(src))
return 1
return 0

Move(atom/nloc,dir)
if(nloc==null)
var/atom/ol = src.loc
var/list/l
if(istype(src.loc,/turf))
l = bounds(src)
. = 1
for(var/atom/movable/o in l)
. = . && l.Uncross(src)
. = . && o.Exit(src,null)
if(.)
src.loc = null
ol.Exited(src)
if(l)
for(var/atom/movable/o in l)
o.Uncrossed(src)
src.Moved(ol,src.dir)
else
Bump(null)
return 0
else
. = ..(nloc,dir)

Moved(atom/oloc,odir)
. = ..()
if(istype(oloc,/mob/combatant/player))
var/mob/player/p = oloc
p.inventory[slot] = null
p.client.screen -= src
src.screen_loc = null


This might be a bit advanced for you, but it should at least show you how to get information about all this stuff. There might also be errors. I wrote this one from the hip pretty fast.
I'd like to expand on this point a bit.

Notice how I simply used MouseDrop() to define the scenarios that could arise from the drop?

That's because I want this behavior to be flexible, and not have to rewrite huge portions of it all over the place.

I've also defined ItemDropped() under atom to create a generic hook, so we can define behavior for anything we want.

Let's say we have a quest mob that wants a certain number of a specific item? You can define the item accept behavior on the quest mob without changing a thing in the item code.

Since we hook from the item, to the over_object, to the player, back to the item, we can change all three functions in certain situations, allowing for all three of the objects to modify the behavior in those specific situations. This is a very modular approach to the problem, and will give you a lot of legroom for clean, expandable code.
Thank you for the help. After doing a bit more research into the "screen_loc" part of the MouseDrop() I came upon the desired reaction. :]