END_CHEAT_FUNCTION();
}
-float Drag(entity e, float candrag);
+float Drag(entity e, float grab);
void Drag_Begin(entity dragger, entity draggee, vector touchpoint);
void Drag_Finish(entity dragger);
float Drag_IsDraggable(entity draggee);
// ENTITY DRAGGING
-float Drag(entity e, float candrag)
+float Drag(entity e, float grab)
{
+ // returns TRUE when an entity has been picked up
+ // If grab is TRUE, the object can also be picked up if it's not being held already
+ // If grab is FALSE, only keep dragging the object if it's already being held
+
if(Drag_IsDragging(self))
{
if(self.BUTTON_DRAG)
else
{
if(Drag_CanDrag(self))
- if(self.BUTTON_DRAG && candrag)
+ if(self.BUTTON_DRAG && grab)
{
if(e)
if(Drag_IsDraggable(e))
}
}
-
-
-
-
-
void DragBox_Think()
{
if(self.aiment && self.enemy)
void Drag_MoveDrag(entity from, entity to); // call this from CopyBody
-float Drag(entity e, float candrag); // used by sandbox code
\ No newline at end of file
+float Drag(entity e, float grab); // used by sandbox code
\ No newline at end of file
// if the player is close enough to their own object and facing it, they can grab it
if(autocvar_sv_cheats)
- return FALSE; // cheats already allow dragging all objects
+ return FALSE; // cheat dragging is used instead
+ float grab;
crosshair_trace_plusvisibletriggers(self);
- float candrag;
+ // grab is TRUE if the object can be picked up. While an object is being carried, the Drag() function
+ // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace.
+ // This also makes sure that an object can only pe picked up if in range, but does not get dropped if it goes
+ // out of range while slinging it around.
+
if(trace_ent.classname == "object" && trace_ent.realowner == self && vlen(trace_ent.origin - self.origin) <= autocvar_g_sandbox_editor_distance_edit)
- candrag = TRUE; // object can be picked up
- if(Drag(trace_ent, candrag)) // execute dragging
+ grab = TRUE; // object can be picked up
+ if(Drag(trace_ent, grab)) // execute dragging
if(autocvar_g_sandbox_info)
print(strcat(self.netname, " grabbed an object at origin ", vtos(trace_ent.origin), "\n"));