1 .string object_clipboard;
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_AIM;
24 e.solid = SOLID_BBOX; // SOLID_BSP would be best, but can lag the server badly
25 e.movetype = MOVETYPE_TOSS;
29 // set origin and direction based on player position and view angle
30 makevectors(self.v_angle);
31 WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_spawn, MOVE_NORMAL, self);
32 setorigin(e, trace_endpos);
33 e.angles_y = self.v_angle_y;
38 MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand)
40 if(MUTATOR_RETURNVALUE) // command was already handled?
42 if(cmd_name == "g_sandbox")
46 print_to(self, "Sandbox mode is active. For usage information, type 'sandbox help'");
54 // ---------------- COMMAND: HELP ----------------
56 print_to(self, "You can use the following sandbox commands:");
57 print_to(self, "^7\"^2spawn_item ^3item^7\" spawns the specified item in front of the player. Only weapons are currently supported");
58 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");
59 print_to(self, "^7\"^2remove_object^7\" removes the object the player is looking at. Players can only remove their own objects");
60 print_to(self, "^7\"^2duplicate_object_copy^7\" copies the object the player is looking at. Players can only copy their own objects");
61 print_to(self, "^7\"^2duplicate_object_paste^7\" pastes the copied object in front of the player");
62 print_to(self, "^7\"^2edit_object ^3property value^7\" edits the given property of the object. Players can only edit their own objects");
63 print_to(self, "^7Object properties for ^2edit_object^7:");
64 print_to(self, "^3skin ^7- changes the skin of the object");
65 print_to(self, "^3alpha ^7- sets object transparency");
66 print_to(self, "^3frame ^7- object animation frame, for self-animated models");
67 print_to(self, "^3scale ^7- changes object scale. 0.5 is half size and 2 is double size");
68 print_to(self, "^3physics ^7- object physics, 0 = static, 1 = movable, 2 = physical");
69 print_to(self, "^7The ^1drag object ^7key can be used to grab and carry objects. Players can only grab their own objects");
72 // ---------------- COMMAND: SPAWN ITEM ----------------
74 // only weapons are currently supported
78 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");
84 makevectors(self.v_angle);
85 WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_spawn, MOVE_NOMONSTERS, self);
87 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
89 e = get_weaponinfo(i);
90 if(e.netname == argv(2))
92 W_ThrowNewWeapon(self, i, FALSE, trace_endpos, '0 0 0');
93 if(autocvar_g_sandbox_info)
94 print(strcat(self.netname, " spawned a ^2", e.netname, "^7 at origin ", vtos(e.origin), "\n"));
99 print_to(self, "WARNING: Attempted to spawn an invalid or unsupported item. See 'sandbox help' for allowed items");
102 // ---------------- COMMAND: SPAWN OBJECT ----------------
104 // don't allow spawning objects without a model
107 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");
110 else if not(fexists(argv(2)))
112 print_to(self, "WARNING: Attempted to spawn an object with a non-existent model. Make sure the path to your model file is correct");
116 e = sandbox_SpawnObject();
117 setmodel(e, argv(2));
119 if(autocvar_g_sandbox_info)
120 print(strcat(self.netname, " spawned an object at origin ", vtos(e.origin), "\n"));
124 // ---------------- COMMAND: REMOVE OBJECT ----------------
125 case "remove_object":
126 e = sandbox_EditObject();
129 if(autocvar_g_sandbox_info)
130 print(strcat(self.netname, " removed an object at origin ", vtos(e.origin), "\n"));
136 print_to(self, "WARNING: Object could not be removed. Make sure you are facing an object that belongs to you");
139 // ---------------- COMMAND: DUPLICATE OBJECT COPY ----------------
140 case "duplicate_object_copy":
141 // copies customizable properties of the selected object to the clipboard
143 e = sandbox_EditObject(); // you can only copy objects you can edit, so this works
146 if(self.object_clipboard)
147 strunzone(self.object_clipboard);
149 // set clipboard properties
150 self.object_clipboard = strcat(e.model, " ");
151 self.object_clipboard = strcat(self.object_clipboard, ftos(e.skin), " ");
152 self.object_clipboard = strcat(self.object_clipboard, ftos(e.alpha), " ");
153 self.object_clipboard = strcat(self.object_clipboard, ftos(e.frame), " ");
154 self.object_clipboard = strcat(self.object_clipboard, ftos(e.scale), " ");
155 self.object_clipboard = strcat(self.object_clipboard, ftos(e.movetype), " ");
157 self.object_clipboard = strzone(self.object_clipboard);
158 print_to(self, "Object copied to clipboard");
162 print_to(self, "WARNING: Object could not be copied. Make sure you are facing an object that belongs to you");
165 // ---------------- COMMAND: DUPLICATE OBJECT PASTE ----------------
166 case "duplicate_object_paste":
167 // spawns a new object using the properties in the player's clipboard
169 if(!self.object_clipboard) // no object in clipboard
171 print_to(self, "WARNING: No object in clipboard. You must copy an object before you can paste it");
175 e = sandbox_SpawnObject();
176 tokenize_console(self.object_clipboard);
178 // apply clipboard properties
179 setmodel(e, argv(0));
180 e.skin = stof(argv(1));
181 e.alpha = stof(argv(2));
182 e.frame = stof(argv(3));
183 e.scale = stof(argv(4)); setsize(e, e.mins * e.scale, e.maxs * e.scale); // adapt bounding box size to model size
184 e.movetype = stof(argv(5));
186 print_to(self, "Object pasted");
187 if(autocvar_g_sandbox_info)
188 print(strcat(self.netname, " pasted an object at origin ", vtos(e.origin), "\n"));
192 // ---------------- COMMAND: EDIT OBJECT ----------------
194 if(!argv(2) || !argv(3))
196 print_to(self, "WARNING: Too few parameters. You must specify a property to edit, followed by its value");
200 e = sandbox_EditObject();
206 e.skin = stof(argv(3));
209 e.alpha = stof(argv(3));
212 e.frame = stof(argv(3));
215 e.scale = stof(argv(3));
216 setsize(e, e.mins * e.scale, e.maxs * e.scale); // adapt bounding box size to model size
222 e.movetype = MOVETYPE_NONE;
225 e.movetype = MOVETYPE_TOSS;
227 case "2": // physical
228 e.movetype = MOVETYPE_PHYSICS;
235 print_to(self, "WARNING: Invalid object property. For usage information, type 'sandbox help'");
242 print_to(self, "WARNING: Object could not be edited. Make sure you are facing an object that belongs to you");
245 // ---------------- COMMAND: DEFAULT ----------------
247 print_to(self, "Invalid command. For usage information, type 'sandbox help'");
254 MUTATOR_HOOKFUNCTION(sandbox_PlayerPreThink)
256 // if the player is close enough to their object, they can drag it
258 if(autocvar_sv_cheats)
259 return FALSE; // cheat dragging is used instead
261 // grab is TRUE if the object can be picked up. While an object is being carried, the Drag() function
262 // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace.
263 // This also makes sure that an object can only pe picked up if in range, but does not get dropped if
264 // it goes out of range while slinging it around.
269 e = sandbox_EditObject();
270 if(e != world && vlen(e.origin - self.origin) <= autocvar_g_sandbox_editor_distance_edit)
273 if(Drag(e, grab)) // execute dragging
275 if(autocvar_g_sandbox_info)
276 print(strcat(self.netname, " grabbed an object at origin ", vtos(e.origin), "\n"));
283 MUTATOR_HOOKFUNCTION(sandbox_ClientDisconnect)
285 // unzone the player's clipboard if it's not empty
286 if(self.object_clipboard)
288 strunzone(self.object_clipboard);
289 self.object_clipboard = string_null;
295 MUTATOR_DEFINITION(sandbox)
297 MUTATOR_HOOK(SV_ParseClientCommand, sandbox_PlayerCommand, CBC_ORDER_ANY);
298 MUTATOR_HOOK(PlayerPreThink, sandbox_PlayerPreThink, CBC_ORDER_ANY);
299 MUTATOR_HOOK(ClientDisconnect, sandbox_ClientDisconnect, CBC_ORDER_ANY);