]> git.xonotic.org Git - xonotic/xonotic.wiki.git/blob - Functions-and-other-programming-QuakeC-things-in-Xonotic.md
Added Menu and Draw functions, weapons introduction and short dev guide. Fixed some...
[xonotic/xonotic.wiki.git] / Functions-and-other-programming-QuakeC-things-in-Xonotic.md
1 **Note:** The article is written as developer notes to ease developer tasks and save QuakeC function terms here. Some references are taken from `events.qh`.
2
3
4 # MUTATOR functions (from: `qcsrc/client/mutators/events.qh`, `qcsrc/common/mutators/events.qh`, `qcsrc/server/mutators/events.qh`)
5
6 ### How to use MUTATOR functions:
7
8 **Attention:** to use a hook, first register your mutator using `REGISTER_MUTATOR`, then create your function using `MUTATOR_HOOKFUNCTION`.
9
10
11 - **`REGISTER_MUTATOR`**
12
13 Registers a new `MUTATOR_HOOKFUNCTION`.
14 ```c
15 REGISTER_MUTATOR(new_mutator_name, some_variable);
16 ```
17
18
19 - **`MUTATOR_HOOKFUNCTION`**
20
21 Creates a function and calls `new_mutator_name` (from `REGISTER_MUTATOR`) and one of `#define MUTATOR()` (from `qcsrc/server/mutators/events.qh` main hooks).
22
23 Example:
24 ```c
25 MUTATOR_HOOKFUNCTION(new_mutator_name, events.qh_main_hook)
26 {
27     // whatever does
28 }
29 ```
30
31 - **`MUTATOR_CALLHOOK`**
32
33 Calls some `MUTATOR_HOOKFUNCTION`.
34 ```c
35 MUTATOR_CALLHOOK(name_of_MUTATOR_HOOKFUNCTION_or_events.qh_main_hook);
36 ```
37
38 There are different versions and depends how many variables need to be called in a `MUTATOR_HOOKFUNCTION`:
39
40 1 `MUTATOR_HOOKFUNCTION` and 1 variable:
41
42 ```c
43 MUTATOR_CALLHOOK(name_of_MUTATOR_HOOKFUNCTION_or_events.qh_main_hook, some_variable);
44 ```
45
46 1 `MUTATOR_HOOKFUNCTION` and 2 variables:
47
48 ```c
49 MUTATOR_CALLHOOK(name_of_MUTATOR_HOOKFUNCTION_or_events.qh_main_hook, some_variable, some_variable);
50 ```
51
52 1 `MUTATOR_HOOKFUNCTION` and 3 variables:
53
54 ```c
55 MUTATOR_CALLHOOK(name_of_MUTATOR_HOOKFUNCTION_or_events.qh_main_hook, some_variable, some_variable, some_variable);
56 ```
57
58 1 `MUTATOR_HOOKFUNCTION` and multiple variables:
59
60 ```c
61 MUTATOR_CALLHOOK(name_of_MUTATOR_HOOKFUNCTION_or_events.qh_main_hook, some_variable, some_variable, some_variable, some_variable, ...);
62 ```
63
64 <br />
65 <br />
66
67
68 ## List of MUTATOR functions
69
70 You can look the MUTATOR functions in:
71
72 **COMMON**:
73
74 **`qcsrc/common/mutators/events.qh`** :
75 https://timepath.github.io/scratchspace/d4/d95/common_2mutators_2events_8qh.html
76
77
78 **CLIENT**:
79
80 **`qcsrc/client/mutators/events.qh`** :
81 https://timepath.github.io/scratchspace/d8/d0e/client_2mutators_2events_8qh.html
82
83
84 **SERVER**:
85
86 **`qcsrc/server/mutators/events.qh`** :
87 https://timepath.github.io/scratchspace/d6/ddd/server_2mutators_2events_8qh.html
88
89
90 <br />
91 <br />
92
93 # WEAPON functions
94
95 ## A bit of introduction
96
97 You'll need understand that weapons can be interacted with autocvars variables and its own .qh file where cvars are declared. *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.
98
99 - **Think** function makes the weapon shot react on what to do.
100 - **Touch** function makes the weapon shot react against some element where touch (like player, monster, vehicle, ...).
101 - **Explode** function makes the weapon explosion react.
102 - **Attack/Whatever** function is where the weapon attack executes, keep in mind that it has the other functions attached to be executed.
103
104 You can look the example of this weapon code:
105 - [**devastator.qh**](https://timepath.github.io/scratchspace/d9/dfa/devastator_8qh_source.html)
106 - [**devastator.qc**](https://timepath.github.io/scratchspace/d9/d5d/devastator_8qc_source.html)
107
108 <br />
109
110 ## List of WEAPON functions
111
112 This is a created list of functions to modify/create weapons. There are incomplete explanations for each function.
113
114 There are contents taken from `qcsrc/common/weapons/all.qh`.
115
116 **WARNING:** The contents may content wonky code, and the interactions can change and not do the same what happens here.
117
118 <br />
119
120 - [**W_SetupShot_Dir**](https://timepath.github.io/scratchspace/d4/d3f/tracing_8qh.html#aff0ea351757ee6caf83b25d12d18656c)
121
122 ```c
123 W_SetupShot_Dir(
124         ent,
125         wepent,
126         s_forward,
127         antilag,
128         recoil,
129         snd,
130         chan,
131         maxdamage,
132         deathtype 
133 )
134 ```
135
136 - [**W_SetupProjVelocity_Explicit**](https://timepath.github.io/scratchspace/d7/d31/tracing_8qc.html#a55f8f2b1828413bfb123a5fcb61b9f8e)
137
138 ```c
139 void W_SetupProjVelocity_Explicit(
140     entity      proj,
141     vector      dir,
142     vector      upDir,
143     float       pSpeed,
144     float       pUpSpeed,
145     float       pZSpeed,
146     float       spread,
147     float       forceAbsolute 
148 )
149 ```
150
151 - [**W_MuzzleFlash**](https://timepath.github.io/scratchspace/d0/ddd/weapons_2all_8qh_source.html)(located in `qcsrc/common/weapons/all.qh` line 406)
152
153 In the moment when player shots the weapon, weapon flashes. 
154
155 *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).
156
157 ```c
158 void W_MuzzleFlash(Weapon thiswep, entity actor, .entity weaponentity, vector shotorg, vector shotdir);
159 ```
160
161 - [**Weapon selection functions**](https://timepath.github.io/scratchspace/d8/d6b/selection_8qh.html)
162 (located in `qcsrc/server/weapons/selection.qh`)
163
164 - [**Weapon decrease ammo, speed factor, rate factor, reload functions**](https://timepath.github.io/scratchspace/d5/de0/weaponsystem_8qc.html)
165 (located in `qcsrc/server/weapons/weaponsystem.qh`)
166
167 <br />
168 <br />
169
170 # Menu and Draw functions
171
172 You can look the draw functions where HUD is being drawn: 
173 - [**Draw functions and macros (`qcsrc/client/draw.qh`)**](https://timepath.github.io/scratchspace/d5/d8d/client_2draw_8qh_source.html)
174
175 More info inside the code where you can draw/print HUD and menu: 
176 - [**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)
177
178 <br />
179
180 AND... STILL more things in process