]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/sandbox.qc
Fix the trace detection issue. Apparently, objects were not being traced because...
[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_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");
18                         return TRUE;
19                 }
20                 else if(argv(1) == "spawn_object")
21                 {
22                         // don't allow spawning objects without a model
23                         if(cmd_argc < 3)
24                         {
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");
26                                 return TRUE;
27                         }
28                         else if not(fexists(argv(2)))
29                         {
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");
31                                 return TRUE;
32                         }
33
34                         // spawn a new object
35                         entity e;
36                         e = spawn();
37
38                         //e.owner = self; // for some reason, setting this causes collisions to break
39                         e.classname = "object";
40                         e.takedamage = DAMAGE_NO;
41
42                         // those properties are defaults that can be edited later
43                         e.movetype = MOVETYPE_TOSS;
44                         e.solid = SOLID_BSP;
45
46                         makevectors(self.v_angle);
47                         traceline(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_spawn, MOVE_NORMAL, self);
48                         setorigin(e, trace_endpos);
49                         setmodel(e, argv(2));
50                         e.angles_y = self.v_angle_y; // apply the player's direction to the object, as he spawns it from behind
51
52                         if(autocvar_g_sandbox_info)
53                                 print(strcat(self.netname, " spawned an object at origin ", vtos(e.origin), "\n"));
54
55                         return TRUE;
56                 }
57                 else if(argv(1) == "spawn_item")
58                 {
59                         // weapons are the only items currently supported
60
61                         if(cmd_argc < 3)
62                         {
63                                 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");
64                                 return TRUE;
65                         }
66
67                         // spawn a new item
68                         entity e;
69                         float i;
70                         makevectors(self.v_angle);
71                         traceline(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_spawn, MOVE_NOMONSTERS, self);
72
73                         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
74                         {
75                                 e = get_weaponinfo(i);
76                                 if(e.netname == argv(2))
77                                 {
78                                         W_ThrowNewWeapon(self, i, FALSE, trace_endpos, '0 0 0');
79                                         if(autocvar_g_sandbox_info)
80                                                 print(strcat(self.netname, " spawned a ^2", e.netname, "^7 at origin ", vtos(e.origin), "\n"));
81                                         return TRUE;
82                                 }
83                         }
84
85                         print_to(self, "WARNING: Attempted to spawn an invalid or unsupported item. See 'g_sandbox help' for supported items");
86                         return TRUE;
87                 }
88                 else if(argv(1) == "remove_object")
89                 {
90                         makevectors(self.v_angle);
91                         traceline(self.origin + self.view_ofs, self.origin + self.view_ofs + v_forward * autocvar_g_sandbox_editor_distance_edit, MOVE_NORMAL, self);
92                         if(trace_ent.classname == "object")
93                         {
94                                 if(autocvar_g_sandbox_info)
95                                         print(strcat(self.netname, " removed an object at origin ", vtos(trace_ent.origin), "\n"));
96                                 remove(trace_ent);
97                                 trace_ent = world;
98                                 return TRUE;
99                         }
100
101                         print_to(self, "WARNING: Object could not be removed. Make sure you are facing an object that you have spawned");
102                         return TRUE;
103                 }
104         }
105         return FALSE;
106 }
107
108 MUTATOR_DEFINITION(sandbox)
109 {
110         MUTATOR_HOOK(SV_ParseClientCommand, sandbox_PlayerCommand, CBC_ORDER_ANY);
111
112         return 0;
113 }