1 .string clipboard_model;
3 entity sandbox_EditObject()
5 // returns the traced entity if the player can edit it, and world if not
7 makevectors(self.v_angle);
8 WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_edit, MOVE_NORMAL, self);
9 if(trace_ent.classname == "object" && trace_ent.realowner == self)
15 entity sandbox_SpawnObject()
17 // spawn a new object with default properties
22 e.classname = "object";
23 e.takedamage = DAMAGE_NO;
24 e.movetype = MOVETYPE_TOSS;
27 // set origin and direction based on player position and view angle
28 makevectors(self.v_angle);
29 WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_spawn, MOVE_NORMAL, self);
30 setorigin(e, trace_endpos);
31 e.angles_y = self.v_angle_y;
36 MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand)
38 if(MUTATOR_RETURNVALUE) // command was already handled?
40 if(cmd_name == "g_sandbox")
44 print_to(self, "Sandbox mode is active. For more information, use 'sandbox help'");
51 print_to(self, "You can use the following sandbox commands:");
52 print_to(self, "^7\"^2spawn_object ^3models/foo/bar.md3^7\" spawns a new object in front of the player, and gives it the specified model");
53 print_to(self, "^7\"^2spawn_item ^3item^7\" spawns the specified item in front of the player. Only weapons are currently supported");
54 print_to(self, "^7\"^2remove_object^7\" removes the object the player is looking at. Players can only remove their own objects");
55 print_to(self, "^7The ^1drag object ^7key can be used to grab and carry objects. Players can only grab their own objects");
58 else if(argv(1) == "spawn_object")
60 // don't allow spawning objects without a model
63 print_to(self, "WARNING: Attempted to spawn an object without specifying a model. Please specify the path to your model file after the 'spawn_object' command");
66 else if not(fexists(argv(2)))
68 print_to(self, "WARNING: Attempted to spawn an object with a non-existent model. Make sure the path to your model file is correct");
72 e = sandbox_SpawnObject();
75 if(autocvar_g_sandbox_info)
76 print(strcat(self.netname, " spawned an object at origin ", vtos(e.origin), "\n"));
80 else if(argv(1) == "spawn_item")
82 // only weapons are currently supported
86 print_to(self, "WARNING: Attempted to spawn an item without specifying its type. Please specify the name of your item after the 'spawn_item' command");
92 makevectors(self.v_angle);
93 WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_spawn, MOVE_NOMONSTERS, self);
95 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
97 e = get_weaponinfo(i);
98 if(e.netname == argv(2))
100 W_ThrowNewWeapon(self, i, FALSE, trace_endpos, '0 0 0');
101 if(autocvar_g_sandbox_info)
102 print(strcat(self.netname, " spawned a ^2", e.netname, "^7 at origin ", vtos(e.origin), "\n"));
107 print_to(self, "WARNING: Attempted to spawn an invalid or unsupported item. See 'sandbox help' for allowed items");
110 else if(argv(1) == "remove_object")
112 e = sandbox_EditObject();
115 if(autocvar_g_sandbox_info)
116 print(strcat(self.netname, " removed an object at origin ", vtos(e.origin), "\n"));
122 print_to(self, "WARNING: Object could not be removed. Make sure you are facing an object that belongs to you");
125 else if(argv(1) == "duplicate_copy")
127 // copies the properties of the selected object to the clipboard
129 e = sandbox_EditObject(); // you can only copy objects you can edit, so this works
132 // -------- COPY PROPERTIES --------
133 self.clipboard_model = e.model;
134 // -------- COPY PROPERTIES --------
136 print_to(self, "Object copied to clipboard");
140 else if(argv(1) == "duplicate_paste")
142 // spawns an object with the properties in the player's clipboard
144 e = sandbox_SpawnObject();
146 // -------- PASTE PROPERTIES --------
147 setmodel(e, self.clipboard_model);
148 // -------- PASTE PROPERTIES --------
150 print_to(self, "Object pasted");
151 if(autocvar_g_sandbox_info)
152 print(strcat(self.netname, " pasted an object at origin ", vtos(e.origin), "\n"));
160 MUTATOR_HOOKFUNCTION(sandbox_PlayerPreThink)
162 // if the player is close enough to their object, they can drag it
164 if(autocvar_sv_cheats)
165 return FALSE; // cheat dragging is used instead
167 // grab is TRUE if the object can be picked up. While an object is being carried, the Drag() function
168 // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace.
169 // This also makes sure that an object can only pe picked up if in range, but does not get dropped if
170 // it goes out of range while slinging it around.
175 e = sandbox_EditObject();
176 if(e != world && vlen(e.origin - self.origin) <= autocvar_g_sandbox_editor_distance_edit)
179 if(Drag(e, grab)) // execute dragging
181 if(autocvar_g_sandbox_info)
182 print(strcat(self.netname, " grabbed an object at origin ", vtos(e.origin), "\n"));
189 MUTATOR_DEFINITION(sandbox)
191 MUTATOR_HOOK(SV_ParseClientCommand, sandbox_PlayerCommand, CBC_ORDER_ANY);
192 MUTATOR_HOOK(PlayerPreThink, sandbox_PlayerPreThink, CBC_ORDER_ANY);