1 .string object_clipboard;
3 entity sandbox_EditObject_Get()
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 void sandbox_EditObject_Scale(entity e, float f)
20 e.scale = bound(autocvar_g_sandbox_object_scale_min, e.scale, autocvar_g_sandbox_object_scale_max);
21 setsize(e, e.mins * e.scale, e.maxs * e.scale); // adapt bounding box size to model size
25 entity sandbox_SpawnObject()
27 // spawn a new object with default properties
32 e.classname = "object";
33 e.takedamage = DAMAGE_AIM;
34 e.damageforcescale = 0;
35 e.solid = SOLID_BBOX; // SOLID_BSP would be best, but can lag the server badly
36 e.movetype = MOVETYPE_TOSS;
40 // set origin and direction based on player position and view angle
41 makevectors(self.v_angle);
42 WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_spawn, MOVE_NORMAL, self);
43 setorigin(e, trace_endpos);
44 e.angles_y = self.v_angle_y;
49 MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand)
51 if(MUTATOR_RETURNVALUE) // command was already handled?
53 if(cmd_name == "g_sandbox")
57 print_to(self, "Sandbox mode is active. For usage information, type 'sandbox help'");
65 // ---------------- COMMAND: HELP ----------------
67 print_to(self, "You can use the following sandbox commands:");
68 print_to(self, "^7\"^2spawn_item ^3item^7\" spawns the specified item in front of the player. Only weapons are currently supported");
69 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");
70 print_to(self, "^7\"^2remove_object^7\" removes the object the player is looking at. Players can only remove their own objects");
71 print_to(self, "^7\"^2duplicate_object_copy^7\" copies the object the player is looking at. Players can only copy their own objects");
72 print_to(self, "^7\"^2duplicate_object_paste^7\" pastes the copied object in front of the player");
73 print_to(self, "^7\"^2edit_object ^3property value^7\" edits the given property of the object. Players can only edit their own objects");
74 print_to(self, "^7Object properties for ^2edit_object^7:");
75 print_to(self, "^3skin value ^7- changes the skin of the object");
76 print_to(self, "^3alpha value ^7- sets object transparency");
77 print_to(self, "^3colormod \"value_x value_y value_z\" ^7- main object color");
78 print_to(self, "^3glowmod \"value_x value_y value_z\" ^7- glow object color");
79 print_to(self, "^3frame value ^7- object animation frame, for self-animated models");
80 print_to(self, "^3scale value ^7- changes object scale. 0.5 is half size and 2 is double size");
81 print_to(self, "^3physics value ^7- object physics, 0 = static, 1 = movable, 2 = physical");
82 print_to(self, "^force value ^7- amount of force applied to objects that are shot");
83 print_to(self, "^7The ^1drag object ^7key can be used to grab and carry objects. Players can only grab their own objects");
86 // ---------------- COMMAND: SPAWN ITEM ----------------
88 // only weapons are currently supported
92 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");
98 makevectors(self.v_angle);
99 WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_spawn, MOVE_NOMONSTERS, self);
101 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
103 e = get_weaponinfo(i);
104 if(e.netname == argv(2))
106 W_ThrowNewWeapon(self, i, FALSE, trace_endpos, '0 0 0');
107 if(autocvar_g_sandbox_info)
108 print(strcat(self.netname, " spawned a ^2", e.netname, "^7 at origin ", vtos(e.origin), "\n"));
113 print_to(self, "WARNING: Attempted to spawn an invalid or unsupported item. See 'sandbox help' for allowed items");
116 // ---------------- COMMAND: SPAWN OBJECT ----------------
118 // don't allow spawning objects without a model
121 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");
124 else if not(fexists(argv(2)))
126 print_to(self, "WARNING: Attempted to spawn an object with a non-existent model. Make sure the path to your model file is correct");
130 e = sandbox_SpawnObject();
131 setmodel(e, argv(2));
133 if(autocvar_g_sandbox_info)
134 print(strcat(self.netname, " spawned an object at origin ", vtos(e.origin), "\n"));
138 // ---------------- COMMAND: REMOVE OBJECT ----------------
139 case "remove_object":
140 e = sandbox_EditObject_Get();
143 if(autocvar_g_sandbox_info)
144 print(strcat(self.netname, " removed an object at origin ", vtos(e.origin), "\n"));
150 print_to(self, "WARNING: Object could not be removed. Make sure you are facing an object that belongs to you");
153 // ---------------- COMMAND: DUPLICATE OBJECT COPY ----------------
154 case "duplicate_object_copy":
155 // copies customizable properties of the selected object to the clipboard
157 e = sandbox_EditObject_Get(); // you can only copy objects you can edit, so this works
160 if(self.object_clipboard)
161 strunzone(self.object_clipboard);
163 // set clipboard properties
164 self.object_clipboard = strcat(e.model, " ");
165 self.object_clipboard = strcat(self.object_clipboard, ftos(e.skin), " ");
166 self.object_clipboard = strcat(self.object_clipboard, ftos(e.alpha), " ");
167 self.object_clipboard = strcat(self.object_clipboard, sprintf("\"%.9v\"", e.colormod), " ");
168 self.object_clipboard = strcat(self.object_clipboard, sprintf("\"%.9v\"", e.glowmod), " ");
169 self.object_clipboard = strcat(self.object_clipboard, ftos(e.frame), " ");
170 self.object_clipboard = strcat(self.object_clipboard, ftos(e.scale), " ");
171 self.object_clipboard = strcat(self.object_clipboard, ftos(e.movetype), " ");
172 self.object_clipboard = strcat(self.object_clipboard, ftos(e.damageforcescale), " ");
174 self.object_clipboard = strzone(self.object_clipboard);
175 print_to(self, "Object copied to clipboard");
179 print_to(self, "WARNING: Object could not be copied. Make sure you are facing an object that belongs to you");
182 // ---------------- COMMAND: DUPLICATE OBJECT PASTE ----------------
183 case "duplicate_object_paste":
184 // spawns a new object using the properties in the player's clipboard
186 if(!self.object_clipboard) // no object in clipboard
188 print_to(self, "WARNING: No object in clipboard. You must copy an object before you can paste it");
192 e = sandbox_SpawnObject();
193 tokenize_console(self.object_clipboard);
195 // apply clipboard properties
196 setmodel(e, argv(0));
197 e.skin = stof(argv(1));
198 e.alpha = stof(argv(2));
199 e.colormod = stov(argv(3));
200 e.glowmod = stov(argv(4));
201 e.frame = stof(argv(5));
202 sandbox_EditObject_Scale(e, stof(argv(6)));
203 e.movetype = stof(argv(7));
204 e.damageforcescale = stof(argv(8));
206 print_to(self, "Object pasted");
207 if(autocvar_g_sandbox_info)
208 print(strcat(self.netname, " pasted an object at origin ", vtos(e.origin), "\n"));
212 // ---------------- COMMAND: EDIT OBJECT ----------------
214 if(!argv(2) || !argv(3))
216 print_to(self, "WARNING: Too few parameters. You must specify a property to edit, followed by its value");
220 e = sandbox_EditObject_Get();
226 e.skin = stof(argv(3));
229 e.alpha = stof(argv(3));
232 e.colormod = stov(argv(3));
235 e.glowmod = stov(argv(3));
238 e.frame = stof(argv(3));
241 sandbox_EditObject_Scale(e, stof(argv(3)));
247 e.movetype = MOVETYPE_NONE;
250 e.movetype = MOVETYPE_TOSS;
252 case "2": // physical
253 e.movetype = MOVETYPE_PHYSICS;
260 e.damageforcescale = stof(argv(3));
263 print_to(self, "WARNING: Invalid object property. For usage information, type 'sandbox help'");
270 print_to(self, "WARNING: Object could not be edited. Make sure you are facing an object that belongs to you");
273 // ---------------- COMMAND: DEFAULT ----------------
275 print_to(self, "Invalid command. For usage information, type 'sandbox help'");
282 MUTATOR_HOOKFUNCTION(sandbox_PlayerPreThink)
284 // if the player is close enough to their object, they can drag it
286 if(autocvar_sv_cheats)
287 return FALSE; // cheat dragging is used instead
289 // grab is TRUE if the object can be picked up. While an object is being carried, the Drag() function
290 // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace.
291 // This also makes sure that an object can only pe picked up if in range, but does not get dropped if
292 // it goes out of range while slinging it around.
297 e = sandbox_EditObject_Get();
298 if(e != world && vlen(e.origin - self.origin) <= autocvar_g_sandbox_editor_distance_edit)
301 if(Drag(e, grab)) // execute dragging
303 if(autocvar_g_sandbox_info)
304 print(strcat(self.netname, " grabbed an object at origin ", vtos(e.origin), "\n"));
311 MUTATOR_HOOKFUNCTION(sandbox_ClientDisconnect)
313 // unzone the player's clipboard if it's not empty
314 if(self.object_clipboard)
316 strunzone(self.object_clipboard);
317 self.object_clipboard = string_null;
323 MUTATOR_DEFINITION(sandbox)
325 MUTATOR_HOOK(SV_ParseClientCommand, sandbox_PlayerCommand, CBC_ORDER_ANY);
326 MUTATOR_HOOK(PlayerPreThink, sandbox_PlayerPreThink, CBC_ORDER_ANY);
327 MUTATOR_HOOK(ClientDisconnect, sandbox_ClientDisconnect, CBC_ORDER_ANY);