X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fmutators%2Fsandbox.qc;h=ff98edbf260ee42ef6997dcc9df370357f572bc8;hb=bf1241a54bc8d6c5c7c2d026ea0789fe9043459b;hp=24b11abefba7c57fcd7a19bf65abb66e0cedd1b2;hpb=d77ac081081f03dc2ea725b9762127d732a1f25a;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/mutators/sandbox.qc b/qcsrc/server/mutators/sandbox.qc index 24b11abef..ff98edbf2 100644 --- a/qcsrc/server/mutators/sandbox.qc +++ b/qcsrc/server/mutators/sandbox.qc @@ -54,6 +54,7 @@ void sandbox_Object_Touch() 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); @@ -75,23 +76,37 @@ void sandbox_EditObject_Scale(entity e, float f) 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() @@ -293,7 +308,7 @@ MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand) 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")); @@ -307,19 +322,41 @@ MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand) // 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;