1 .string clipboard_model;
2 .float clipboard_movetype;
4 entity sandbox_EditObject()
6 // returns the traced entity if the player can edit it, and world if not
8 makevectors(self.v_angle);
9 WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_edit, MOVE_NORMAL, self);
10 if(trace_ent.classname == "object" && trace_ent.realowner == self)
16 entity sandbox_SpawnObject()
18 // spawn a new object with default properties
23 e.classname = "object";
24 e.takedamage = DAMAGE_NO;
25 e.movetype = MOVETYPE_TOSS;
28 // set origin and direction based on player position and view angle
29 makevectors(self.v_angle);
30 WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_spawn, MOVE_NORMAL, self);
31 setorigin(e, trace_endpos);
32 e.angles_y = self.v_angle_y;
37 MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand)
39 if(MUTATOR_RETURNVALUE) // command was already handled?
41 if(cmd_name == "g_sandbox")
45 print_to(self, "Sandbox mode is active. For more information, use 'sandbox help'");
52 print_to(self, "You can use the following sandbox commands:");
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\"^2spawn_object ^3models/foo/bar.md3^7\" spawns a new object in front of the player, and gives it the specified model");
55 print_to(self, "^7\"^2remove_object^7\" removes the object the player is looking at. Players can only remove their own objects");
56 print_to(self, "^7\"^2duplicate_object_copy^7\" copies the object the player is looking at. Players can only copy their own objects");
57 print_to(self, "^7\"^2duplicate_object_paste^7\" pastes the copied object in front of the player");
58 print_to(self, "^7The ^1drag object ^7key can be used to grab and carry objects. Players can only grab their own objects");
61 else if(argv(1) == "spawn_item")
63 // only weapons are currently supported
67 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");
73 makevectors(self.v_angle);
74 WarpZone_TraceLine(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_spawn, MOVE_NOMONSTERS, self);
76 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
78 e = get_weaponinfo(i);
79 if(e.netname == argv(2))
81 W_ThrowNewWeapon(self, i, FALSE, trace_endpos, '0 0 0');
82 if(autocvar_g_sandbox_info)
83 print(strcat(self.netname, " spawned a ^2", e.netname, "^7 at origin ", vtos(e.origin), "\n"));
88 print_to(self, "WARNING: Attempted to spawn an invalid or unsupported item. See 'sandbox help' for allowed items");
91 else if(argv(1) == "spawn_object")
93 // don't allow spawning objects without a model
96 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");
99 else if not(fexists(argv(2)))
101 print_to(self, "WARNING: Attempted to spawn an object with a non-existent model. Make sure the path to your model file is correct");
105 e = sandbox_SpawnObject();
106 setmodel(e, argv(2));
108 if(autocvar_g_sandbox_info)
109 print(strcat(self.netname, " spawned an object at origin ", vtos(e.origin), "\n"));
113 else if(argv(1) == "remove_object")
115 e = sandbox_EditObject();
118 if(autocvar_g_sandbox_info)
119 print(strcat(self.netname, " removed an object at origin ", vtos(e.origin), "\n"));
125 print_to(self, "WARNING: Object could not be removed. Make sure you are facing an object that belongs to you");
128 else if(argv(1) == "duplicate_object_copy")
130 // copies customizable properties of the selected object to the clipboard
132 e = sandbox_EditObject(); // you can only copy objects you can edit, so this works
135 // -------- COPY PROPERTIES --------
136 self.clipboard_model = e.model;
137 self.clipboard_movetype = e.movetype;
138 // -------- COPY PROPERTIES --------
140 print_to(self, "Object copied to clipboard");
144 print_to(self, "WARNING: Object could not be copied. Make sure you are facing an object that belongs to you");
147 else if(argv(1) == "duplicate_object_paste")
149 // spawns a new object using the properties in the player's clipboard
151 if(self.clipboard_model == "") // no object in clipboard
153 print_to(self, "WARNING: No object in clipboard. You must copy an object before you can paste it");
157 e = sandbox_SpawnObject();
159 // -------- PASTE PROPERTIES --------
160 setmodel(e, self.clipboard_model);
161 e.movetype = self.clipboard_movetype;
162 // -------- PASTE PROPERTIES --------
164 print_to(self, "Object pasted");
165 if(autocvar_g_sandbox_info)
166 print(strcat(self.netname, " pasted an object at origin ", vtos(e.origin), "\n"));
174 MUTATOR_HOOKFUNCTION(sandbox_PlayerPreThink)
176 // if the player is close enough to their object, they can drag it
178 if(autocvar_sv_cheats)
179 return FALSE; // cheat dragging is used instead
181 // grab is TRUE if the object can be picked up. While an object is being carried, the Drag() function
182 // must execute for it either way, otherwise it would cause bugs if it went out of the player's trace.
183 // This also makes sure that an object can only pe picked up if in range, but does not get dropped if
184 // it goes out of range while slinging it around.
189 e = sandbox_EditObject();
190 if(e != world && vlen(e.origin - self.origin) <= autocvar_g_sandbox_editor_distance_edit)
193 if(Drag(e, grab)) // execute dragging
195 if(autocvar_g_sandbox_info)
196 print(strcat(self.netname, " grabbed an object at origin ", vtos(e.origin), "\n"));
203 MUTATOR_DEFINITION(sandbox)
205 MUTATOR_HOOK(SV_ParseClientCommand, sandbox_PlayerCommand, CBC_ORDER_ANY);
206 MUTATOR_HOOK(PlayerPreThink, sandbox_PlayerPreThink, CBC_ORDER_ANY);