]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Allow copying and pasting of objects. This is done by saving each object's property...
authorMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Tue, 25 Oct 2011 11:29:33 +0000 (14:29 +0300)
committerMircea Kitsune <sonichedgehog_hyperblast00@yahoo.com>
Tue, 25 Oct 2011 11:29:33 +0000 (14:29 +0300)
qcsrc/server/mutators/sandbox.qc

index 5291ff280da82c37cb7730379b4e83036e89ad3b..9c32f0ae5e133a3c9457dbffc7ecdd8b03c9b866 100644 (file)
@@ -1,3 +1,5 @@
+.string clipboard_model;
+
 entity sandbox_EditObject()
 {
        // returns the traced entity if the player can edit it, and world if not
@@ -10,6 +12,27 @@ entity sandbox_EditObject()
                return world;
 }
 
+entity sandbox_SpawnObject()
+{
+       // spawn a new object with default properties
+
+       entity e;
+       e = spawn();
+       e.realowner = self;
+       e.classname = "object";
+       e.takedamage = DAMAGE_NO;
+       e.movetype = MOVETYPE_TOSS;
+       e.solid = SOLID_BSP;
+
+       // set origin and direction based on player position and view angle
+       makevectors(self.v_angle);
+       WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_spawn, MOVE_NORMAL, self);
+       setorigin(e, trace_endpos);
+       e.angles_y = self.v_angle_y;
+
+       return e;
+}
+
 MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand)
 {
        if(MUTATOR_RETURNVALUE) // command was already handled?
@@ -46,20 +69,8 @@ MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand)
                                return TRUE;
                        }
 
-                       // spawn a new object with default properties
-                       e = spawn();
-                       e.realowner = self;
-                       e.classname = "object";
-                       e.takedamage = DAMAGE_NO;
-                       e.movetype = MOVETYPE_TOSS;
-                       e.solid = SOLID_BSP;
-
-                       // set origin and direction based on player position and view angle
-                       makevectors(self.v_angle);
-                       WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_spawn, MOVE_NORMAL, self);
-                       setorigin(e, trace_endpos);
+                       e = sandbox_SpawnObject();
                        setmodel(e, argv(2));
-                       e.angles_y = self.v_angle_y;
 
                        if(autocvar_g_sandbox_info)
                                print(strcat(self.netname, " spawned an object at origin ", vtos(e.origin), "\n"));
@@ -111,6 +122,37 @@ MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand)
                        print_to(self, "WARNING: Object could not be removed. Make sure you are facing an object that belongs to you");
                        return TRUE;
                }
+               else if(argv(1) == "duplicate_copy")
+               {
+                       // copies the properties of the selected object to the clipboard
+
+                       e = sandbox_EditObject(); // you can only copy objects you can edit, so this works
+                       if(e != world)
+                       {
+                               // -------- COPY PROPERTIES --------
+                               self.clipboard_model = e.model;
+                               // -------- COPY PROPERTIES --------
+
+                               print_to(self, "Object copied to clipboard");
+                       }
+                       return TRUE;
+               }
+               else if(argv(1) == "duplicate_paste")
+               {
+                       // spawns an object with the properties in the player's clipboard
+
+                       e = sandbox_SpawnObject();
+
+                       // -------- PASTE PROPERTIES --------
+                       setmodel(e, self.clipboard_model);
+                       // -------- PASTE PROPERTIES --------
+
+                       print_to(self, "Object pasted");
+                       if(autocvar_g_sandbox_info)
+                               print(strcat(self.netname, " pasted an object at origin ", vtos(e.origin), "\n"));
+
+                       return TRUE;
+               }
        }
        return FALSE;
 }