]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/mutators/sandbox.qc
Allow editing the object's skin too. Add both skin and frame to the copied clipboard...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / sandbox.qc
index e5e2799fc924046a05170bf58582b4adb51d0915..36d1db83c2bdb4d5af35909f604e638397ae87ea 100644 (file)
@@ -22,7 +22,7 @@ entity sandbox_SpawnObject()
        e.classname = "object";
        e.takedamage = DAMAGE_NO;
        e.movetype = MOVETYPE_TOSS;
-       e.solid = SOLID_BSP;
+       e.solid = SOLID_BBOX; // SOLID_BSP would be best, but can lag the server badly
 
        // set origin and direction based on player position and view angle
        makevectors(self.v_angle);
@@ -54,6 +54,10 @@ MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand)
                        print_to(self, "^7\"^2remove_object^7\" removes the object the player is looking at. Players can only remove their own objects");
                        print_to(self, "^7\"^2duplicate_object_copy^7\" copies the object the player is looking at. Players can only copy their own objects");
                        print_to(self, "^7\"^2duplicate_object_paste^7\" pastes the copied object in front of the player");
+                       print_to(self, "^7\"^2edit_object ^3property value^7\" edits the given property of the object. Players can only edit their own objects");
+                       print_to(self, "^7Object properties for ^2edit_object^7:");
+                       print_to(self, "^3skin ^7- changes the skin of the object");
+                       print_to(self, "^3frame ^7- object animation frame, for self-animated models");
                        print_to(self, "^7The ^1drag object ^7key can be used to grab and carry objects. Players can only grab their own objects");
                        return TRUE;
                }
@@ -131,9 +135,10 @@ MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand)
                        e = sandbox_EditObject(); // you can only copy objects you can edit, so this works
                        if(e != world)
                        {
-                               if(self.object_clipboard != "") // unzone the player's clipboard if it's not empty
+                               // set clipboard properties
+                               if(self.object_clipboard)
                                        strunzone(self.object_clipboard);
-                               self.object_clipboard = strzone(strcat(e.model, " ", ftos(e.movetype)));
+                               self.object_clipboard = strzone(strcat(e.model, " ", ftos(e.skin), " ", ftos(e.frame), " ", ftos(e.movetype)));
 
                                print_to(self, "Object copied to clipboard");
                                return TRUE;
@@ -146,7 +151,7 @@ MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand)
                {
                        // spawns a new object using the properties in the player's clipboard
 
-                       if(self.object_clipboard == "") // no object in clipboard
+                       if(!self.object_clipboard) // no object in clipboard
                        {
                                print_to(self, "WARNING: No object in clipboard. You must copy an object before you can paste it");
                                return TRUE;
@@ -155,8 +160,11 @@ MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand)
                        e = sandbox_SpawnObject();
                        tokenize_console(self.object_clipboard);
 
+                       // apply clipboard properties
                        setmodel(e, argv(0));
-                       e.movetype = stof(argv(1));
+                       e.skin = stof(argv(1));
+                       e.frame = stof(argv(2));
+                       e.movetype = stof(argv(3));
 
                        print_to(self, "Object pasted");
                        if(autocvar_g_sandbox_info)
@@ -164,6 +172,30 @@ MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand)
 
                        return TRUE;
                }
+               else if(argv(1) == "edit_object")
+               {
+                       if(!argv(2) || !argv(3))
+                       {
+                               print_to(self, "WARNING: Too few parameters. You must specify a property to edit, followed by its value");
+                               return TRUE;
+                       }
+
+                       e = sandbox_EditObject();
+                       if(e != world)
+                       {
+                               if(argv(2) == "skin")
+                                       e.skin = stof(argv(3));
+                               else if(argv(2) == "frame")
+                                       e.frame = stof(argv(3));
+                               else
+                                       print_to(self, "WARNING: Invalid object property. For usage information, type 'sandbox help'");
+
+                               return TRUE;
+                       }
+
+                       print_to(self, "WARNING: Object could not be edited. Make sure you are facing an object that belongs to you");
+                       return TRUE;
+               }
                else
                {
                        print_to(self, "Invalid command. For usage information, type 'sandbox help'");
@@ -205,11 +237,13 @@ MUTATOR_HOOKFUNCTION(sandbox_PlayerPreThink)
 MUTATOR_HOOKFUNCTION(sandbox_ClientDisconnect)
 {
        // unzone the player's clipboard if it's not empty
-       if(self.object_clipboard != "")
+       if(self.object_clipboard)
        {
                strunzone(self.object_clipboard);
                self.object_clipboard = string_null;
        }
+
+       return FALSE;
 }
 
 MUTATOR_DEFINITION(sandbox)
@@ -218,5 +252,5 @@ MUTATOR_DEFINITION(sandbox)
        MUTATOR_HOOK(PlayerPreThink, sandbox_PlayerPreThink, CBC_ORDER_ANY);
        MUTATOR_HOOK(ClientDisconnect, sandbox_ClientDisconnect, CBC_ORDER_ANY);
 
-       return 0;
+       return FALSE;
 }