-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathsniper.qc
168 lines (131 loc) · 4.61 KB
/
sniper.qc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//========================================================
// Functions for the SNIPER class and associated weaponry
//========================================================
void (float zoom_to) Sniper_Zoom = {
self.default_fov = stof(infokey(self, "df"));
self.default_sensitivity = stof(infokey(self, "ds"));
self.zoom_fov = stof(infokey(self, "zf"));
if (self.default_fov == 0)
return;
if (zoom_to >= self.default_fov)
Sniper_ZoomReset(self);
else if (zoom_to != self.current_fov) {
if (zoom_to < self.default_fov)
self.zoom_last = zoom_to;
self.current_fov = zoom_to;
stuffcmd(self, "fov ");
stuffcmd(self, ftos(zoom_to));
stuffcmd(self, "\n");
if (self.default_sensitivity > 0) {
stuffcmd(self, "sensitivity ");
stuffcmd(self, ftos(self.default_sensitivity * zoom_to / self.default_fov));
stuffcmd(self, "\n");
}
}
};
void (entity pl) Sniper_ZoomReset = {
pl.default_sensitivity = stof(infokey(pl, "ds"));
pl.default_fov = stof(infokey(pl, "df"));
pl.is_zooming = 0;
if (pl.default_fov > 0) {
pl.current_fov = pl.default_fov;
stuffcmd(pl, "fov ");
stuffcmd(pl, ftos(pl.default_fov));
stuffcmd(pl, "\n");
}
if (pl.default_sensitivity > 0) {
stuffcmd(pl, "sensitivity ");
stuffcmd(pl, ftos(pl.default_sensitivity));
stuffcmd(pl, "\n");
}
};
void () Sniper_ZoomToggle = {
local float magnification = 0;
local float zoom_to = 0;
if (self.playerclass != PC_SNIPER)
return;
self.default_fov = stof(infokey(self, "df"));
self.default_sensitivity = stof(infokey(self, "ds"));
self.zoom_fov = stof(infokey(self, "zf"));
if (self.default_fov == 0) {
sprint(self, PRINT_HIGH, "Use \"setinfo df <fov>\" to set default fov to use sniper zoom. Use \"setinfo ds <sensitivity>\" to set default sensitivity for sensitivity scaling.\n");
return;
}
if (self.is_zooming) {
self.is_zooming = 0;
zoom_to = self.default_fov;
sprint(self, PRINT_HIGH, "Zoomed out\n");
} else {
self.is_zooming = 1;
if (self.zoom_last && self.zoom_last < self.default_fov)
zoom_to = self.zoom_last;
else if (self.zoom_fov)
zoom_to = self.zoom_fov;
else
zoom_to = 30;
magnification = floor(self.default_fov / zoom_to);
sprint(self, PRINT_HIGH, ftos(magnification), "x zoom\n");
}
Sniper_Zoom(zoom_to);
};
void (float zoom_in) Sniper_ZoomAdjust = {
local float zoom_to = 0;
local float zoom_steps = 0;
if (self.playerclass != PC_SNIPER || !self.is_zooming)
return;
zoom_steps = stof(infokey(self, "zs"));
if (!zoom_steps)
zoom_steps = 5;
if (self.default_fov == 0) {
sprint(self, PRINT_HIGH, "Use \"setinfo df <fov>\" to set default fov to use sniper zoom. Use \"setinfo ds <sensitivity>\" to set default sensitivity for sensitivity scaling.\n");
return;
}
if (zoom_in)
zoom_to = self.current_fov - zoom_steps;
else
zoom_to = self.current_fov + zoom_steps;
if (zoom_to <= 10)
zoom_to = 10;
else if (zoom_to >= self.default_fov)
zoom_to = self.default_fov;
self.zoom_last = zoom_to;
Sniper_Zoom(zoom_to);
};
void () SniperSight_Update = {
local vector org;
if (!(self.owner.tfstate & TFSTATE_AIMING) ||
(self.owner.current_weapon != WEAP_SNIPER_RIFLE)) {
self.owner.tfstate =
self.owner.tfstate - (self.owner.tfstate & TFSTATE_AIMING);
TeamFortress_SetSpeed(self.owner);
self.owner.heat = 0;
dremove(self);
return;
}
makevectors(self.owner.v_angle);
org = self.owner.origin + v_forward * 10;
org_z = self.owner.absmin_z + self.owner.size_z * 0.7;
traceline(org, org + v_forward * 9192, FALSE, self);
if (trace_fraction == 1) {
setorigin(self, self.owner.origin);
return;
}
self.angles = vectoangles(v_forward);
setorigin(self, trace_endpos);
self.nextthink = time + 0.1;
};
void () SniperSight_Create = {
local entity sight;
if (self.has_disconnected == TRUE || (self.tfstate & TFSTATE_RELOADING))
return;
self.tfstate = self.tfstate | TFSTATE_AIMING;
sight = spawn();
sight.owner = self;
sight.movetype = MOVETYPE_NOCLIP;
sight.solid = SOLID_NOT;
setmodel(sight, "progs/sight.spr");
sight.classname = "timer";
setorigin(sight, self.origin);
sight.think = SniperSight_Update;
sight.nextthink = time + 0.05;
};