diff --git a/code/datums/action.dm b/code/datums/action.dm
index f64a549b29..fd33ef79b5 100644
--- a/code/datums/action.dm
+++ b/code/datums/action.dm
@@ -494,6 +494,7 @@
else
to_chat(owner, "Your hands are full!")
+//MGS Box
/datum/action/item_action/agent_box
name = "Deploy Box"
desc = "Find inner peace, here, in the box."
@@ -502,21 +503,27 @@
icon_icon = 'icons/mob/actions/actions_items.dmi'
button_icon_state = "deploy_box"
var/cooldown = 0
- var/obj/structure/closet/cardboard/agent/box
+ var/boxtype = /obj/structure/closet/cardboard/agent
+//Handles open and closing the box
/datum/action/item_action/agent_box/Trigger()
- if(!..())
+ . = ..()
+ if(!.)
return FALSE
- if(QDELETED(box))
- if(cooldown < world.time - 100)
- box = new(owner.drop_location())
- owner.forceMove(box)
- cooldown = world.time
- owner.playsound_local(box, 'sound/misc/box_deploy.ogg', 50, TRUE)
- else
- owner.forceMove(box.drop_location())
+ if(istype(owner.loc, /obj/structure/closet/cardboard/agent))
+ var/obj/structure/closet/cardboard/agent/box = owner.loc
+ owner.playsound_local(box, 'sound/misc/box_deploy.ogg', 50, TRUE)
+ box.open()
+ return
+ //Box closing from here on out.
+ if(!isturf(owner.loc)) //Don't let the player use this to escape mechs/welded closets.
+ to_chat(owner, "You need more space to activate this implant.")
+ return
+ if(cooldown < world.time - 100)
+ var/box = new boxtype(owner.drop_location())
+ owner.forceMove(box)
+ cooldown = world.time
owner.playsound_local(box, 'sound/misc/box_deploy.ogg', 50, TRUE)
- QDEL_NULL(box)
//Preset for spells
/datum/action/spell_action