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_NO;
24 e.movetype = MOVETYPE_TOSS;
25 e.solid = SOLID_BBOX; // SOLID_BSP would be best, but can lag the server badly
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 usage information, type 'sandbox help'");
51 print_to(self, "You can use the following sandbox commands:");
52 print_to(self, "^7\"^2spawn_item ^3item^7\" spawns the specified item in front of the player. Only weapons are currently supported");
53 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");
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, "^7\"^2duplicate_object_copy^7\" copies the object the player is looking at. Players can only copy their own objects");
56 print_to(self, "^7\"^2duplicate_object_paste^7\" pastes the copied object in front of the player");
57 print_to(self, "^7\"^2edit_object ^3property value^7\" edits the given property of the object. Players can only edit their own objects");
58 print_to(self, "^7Object properties for ^2edit_object^7:");
59 print_to(self, "^3skin ^7- changes the skin of the object");
60 print_to(self, "^3frame ^7- object animation frame, for self-animated models");
61 print_to(self, "^7The ^1drag object ^7key can be used to grab and carry objects. Players can only grab their own objects");
64 else if(argv(1) == "spawn_item")
66 // only weapons are currently supported
70 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");
76 makevectors(self.v_angle);
77 WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_spawn, MOVE_NOMONSTERS, self);
79 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
81 e = get_weaponinfo(i);
82 if(e.netname == argv(2))
84 W_ThrowNewWeapon(self, i, FALSE, trace_endpos, '0 0 0');
85 if(autocvar_g_sandbox_info)
86 print(strcat(self.netname, " spawned a ^2", e.netname, "^7 at origin ", vtos(e.origin), "\n"));
91 print_to(self, "WARNING: Attempted to spawn an invalid or unsupported item. See 'sandbox help' for allowed items");
94 else if(argv(1) == "spawn_object")
96 // don't allow spawning objects without a model
99 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");
102 else if not(fexists(argv(2)))
104 print_to(self, "WARNING: Attempted to spawn an object with a non-existent model. Make sure the path to your model file is correct");
108 e = sandbox_SpawnObject();
109 setmodel(e, argv(2));
111 if(autocvar_g_sandbox_info)
112 print(strcat(self.netname, " spawned an object at origin ", vtos(e.origin), "\n"));
116 else if(argv(1) == "remove_object")
118 e = sandbox_EditObject();
121 if(autocvar_g_sandbox_info)
122 print(strcat(self.netname, " removed an object at origin ", vtos(e.origin), "\n"));
128 print_to(self, "WARNING: Object could not be removed. Make sure you are facing an object that belongs to you");
131 else if(argv(1) == "duplicate_object_copy")
133 // copies customizable properties of the selected object to the clipboard
135 e = sandbox_EditObject(); // you can only copy objects you can edit, so this works
138 // set clipboard properties
139 if(self.object_clipboard)
140 strunzone(self.object_clipboard);
141 self.object_clipboard = strzone(strcat(e.model, " ", ftos(e.skin), " ", ftos(e.frame), " ", ftos(e.movetype)));
143 print_to(self, "Object copied to clipboard");
147 print_to(self, "WARNING: Object could not be copied. Make sure you are facing an object that belongs to you");
150 else if(argv(1) == "duplicate_object_paste")
152 // spawns a new object using the properties in the player's clipboard
154 if(!self.object_clipboard) // no object in clipboard
156 print_to(self, "WARNING: No object in clipboard. You must copy an object before you can paste it");
160 e = sandbox_SpawnObject();
161 tokenize_console(self.object_clipboard);
163 // apply clipboard properties
164 setmodel(e, argv(0));
165 e.skin = stof(argv(1));
166 e.frame = stof(argv(2));
167 e.movetype = stof(argv(3));
169 print_to(self, "Object pasted");
170 if(autocvar_g_sandbox_info)
171 print(strcat(self.netname, " pasted an object at origin ", vtos(e.origin), "\n"));
175 else if(argv(1) == "edit_object")
177 if(!argv(2) || !argv(3))
179 print_to(self, "WARNING: Too few parameters. You must specify a property to edit, followed by its value");
183 e = sandbox_EditObject();
186 if(argv(2) == "skin")
187 e.skin = stof(argv(3));
188 else if(argv(2) == "frame")
189 e.frame = stof(argv(3));
191 print_to(self, "WARNING: Invalid object property. For usage information, type 'sandbox help'");
196 print_to(self, "WARNING: Object could not be edited. Make sure you are facing an object that belongs to you");
201 print_to(self, "Invalid command. For usage information, type 'sandbox help'");
208 MUTATOR_HOOKFUNCTION(sandbox_PlayerPreThink)
210 // if the player is close enough to their object, they can drag it
212 if(autocvar_sv_cheats)
213 return FALSE; // cheat dragging is used instead
215 // grab is TRUE if the object can be picked up. While an object is being carried, the Drag() function
216 // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace.
217 // This also makes sure that an object can only pe picked up if in range, but does not get dropped if
218 // it goes out of range while slinging it around.
223 e = sandbox_EditObject();
224 if(e != world && vlen(e.origin - self.origin) <= autocvar_g_sandbox_editor_distance_edit)
227 if(Drag(e, grab)) // execute dragging
229 if(autocvar_g_sandbox_info)
230 print(strcat(self.netname, " grabbed an object at origin ", vtos(e.origin), "\n"));
237 MUTATOR_HOOKFUNCTION(sandbox_ClientDisconnect)
239 // unzone the player's clipboard if it's not empty
240 if(self.object_clipboard)
242 strunzone(self.object_clipboard);
243 self.object_clipboard = string_null;
249 MUTATOR_DEFINITION(sandbox)
251 MUTATOR_HOOK(SV_ParseClientCommand, sandbox_PlayerCommand, CBC_ORDER_ANY);
252 MUTATOR_HOOK(PlayerPreThink, sandbox_PlayerPreThink, CBC_ORDER_ANY);
253 MUTATOR_HOOK(ClientDisconnect, sandbox_ClientDisconnect, CBC_ORDER_ANY);