ID:2131934
 
(See the best response by Ter13.)
client/var/equipped_helm=0
mob/var/helmet
client

MouseDrag(src_object, over_object, src_location, over_location, src_control, over_control, params)

if(!(src in usr.contents))return


MouseDrop(src_object, over_object, src_location, over_location, src_control, over_control, params)
if(src in usr.contents)
if(over_object == /obj/hud/Helmet)
if(!usr.helmet)
usr.helmet=src
equipped_helm=1
new src_object
if(over_location == null)
if(!equipped_helm)
switch(alert("Are you sure you want to drop [src]?","Drop [src]","Drop it","Cancel"))
if("Drop it")
src_location = locate(usr.x,usr.y,usr.z)
else return
else
usr << "You cannot drop [src] while it is equipped!"
return


Problem description:For the life of my i cannot figure out why it wont drop the src over my hud object and display the icon over it, can anyone provide any insight please? no compile errors or runtime

Best response
There's a lot going wrong here.

if(src in usr.contents)

This will never be true, because src is the client that dropped the item.

Let's take a look at how to do this properly.

client/MouseDrop() is called when any object is dropped after a drag operation. Its default action is to call atom/MouseDrop() on the object being dropped.

obj/item/equipment
var
tmp/slot
eqipped

proc
Equip(mob/user,obj/hud/equip/e)
e.overlays += src
slot = e
user.equipment[e.slot] = src
equipped = 1

Unequip(mob/user)
equipped = 0
var/obj/hud/equip/e = slot
e.overlays -= src
slot = initial(slot)
user.equipment[slot] = null

Drop(mob/user,turf/location)
Move(location)

PickUp(mob/user)
Move(user)

MouseDrop(atom/over_object,atom/src_location,atom/over_location,src_control,over_control,params)
if(loc==usr&&istype(over_object,/obj/hud/equip)&&over_object:slot==slot) //make sure the item is in the user, the over_object is an equip slot, and the slot is the correct type for the item
if(!usr.equipment[slot]) //if the user doesn't already have one of these equipped
Equip(usr,over_object)
else if(isturf(over_location)) //if we're dropping it on the map
if(equipped) //unequip if equipped
Unequip(usr)
Drop(usr,over_location)

obj/hud/equip
var
slot

MouseDrop(atom/over_object,atom/src_location,atom/over_location,src_control,over_control,params)
var/obj/item/equipment/i = usr.equipment[slot] //make sure the item exists
if(i)
if(over_object==usr||over_control=="statpanel") //if we're dragging the slot over the player or the statpanel
i.Unequip(usr)
else if(isturf(over_location)) //if we're dragging the slot over a location on the map
i.Unequip(usr)
i.Drop(usr,over_location)


Also, a few finer points:

over_object == /obj/hud/Helmet

A type path is never equal to an object. You can check if an object is a type of something with istype().

(src in usr.contents)

src in usr.contents should never be done, because all atoms have a variable called loc. if(loc==usr) is significantly faster.

src_location = locate(usr.x,usr.y,usr.z)

You aren't actually moving the object. src.loc = locate(usr.x,usr.y,usr.z) would be changing the loc of the object. You are just changing an argument in the Drop proc. Second, you don't need locate(usr.x,usr.y,usr.z), you already have the location you are trying to locate, so you can just do: loc = usr.loc. However, this is still wrong. You never want to manually assign the location of anything in DM unless you want to lose the ability to use Cross()/Uncross()/ed and Enter()/Exit()/ed functions. You should ALWAYS use Move() to move things or you risk making in-out trackers nonfunctional and eliminating algorithms that are amazingly easy and fast to solve a lot of really complex/irritating problems otherwise.
In response to Ter13
ok i see just how bad what i did is...but the slot var is throwing me off..can you explain how it handles which slot its over as a temp var? im sure its simple and im just looking blindly, gonna read back over some ref's im missing something. I greatly appreciate your help
It was more of an example.

Here's how I pictured the equipment slotting working:

mob
var
list/equipment = list()
tmp/list/equip_slots

Login()
. = ..()
setupHud()
proc
setupHud()
equip_slots = list("head"=new/obj/hud/equip("head","1,1",src),
"body"=new/obj/hud/equip("body","2,1",src),
"feet"=new/obj/hud/equip("feet","3,1",src))

obj/hud/equip
New(slot,sloc,mob/owner)
src.slot = slot
src.screen_loc = sloc
var/obj/item/i = owner.equipment[slot]
if(i)
overlays += i
i.slot = src
owner.client.screen += src


Basically, the reason I marked the slot variable temporary is so that I can keep track of the hud object that the item is attached to when equipped from the item, as well as not actually save this link when the mob is dumped to a savefile. There isn't a lot of purpose here, it's just a method for keeping track of the slot during the game session without saving the link between item and slot.

Since the links and slots aren't saved, you have to regenerate them either when the object is loaded from a savefile, which can be irritating, or on the login of the client --which is actually probably a better bet for most RPG-style games.
ok i didn't know you could procs in list i thought it was for base text only thats gonna make it alot easier for stuff i had in mind i appreciate the help Ter13 i know my questions are beginner stuff but thanks for baring with me as i learn, seeing the way you wrote this up is alot more slim line than what i have been doing