1 .string object_clipboard;
4 const float MATERIAL_METAL = 1;
5 const float MATERIAL_STONE = 2;
6 const float MATERIAL_WOOD = 3;
7 const float MATERIAL_FLESH = 4;
9 entity sandbox_EditObject_Get()
11 // returns the traced entity if the player can edit it, and world if not
13 makevectors(self.v_angle);
14 WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_edit, MOVE_NORMAL, self);
15 if(trace_ent.classname == "object" && trace_ent.realowner == self)
21 void sandbox_EditObject_Scale(entity e, float f)
26 e.scale = bound(autocvar_g_sandbox_object_scale_min, e.scale, autocvar_g_sandbox_object_scale_max);
27 setsize(e, e.mins * e.scale, e.maxs * e.scale); // adapt bounding box size to model size
31 void sandbox_Object_Touch()
36 sound(self, CH_TRIGGER, strcat("object/impact_metal_", ftos(ceil(random() * 5)) , ".ogg"), VOL_BASE, ATTN_NORM);
39 sound(self, CH_TRIGGER, strcat("object/impact_stone_", ftos(ceil(random() * 5)) , ".ogg"), VOL_BASE, ATTN_NORM);
42 sound(self, CH_TRIGGER, strcat("object/impact_wood_", ftos(ceil(random() * 5)) , ".ogg"), VOL_BASE, ATTN_NORM);
45 sound(self, CH_TRIGGER, strcat("object/impact_flesh_", ftos(ceil(random() * 5)) , ".ogg"), VOL_BASE, ATTN_NORM);
52 entity sandbox_SpawnObject()
54 // spawn a new object with default properties
59 e.classname = "object";
60 e.takedamage = DAMAGE_AIM;
61 e.damageforcescale = 1;
62 e.solid = SOLID_BBOX; // SOLID_BSP would be best, but can lag the server badly
63 e.movetype = MOVETYPE_TOSS;
66 e.material = MATERIAL_METAL;
68 e.touch = sandbox_Object_Touch;
70 // set origin and direction based on player position and view angle
71 makevectors(self.v_angle);
72 WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_spawn, MOVE_NORMAL, self);
73 setorigin(e, trace_endpos);
74 e.angles_y = self.v_angle_y;
79 MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand)
81 if(MUTATOR_RETURNVALUE) // command was already handled?
83 if(cmd_name == "g_sandbox")
87 print_to(self, "Sandbox mode is active. For usage information, type 'sandbox help'");
95 // ---------------- COMMAND: HELP ----------------
97 print_to(self, "You can use the following sandbox commands:");
98 print_to(self, "^7\"^2spawn_item ^3item^7\" spawns the specified item in front of the player. Only weapons are currently supported");
99 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");
100 print_to(self, "^7\"^2remove_object^7\" removes the object the player is looking at. Players can only remove their own objects");
101 print_to(self, "^7\"^2duplicate_object_copy^7\" copies the object the player is looking at. Players can only copy their own objects");
102 print_to(self, "^7\"^2duplicate_object_paste^7\" pastes the copied object in front of the player");
103 print_to(self, "^7\"^2edit_object ^3property value^7\" edits the given property of the object. Players can only edit their own objects");
104 print_to(self, "^7Object properties for ^2edit_object^7:");
105 print_to(self, "^3skin value ^7- changes the skin of the object");
106 print_to(self, "^3alpha value ^7- sets object transparency");
107 print_to(self, "^3colormod \"value_x value_y value_z\" ^7- main object color");
108 print_to(self, "^3glowmod \"value_x value_y value_z\" ^7- glow object color");
109 print_to(self, "^3frame value ^7- object animation frame, for self-animated models");
110 print_to(self, "^3scale value ^7- changes object scale. 0.5 is half size and 2 is double size");
111 print_to(self, "^3physics value ^7- object physics, 0 = static, 1 = movable, 2 = physical");
112 print_to(self, "^3force value ^7- amount of force applied to objects that are shot");
113 print_to(self, "^3material value ^7- sets the material of the object. Valid materials are: 1 (metal), 2 (stone), 3 (wood), 4 (flesh)");
114 print_to(self, "^7The ^1drag object ^7key can be used to grab and carry objects. Players can only grab their own objects");
117 // ---------------- COMMAND: SPAWN ITEM ----------------
119 // only weapons are currently supported
123 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");
129 makevectors(self.v_angle);
130 WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_spawn, MOVE_NOMONSTERS, self);
132 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
134 e = get_weaponinfo(i);
135 if(e.netname == argv(2))
137 W_ThrowNewWeapon(self, i, FALSE, trace_endpos, '0 0 0');
138 if(autocvar_g_sandbox_info)
139 print(strcat(self.netname, " spawned a ^2", e.netname, "^7 at origin ", vtos(e.origin), "\n"));
144 print_to(self, "WARNING: Attempted to spawn an invalid or unsupported item. See 'sandbox help' for allowed items");
147 // ---------------- COMMAND: SPAWN OBJECT ----------------
149 // don't allow spawning objects without a model
152 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");
155 else if not(fexists(argv(2)))
157 print_to(self, "WARNING: Attempted to spawn an object with a non-existent model. Make sure the path to your model file is correct");
161 e = sandbox_SpawnObject();
162 setmodel(e, argv(2));
164 if(autocvar_g_sandbox_info)
165 print(strcat(self.netname, " spawned an object at origin ", vtos(e.origin), "\n"));
169 // ---------------- COMMAND: REMOVE OBJECT ----------------
170 case "remove_object":
171 e = sandbox_EditObject_Get();
174 if(autocvar_g_sandbox_info)
175 print(strcat(self.netname, " removed an object at origin ", vtos(e.origin), "\n"));
181 print_to(self, "WARNING: Object could not be removed. Make sure you are facing an object that belongs to you");
184 // ---------------- COMMAND: DUPLICATE OBJECT COPY ----------------
185 case "duplicate_object_copy":
186 // copies customizable properties of the selected object to the clipboard
188 e = sandbox_EditObject_Get(); // you can only copy objects you can edit, so this works
191 if(self.object_clipboard)
192 strunzone(self.object_clipboard);
194 // set clipboard properties
195 self.object_clipboard = strcat(e.model, " ");
196 self.object_clipboard = strcat(self.object_clipboard, ftos(e.skin), " ");
197 self.object_clipboard = strcat(self.object_clipboard, ftos(e.alpha), " ");
198 self.object_clipboard = strcat(self.object_clipboard, sprintf("\"%.9v\"", e.colormod), " ");
199 self.object_clipboard = strcat(self.object_clipboard, sprintf("\"%.9v\"", e.glowmod), " ");
200 self.object_clipboard = strcat(self.object_clipboard, ftos(e.frame), " ");
201 self.object_clipboard = strcat(self.object_clipboard, ftos(e.scale), " ");
202 self.object_clipboard = strcat(self.object_clipboard, ftos(e.movetype), " ");
203 self.object_clipboard = strcat(self.object_clipboard, ftos(e.damageforcescale), " ");
204 self.object_clipboard = strcat(self.object_clipboard, ftos(e.material), " ");
206 self.object_clipboard = strzone(self.object_clipboard);
207 print_to(self, "Object copied to clipboard");
211 print_to(self, "WARNING: Object could not be copied. Make sure you are facing an object that belongs to you");
214 // ---------------- COMMAND: DUPLICATE OBJECT PASTE ----------------
215 case "duplicate_object_paste":
216 // spawns a new object using the properties in the player's clipboard
218 if(!self.object_clipboard) // no object in clipboard
220 print_to(self, "WARNING: No object in clipboard. You must copy an object before you can paste it");
224 e = sandbox_SpawnObject();
225 tokenize_console(self.object_clipboard);
227 // apply clipboard properties
228 setmodel(e, argv(0));
229 e.skin = stof(argv(1));
230 e.alpha = stof(argv(2));
231 e.colormod = stov(argv(3));
232 e.glowmod = stov(argv(4));
233 e.frame = stof(argv(5));
234 sandbox_EditObject_Scale(e, stof(argv(6)));
235 e.movetype = stof(argv(7));
236 e.damageforcescale = stof(argv(8));
237 e.material = stof(argv(9));
239 print_to(self, "Object pasted");
240 if(autocvar_g_sandbox_info)
241 print(strcat(self.netname, " pasted an object at origin ", vtos(e.origin), "\n"));
245 // ---------------- COMMAND: EDIT OBJECT ----------------
247 if(!argv(2) || !argv(3))
249 print_to(self, "WARNING: Too few parameters. You must specify a property to edit, followed by its value");
253 e = sandbox_EditObject_Get();
259 e.skin = stof(argv(3));
262 e.alpha = stof(argv(3));
265 e.colormod = stov(argv(3));
268 e.glowmod = stov(argv(3));
271 e.frame = stof(argv(3));
274 sandbox_EditObject_Scale(e, stof(argv(3)));
280 e.movetype = MOVETYPE_NONE;
283 e.movetype = MOVETYPE_TOSS;
285 case "2": // physical
286 e.movetype = MOVETYPE_PHYSICS;
293 e.damageforcescale = stof(argv(3));
296 e.material = stof(argv(3));
299 print_to(self, "WARNING: Invalid object property. For usage information, type 'sandbox help'");
306 print_to(self, "WARNING: Object could not be edited. Make sure you are facing an object that belongs to you");
309 // ---------------- COMMAND: DEFAULT ----------------
311 print_to(self, "Invalid command. For usage information, type 'sandbox help'");
318 MUTATOR_HOOKFUNCTION(sandbox_PlayerPreThink)
320 // if the player is close enough to their object, they can drag it
322 if(autocvar_sv_cheats)
323 return FALSE; // cheat dragging is used instead
325 // grab is TRUE if the object can be picked up. While an object is being carried, the Drag() function
326 // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace.
327 // This also makes sure that an object can only pe picked up if in range, but does not get dropped if
328 // it goes out of range while slinging it around.
333 e = sandbox_EditObject_Get();
334 if(e != world && vlen(e.origin - self.origin) <= autocvar_g_sandbox_editor_distance_edit)
337 if(Drag(e, grab)) // execute dragging
339 if(autocvar_g_sandbox_info)
340 print(strcat(self.netname, " grabbed an object at origin ", vtos(e.origin), "\n"));
347 MUTATOR_HOOKFUNCTION(sandbox_ClientDisconnect)
349 // unzone the player's clipboard if it's not empty
350 if(self.object_clipboard)
352 strunzone(self.object_clipboard);
353 self.object_clipboard = string_null;
359 MUTATOR_DEFINITION(sandbox)
361 MUTATOR_HOOK(SV_ParseClientCommand, sandbox_PlayerCommand, CBC_ORDER_ANY);
362 MUTATOR_HOOK(PlayerPreThink, sandbox_PlayerPreThink, CBC_ORDER_ANY);
363 MUTATOR_HOOK(ClientDisconnect, sandbox_ClientDisconnect, CBC_ORDER_ANY);
368 for (i = 1; i <= 5; i++)
370 // precache material sounds
371 precache_sound(strcat("objects/impact_metal_", ftos(i), ".ogg"));
372 precache_sound(strcat("objects/impact_stone_", ftos(i), ".ogg"));
373 precache_sound(strcat("objects/impact_wood_", ftos(i), ".ogg"));
374 precache_sound(strcat("objects/impact_flesh_", ftos(i), ".ogg"));