]> git.xonotic.org Git - xonotic/xonotic.wiki.git/blob - Programming-QuakeC-stuff-in-Xonotic.md
Added a bit explanation in the beginning of CSQC, MENUQC, SVQC and GAMEQC blocks
[xonotic/xonotic.wiki.git] / Programming-QuakeC-stuff-in-Xonotic.md
1 **Note:** The article is written as developer notes to ease developer tasks and save QuakeC terms here.
2
3 # CSQC, MENUQC, SVQC and GAMEQC blocks
4
5 Xonotic uses the ***csprogs.dat*** from the server you're playing on, as it must match the server's ***progs.dat*** code (whereas your ***menu.dat*** is always your local copy).
6
7 Menu and HUD code are actually separated as they run in 2 distinct programs: ***csprogs.dat*** and ***menu.dat***
8
9 Server program is ***progs.dat***
10
11 - Code inside a **`#ifdef CSQC`** block is part of the client code and will be compiled to **csprogs.dat**
12
13 - Code inside a **`#ifdef MENUQC`** block is part of the menu code and will be compiled to **menu.dat**
14
15 - Code inside a **`#ifdef SVQC`** block is part of the menu code and will be compiled to **progs.dat**
16
17 - Also, code inside a **`#ifdef GAMEQC`** block is part of both client (not menu) and server code.
18
19 Example: `g_balance_grapplehook_speed_fly` is clearly a server cvar (**g_*** cvars are server cvars), so you CAN'T declare it within a `#ifdef CSQC` block. This cvar should be declared inside a **`#ifdef SVQC`**.
20
21 Other example: `cl_chatsound` is clearly a client cvar (**cl_*** cvars are client cvars), only can be declared in a **`#ifdef CSQC`** block.
22
23
24 <br />
25
26 # MUTATOR functions (from: [`qcsrc/client/mutators/events.qh`](https://timepath.github.io/scratchspace/d8/d0e/client_2mutators_2events_8qh_source.html), [`qcsrc/common/mutators/events.qh`](https://timepath.github.io/scratchspace/d4/d95/common_2mutators_2events_8qh_source.html), [`qcsrc/server/mutators/events.qh`](https://timepath.github.io/scratchspace/d6/ddd/server_2mutators_2events_8qh_source.html))
27
28 ### How to use MUTATOR functions:
29
30 **Attention:** to use a hook, first register your mutator using `REGISTER_MUTATOR`, then create your function using `MUTATOR_HOOKFUNCTION`.
31
32
33 - **`REGISTER_MUTATOR`**
34
35 Registers a new `MUTATOR_HOOKFUNCTION`.
36 ```c
37 REGISTER_MUTATOR(new_mutator_name, some_variable);
38 ```
39
40
41 - **`MUTATOR_HOOKFUNCTION`**
42
43 Creates a function and calls `new_mutator_name` (from `REGISTER_MUTATOR`) and one of `#define MUTATOR()` (from `qcsrc/server/mutators/events.qh` main hooks).
44
45 Example:
46 ```c
47 MUTATOR_HOOKFUNCTION(new_mutator_name, events.qh_main_hook)
48 {
49     // whatever does
50 }
51 ```
52
53 - **`MUTATOR_CALLHOOK`**
54
55 Calls some `MUTATOR_HOOKFUNCTION`.
56 ```c
57 MUTATOR_CALLHOOK(name_of_MUTATOR_HOOKFUNCTION_or_events.qh_main_hook);
58 ```
59
60 There are different versions and depends how many variables need to be called in a `MUTATOR_HOOKFUNCTION`:
61
62 1 `MUTATOR_HOOKFUNCTION` and 1 variable:
63
64 ```c
65 MUTATOR_CALLHOOK(name_of_MUTATOR_HOOKFUNCTION_or_events.qh_main_hook, some_variable);
66 ```
67
68 1 `MUTATOR_HOOKFUNCTION` and 2 variables:
69
70 ```c
71 MUTATOR_CALLHOOK(name_of_MUTATOR_HOOKFUNCTION_or_events.qh_main_hook, some_variable, some_variable);
72 ```
73
74 1 `MUTATOR_HOOKFUNCTION` and 3 variables:
75
76 ```c
77 MUTATOR_CALLHOOK(name_of_MUTATOR_HOOKFUNCTION_or_events.qh_main_hook, some_variable, some_variable, some_variable);
78 ```
79
80 1 `MUTATOR_HOOKFUNCTION` and multiple variables:
81
82 ```c
83 MUTATOR_CALLHOOK(name_of_MUTATOR_HOOKFUNCTION_or_events.qh_main_hook, some_variable, some_variable, some_variable, some_variable, ...);
84 ```
85
86 <br />
87
88 ## List of MUTATOR functions
89
90 You can look the MUTATOR functions in:
91
92 - **COMMON:** [`qcsrc/common/mutators/events.qh`](https://timepath.github.io/scratchspace/d4/d95/common_2mutators_2events_8qh.html)
93
94 - **CLIENT:** [`qcsrc/client/mutators/events.qh`](https://timepath.github.io/scratchspace/d8/d0e/client_2mutators_2events_8qh.html)
95
96 - **SERVER:** [`qcsrc/server/mutators/events.qh`](https://timepath.github.io/scratchspace/d6/ddd/server_2mutators_2events_8qh.html)
97
98 <br />
99 <br />
100
101 # WEAPON functions
102
103 ## A bit of introduction
104
105 You'll need understand that weapons can be interacted with **autocvars** variables (example: `float autocvar_g_balance_someweapon_speed;`) and each weapon with .qh file where cvars are declared without the need to declare using `autocvar_blabla...`. *Think*, *touch*, *explode* and those types of functions can be declared within an *attack* function and *whatever* it is called. Note that there are also METHODs that are necessary for the weapon to work.
106
107 - **Think** function makes the weapon shot react on what to do.
108 - **Touch** function makes the weapon shot react against some element where touch (like player, monster, vehicle, ...).
109 - **Explode** function makes the weapon explosion react.
110 - **Attack/Whatever** function is where the weapon attack executes, keep in mind that it has the other functions attached to be executed.
111
112 You can look the example of this weapon code:
113 - [**devastator.qh**](https://timepath.github.io/scratchspace/d9/dfa/devastator_8qh_source.html)
114 - [**devastator.qc**](https://timepath.github.io/scratchspace/d9/d5d/devastator_8qc_source.html)
115
116 <br />
117
118 ## List of WEAPON functions
119
120 This is a created list of functions to modify/create weapons. There may be incomplete explanations for each function.
121
122 There are contents taken from [`qcsrc/common/weapons/all.qh`](https://timepath.github.io/scratchspace/d0/ddd/weapons_2all_8qh_source.html)
123
124 **WARNING:** The contents may content wonky code, and the interactions can change and not do the same what happens here.
125
126 <br />
127
128 - [**W_SetupShot_Dir**](https://timepath.github.io/scratchspace/d4/d3f/tracing_8qh.html#aff0ea351757ee6caf83b25d12d18656c)
129
130 ```c
131 W_SetupShot_Dir(
132         ent,
133         wepent,
134         s_forward,
135         antilag,
136         recoil,
137         snd,
138         chan,
139         maxdamage,
140         deathtype 
141 )
142 ```
143
144 - [**W_SetupProjVelocity_Explicit**](https://timepath.github.io/scratchspace/d7/d31/tracing_8qc.html#a55f8f2b1828413bfb123a5fcb61b9f8e)
145
146 ```c
147 void W_SetupProjVelocity_Explicit(
148     entity      proj,
149     vector      dir,
150     vector      upDir,
151     float       pSpeed,
152     float       pUpSpeed,
153     float       pZSpeed,
154     float       spread,
155     float       forceAbsolute 
156 )
157 ```
158
159 - [**W_MuzzleFlash**](https://timepath.github.io/scratchspace/d0/ddd/weapons_2all_8qh_source.html)(located in **`qcsrc/common/weapons/all.qh`** line 406)
160
161 In the moment when player shots the weapon, weapon flashes. 
162
163 **Note:** write **`#ifdef SVQC`** at the start of using this function, and write with **`#endif`** after declared the function (only can do this if the code which needs execute can do this, although maybe you need more functions/things in the code inside this).
164
165 ```c
166 void W_MuzzleFlash(Weapon thiswep, entity actor, .entity weaponentity, vector shotorg, vector shotdir);
167 ```
168
169 - [**Weapon selection functions**](https://timepath.github.io/scratchspace/d8/d6b/selection_8qh.html)
170 (located in **`qcsrc/server/weapons/selection.qh`**)
171
172 - [**Weapon decrease ammo, speed factor, rate factor, reload functions**](https://timepath.github.io/scratchspace/d5/de0/weaponsystem_8qc.html)
173 (located in **`qcsrc/server/weapons/weaponsystem.qh`**)
174
175 <br />
176
177 # HUD, Menu and Draw functions
178
179 You can look the draw functions where HUD is being drawn: 
180 - [**Draw functions and macros (`qcsrc/client/draw.qh`)**](https://timepath.github.io/scratchspace/d5/d8d/client_2draw_8qh_source.html)
181
182 More info inside the code where you can draw/print HUD and menu: 
183 - [**Globals, constants, fonts, prints, error cmds, vector stuff, conversion functions and all drawing/printing HUDs/menus/characters related (`qcsrc/dpdefs/upstream/menudefs.qc`)**](https://timepath.github.io/scratchspace/d8/de2/menudefs_8qc_source.html)
184
185 <br />
186
187 AND... STILL more things in process