entity sandbox_EditObject_Get()
{
// returns the traced entity if the player can edit it, and world if not
+ // attached objects are SOLID_NOT and don't risk getting traced
makevectors(self.v_angle);
WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_edit, MOVE_NORMAL, self);
void sandbox_AttachObject_Set(entity e, entity parent, string s)
{
+ // attaches e to parent on string s
+
e.movetype = MOVETYPE_FOLLOW;
e.solid = SOLID_NOT;
e.takedamage = DAMAGE_NO;
- setorigin(e, parent.origin);
setattachment(e, parent, s);
e.owner = parent;
}
void sandbox_AttachObject_Remove(entity e)
{
- e.movetype = MOVETYPE_TOSS;
- e.solid = SOLID_BBOX;
- e.takedamage = DAMAGE_AIM;
+ // detaches any object attached to e
+
+ entity head;
+ for(head = world; (head = find(head, classname, "object")); )
+ {
+ if(head.owner == e)
+ {
+ head.movetype = MOVETYPE_TOSS;
+ head.solid = SOLID_BBOX;
+ head.takedamage = DAMAGE_AIM;
+
+ setattachment(head, world, "");
+ head.owner = world;
- setattachment(e, world, "");
- e.owner = world;
+ // objects reset origin and angles when detached, so apply the parent's to prevent teleporting
+ setorigin(head, e.origin);
+ head.angles = e.angles;
+ }
+ }
}
entity sandbox_SpawnObject()
e = sandbox_SpawnObject();
sandbox_Storage_Load(e, self.object_clipboard);
- print_to(self, "Object pasted");
+ print_to(self, "Object pasted successfully");
if(autocvar_g_sandbox_info)
print(strcat(self.netname, " pasted an object at origin ", vtos(e.origin), "\n"));
// select e as the object as meant to be attached
e = sandbox_EditObject_Get();
if(e != world)
+ {
self.object_attach = e;
+ print_to(self, "Object selected for attachment");
+ return TRUE;
+ }
+ print_to(self, "WARNING: Object could not be selected for attachment. Make sure you are facing an object that belongs to you");
return TRUE;
case "set":
+ if(self.object_attach == world)
+ {
+ print_to(self, "WARNING: No object selected for attachment. Please select an object to be attached first.");
+ return TRUE;
+ }
+
// attaches the previously selected object to e
e = sandbox_EditObject_Get();
if(e != world)
+ {
sandbox_AttachObject_Set(self.object_attach, e, argv(3));
+ print_to(self, "Object attached successfully");
+ self.object_attach = world; // object was attached, no longer keep it scheduled for attachment
+ return TRUE;
+ }
+ print_to(self, "WARNING: Object could not be attached to the parent. Make sure you are facing an object that belongs to you");
return TRUE;
case "remove":
// removes e if it was attached
e = sandbox_EditObject_Get();
if(e != world)
+ {
sandbox_AttachObject_Remove(e);
+ print_to(self, "Child objects detached successfully");
+ return TRUE;
+ }
+ print_to(self, "WARNING: Child objects could not be detached. Make sure you are facing an object that belongs to you");
return TRUE;
}
return TRUE;