1e66c9d26d9d98642d73b2d8ec87391a7a7af6bf
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / sandbox.qc
1 MUTATOR_HOOKFUNCTION(sandbox_PlayerCommand)
2 {
3         if(MUTATOR_RETURNVALUE) // command was already handled?
4                 return FALSE;
5         if(cmd_name == "g_sandbox")
6         {
7                 if(cmd_argc < 2)
8                 {
9                         print_to(self, "Sandbox mode is active. For more information, use 'g_sandbox help'");
10                         return TRUE;
11                 }
12
13                 if(argv(1) == "help")
14                 {
15                         print_to(self, "You can use the following sandbox commands:");
16                         print_to(self, "^7\"^2spawn ^3models/foo/bar.md3^7\" spawns a new object in front of the player, and gives it the specified model");
17                         return TRUE;
18                 }
19                 else if(argv(1) == "spawn")
20                 {
21                         // spawn a new object with the default settings
22
23                         if(cmd_argc < 3)
24                         {
25                                 // don't allow spawning objects without a model
26                                 print_to(self, "WARNING: Attempted to spawn an object without a model. Please specify the path to your mesh after the 'spawn' command");
27                                 return TRUE;
28                         }
29
30                         entity e;
31                         e = spawn();
32                         e.classname = "object";
33                         makevectors(self.v_angle);
34                         traceline(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance, MOVE_NOMONSTERS, self);
35                         setorigin(e, trace_endpos);
36                         setmodel(e, argv(2));
37                         e.angles = self.v_angle; // give the player's angles to the object, as he spawns it from behind
38
39                         if(autocvar_g_sandbox_info)
40                                 print(strcat(self.netname, " spawned an object at origin ", vtos(e.origin), "\n"));
41
42                         return TRUE;
43                 }
44         }
45         return FALSE;
46 }
47
48 MUTATOR_DEFINITION(sandbox)
49 {
50         MUTATOR_HOOK(SV_ParseClientCommand, sandbox_PlayerCommand, CBC_ORDER_ANY);
51
52         return 0;
53 }