1 MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand)
3 if(MUTATOR_RETURNVALUE) // command was already handled?
5 if(cmd_name == "g_sandbox")
9 print_to(self, "Sandbox mode is active. For more information, use 'g_sandbox help'");
15 print_to(self, "You can use the following sandbox commands:");
16 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");
17 print_to(self, "^7\"^2spawn_item ^3item^7\" spawns the specified item in front of the player. Only weapons are currently supported");
20 else if(argv(1) == "spawn_object")
22 // don't allow spawning objects without a model
25 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");
28 else if not(fexists(argv(2)))
30 print_to(self, "WARNING: Attempted to spawn an object with a non-existent model. Make sure the path to your model file is correct");
38 e.classname = "object";
39 e.takedamage = DAMAGE_NO;
41 // those properties are defaults that can be edited later
42 e.movetype = MOVETYPE_TOSS;
45 makevectors(self.v_angle);
46 traceline(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_spawn, MOVE_NOMONSTERS, self);
47 setorigin(e, trace_endpos);
49 e.angles_y = self.v_angle_y; // apply the player's direction to the object, as he spawns it from behind
51 if(autocvar_g_sandbox_info)
52 print(strcat(self.netname, " spawned an object at origin ", vtos(e.origin), "\n"));
54 dprint(strcat(vtos(e.absmin), " - ", vtos(e.absmax), "\n"));
58 else if(argv(1) == "spawn_item")
60 // weapons are the only items currently supported
64 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");
71 makevectors(self.v_angle);
72 traceline(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_spawn, MOVE_NOMONSTERS, self);
74 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
76 e = get_weaponinfo(i);
77 if(e.netname == argv(2))
79 W_ThrowNewWeapon(self, i, FALSE, trace_endpos, '0 0 0');
80 if(autocvar_g_sandbox_info)
81 print(strcat(self.netname, " spawned a ^2", e.netname, "^7 at origin ", vtos(e.origin), "\n"));
86 print_to(self, "WARNING: Attempted to spawn an invalid or unsupported item. See 'g_sandbox help' for supported items");
89 else if(argv(1) == "remove_object")
91 makevectors(self.v_angle);
92 traceline(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_edit, MOVE_NORMAL, self);
93 if(trace_ent.classname == "object")
95 if(autocvar_g_sandbox_info)
96 print(strcat(self.netname, " removed an object at origin ", vtos(trace_ent.origin), "\n"));
102 dprint(strcat(trace_ent.classname, "\n"));
103 te_lightning2(world, self.origin + self.view_ofs + v_forward * 5 - v_up * 5, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_edit);
105 print_to(self, "WARNING: Object could not be removed. Make sure you are facing an object that you have spawned");
112 MUTATOR_DEFINITION(sandbox)
114 MUTATOR_HOOK(SV_ParseClientCommand, sandbox_PlayerCommand, CBC_ORDER_ANY);