-
Notifications
You must be signed in to change notification settings - Fork 0
/
brap.as
468 lines (393 loc) · 15.6 KB
/
brap.as
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
class Brap {
EHandle h_sprite;
EHandle h_model;
float expire_time; // time brap should be deleted if inactive
Brap(EHandle h_sprite, EHandle h_model, float lifetime=BRAP_LIFE) {
this.h_sprite = h_sprite;
this.h_model = h_model;
expire_time = g_Engine.time + lifetime;
}
Brap() {}
}
array<Brap> g_braps;
array<float> g_sniffers(g_Engine.maxClients+1); // value = time sniff will end
array<string> brap_sprites = {
"sprites/sence/cloud1.spr",
"sprites/sence/cloud2.spr",
"sprites/sence/cloud3.spr",
"sprites/sence/cloud4.spr"
};
const string cycler_model = "models/scmod/null.mdl";
const float SNIFF_DISTANCE = 256;
const float BRAP_SPR_SCALE = 0.2f; // sprite scale at maximum size
const float INHALE_DIST = 96.0f; // distance that sniffing affects braps
const float KILL_DIST = 8.0f; // braps are killed within this range
const float BRAP_LIFE = 20.0f; // braps live for this long before being deleted
const float BRAP_RENDER_AMT = 24.0f;
const float BRAP_SPREAD_DIST = 16.0f; // braps will push each other away within this dist
CClientCommand _brapcolor("brapcolor", "Set brap color", @brapcolor_cmd);
void brapcolor_cmd(const CCommand@ args) {
CBasePlayer@ plr = g_ConCommandSystem.GetCurrentPlayer();
brapcolor(plr, args);
}
void brapcolor(CBasePlayer@ plr, const CCommand@ args) {
PlayerState@ state = getPlayerState(plr);
if (args.ArgC() < 4) {
g_PlayerFuncs.ClientPrint(plr, HUD_PRINTTALK, ".brapcolor requires 3 values for red, green, and blue (0-255).\n");
} else {
state.brapColor = Vector(
Math.clamp(0, 255, atoi(args[1])),
Math.clamp(0, 255, atoi(args[2])),
Math.clamp(0, 255, atoi(args[3]))
);
}
string brapStr = "" + int(state.brapColor.x) + " " + int(state.brapColor.y) + " " + int(state.brapColor.z);
g_PlayerFuncs.ClientPrint(plr, HUD_PRINTTALK, "Your brap color is: " + brapStr + "\n");
}
void te_bubbles(Vector mins, Vector maxs, float height=256.0f,
string sprite="sprites/bubble.spr", uint8 count=64, float speed=16.0f,
NetworkMessageDest msgType=MSG_BROADCAST, edict_t@ dest=null)
{
NetworkMessage m(msgType, NetworkMessages::SVC_TEMPENTITY, dest);
m.WriteByte(TE_BUBBLES);
m.WriteCoord(mins.x);
m.WriteCoord(mins.y);
m.WriteCoord(mins.z);
m.WriteCoord(maxs.x);
m.WriteCoord(maxs.y);
m.WriteCoord(maxs.z);
m.WriteCoord(height);
m.WriteShort(g_EngineFuncs.ModelIndex(sprite));
m.WriteByte(count);
m.WriteCoord(speed);
m.End();
}
void te_bloodsprite(Vector pos, string sprite1="sprites/bloodspray.spr",
string sprite2="sprites/blood.spr", uint8 color=70, uint8 scale=3,
NetworkMessageDest msgType=MSG_BROADCAST, edict_t@ dest=null)
{
NetworkMessage m(msgType, NetworkMessages::SVC_TEMPENTITY, dest);
m.WriteByte(TE_BLOODSPRITE);
m.WriteCoord(pos.x);
m.WriteCoord(pos.y);
m.WriteCoord(pos.z);
m.WriteShort(g_EngineFuncs.ModelIndex(sprite1));
m.WriteShort(g_EngineFuncs.ModelIndex(sprite2));
m.WriteByte(color);
m.WriteByte(scale);
m.End();
}
// multiply a matrix with a vector (assumes w component of vector is 1.0f)
Vector matMultVector(array<float> rotMat, Vector v)
{
Vector outv;
outv.x = rotMat[0]*v.x + rotMat[4]*v.y + rotMat[8]*v.z + rotMat[12];
outv.y = rotMat[1]*v.x + rotMat[5]*v.y + rotMat[9]*v.z + rotMat[13];
outv.z = rotMat[2]*v.x + rotMat[6]*v.y + rotMat[10]*v.z + rotMat[14];
return outv;
}
array<float> rotationMatrix(Vector axis, float angle)
{
axis = axis.Normalize();
float s = sin(angle);
float c = cos(angle);
float oc = 1.0 - c;
array<float> mat = {
oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0,
oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0,
oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0,
0.0, 0.0, 0.0, 1.0
};
return mat;
}
// Randomize the direction of a vector by some amount
// Max degrees = 360, which makes a full sphere
Vector spreadDir(Vector dir, float degrees)
{
float spread = Math.DegreesToRadians(degrees) * 0.5f;
float x, y;
Vector vecAiming = dir;
float c = Math.RandomFloat(0, Math.PI*2); // random point on circle
float r = Math.RandomFloat(-1, 1); // random radius
x = cos(c) * r * spread;
y = sin(c) * r * spread;
// get "up" vector relative to aim direction
Vector pitAxis = CrossProduct(dir, Vector(0, 0, 1)).Normalize(); // get left vector of aim dir
Vector yawAxis = CrossProduct(dir, pitAxis).Normalize(); // get up vector relative to aim dir
// Apply rotation around arbitrary "up" axis
array<float> yawRotMat = rotationMatrix(yawAxis, x);
vecAiming = matMultVector(yawRotMat, vecAiming).Normalize();
// Apply rotation around "left/right" axis
array<float> pitRotMat = rotationMatrix(pitAxis, y);
vecAiming = matMultVector(pitRotMat, vecAiming).Normalize();
return vecAiming;
}
CBaseEntity@ getTootEnt(CBasePlayer@ plr) {
if (plr.IsAlive() || plr.pev.effects & EF_NODRAW == 0) {
return plr;
}
if (plr.GetObserver().IsObserver() && plr.GetObserver().HasCorpse()) {
CBaseEntity@ ent = null;
do {
@ent = g_EntityFuncs.FindEntityByClassname(ent, "deadplayer");
if (ent !is null) {
CustomKeyvalues@ pCustom = ent.GetCustomKeyvalues();
CustomKeyvalue ownerKey( pCustom.GetKeyvalue( "$i_hipoly_owner" ) );
if (ownerKey.Exists() && ownerKey.GetInteger() == plr.entindex()) {
return ent;
}
}
} while (ent !is null);
}
return null;
}
bool canTootEffect(CBasePlayer@ plr) {
return plr.IsAlive() || (plr.pev.effects & EF_NODRAW == 0) || (plr.GetObserver().IsObserver() && plr.GetObserver().HasCorpse());
}
void bubble_toot(EHandle h_plr, int power) {
CBaseEntity@ plr = h_plr;
if (plr is null) {
return;
}
if (plr.pev.waterlevel >= WATERLEVEL_WAIST) {
Vector pos = plr.pev.origin;
Vector sz = Vector(8,8,8);
if (!plr.IsAlive()) {
pos.z -= (35 - sz.z);
}
float bottomZ = pos.z - sz.z;
float height = g_Utility.WaterLevel(pos - Vector(0,0,sz.z), bottomZ, bottomZ + 1024);
te_bubbles(pos - sz, pos + sz, height - bottomZ, "sprites/bubble.spr", power, 16);
}
}
void cloud_toot(EHandle h_ent, float spread, float baseSpeed, float speedMultMax, float braplife) {
CBaseEntity@ ent = h_ent;
CBasePlayer@ plr = cast<CBasePlayer@>(ent);
if (ent is null) {
return;
}
if (plr is null and ent.pev.classname == "deadplayer") {
CustomKeyvalues@ pCustom = ent.GetCustomKeyvalues();
CustomKeyvalue ownerKey( pCustom.GetKeyvalue( "$i_hipoly_owner" ) );
if (ownerKey.Exists()) {
@plr = @g_PlayerFuncs.FindPlayerByIndex(ownerKey.GetInteger());
}
}
Vector brapColor = Vector(200, 255, 200);
if (plr !is null) {
PlayerState@ state = getPlayerState(plr);
brapColor = state.brapColor;
}
float speed = baseSpeed * Math.RandomFloat(0.8f, speedMultMax);
Vector buttPos = ent.pev.origin;
Vector angles = ent.pev.v_angle;
angles.x = 0;
Math.MakeVectors(angles);
Vector dir = g_Engine.v_forward;
dir = spreadDir(dir, spread) * -speed;
if (!ent.IsAlive()) {
buttPos.z -= 35;
float u = Math.RandomFloat(0, 1);
float v = Math.RandomFloat(0, 1);
float theta = 2 * Math.PI * u;
float phi = acos(2 * v - 1);
float x = sin(phi) * cos(theta);
float y = sin(phi) * sin(theta);
float z = abs(cos(phi));
dir = Vector(x, y, z)*speed*0.3f;
}
dictionary keys;
keys["origin"] = buttPos.ToString();
keys["velocity"] = dir.ToString();
keys["model"] = cycler_model;
CBaseEntity@ brapModel = g_EntityFuncs.CreateEntity("cycler", keys, true);
brapModel.pev.solid = SOLID_NOT;
brapModel.pev.movetype = MOVETYPE_FLY;
brapModel.pev.velocity = dir;
g_EntityFuncs.SetSize(brapModel.pev, Vector(0,0,0), Vector(0,0,0));
keys["origin"] = buttPos.ToString();
keys["velocity"] = dir.ToString();
keys["model"] = brap_sprites[Math.RandomLong(0, brap_sprites.size()-1)];
keys["rendermode"] = "5";
keys["renderamt"] = "" + BRAP_RENDER_AMT;
keys["rendercolor"] = brapColor.ToString();
keys["scale"] = "0.01";
CBaseEntity@ brapSprite = g_EntityFuncs.CreateEntity("env_sprite", keys, true);
brapSprite.pev.movetype = MOVETYPE_FOLLOW;
@brapSprite.pev.aiment = @brapModel.edict();
g_braps.insertLast(Brap(EHandle(brapSprite), EHandle(brapModel), braplife));
}
void shit(EHandle h_plr, int scale, bool isBlood) {
CBaseEntity@ plr = h_plr;
if (plr is null) {
return;
}
Vector buttPos = plr.pev.origin;
if (!plr.IsAlive()) {
buttPos.z -= 35;
}
int color = isBlood ? 70 : 22;
te_bloodsprite(buttPos + g_Engine.v_forward*-4, "sprites/bloodspray.spr", "sprites/blood.spr", color, scale);
}
void do_brap(CBasePlayer@ plr, string arg, float pitch) {
if (!canTootEffect(plr)) {
return;
}
float speed = (100.0f/pitch);
CBaseEntity@ tootEnt = getTootEnt(plr);
if (tootEnt is null) {
return;
}
if (tootEnt.pev.waterlevel >= WATERLEVEL_WAIST) {
if (arg == "brap" || arg == "bloodbrap") {
g_Scheduler.SetInterval("bubble_toot", 0.05f*speed, 16, EHandle(tootEnt), 4);
g_Scheduler.SetInterval("shit", 0.05f*speed, 15, EHandle(tootEnt), 8, arg == "bloodbrap");
} else if (arg == "braprape" || arg == "bloodbraprape") {
g_Scheduler.SetInterval("bubble_toot", 0.05f*speed, 16, EHandle(tootEnt), 16);
g_Scheduler.SetInterval("shit", 0.05f*speed, 15, EHandle(tootEnt), 32, arg == "bloodbraprape");
} else if (arg == "toot") {
g_Scheduler.SetInterval("bubble_toot", 0.05f*speed, 1, EHandle(tootEnt), 12);
} else if (arg == "tooot") {
g_Scheduler.SetInterval("bubble_toot", 0.05f*speed, 1, EHandle(tootEnt), 40);
} else if (arg == "tootrape") {
g_Scheduler.SetInterval("bubble_toot", 0.05f*speed, 2, EHandle(tootEnt), 180);
} else if (arg == "braplong") {
g_Scheduler.SetInterval("bubble_toot", 0.05f*speed, 270, EHandle(tootEnt), 2);
}
} else {
if (arg == "brap" || arg == "bloodbrap") {
g_Scheduler.SetInterval("cloud_toot", 0.1f*speed, 8, EHandle(tootEnt), 90.0f, 100.0f, 1.5f, BRAP_LIFE);
g_Scheduler.SetInterval("shit", 0.05f*speed, 20, EHandle(tootEnt), 8, arg == "bloodbrap");
} else if (arg == "braprape" || arg == "bloodbraprape") {
g_Scheduler.SetInterval("cloud_toot", 0.05f*speed, 15, EHandle(tootEnt), 360.0f, 150.0f, 2.0f, BRAP_LIFE);
g_Scheduler.SetInterval("shit", 0.05f*speed, 15, EHandle(tootEnt), 32, arg == "bloodbraprape");
} else if (arg == "toot") {
g_Scheduler.SetInterval("cloud_toot", 0.05f*speed, 1, EHandle(tootEnt), 0, 100.0f, 1.0f, BRAP_LIFE);
} else if (arg == "tooot") {
for (uint i = 0; i < 10; i++) {
g_Scheduler.SetInterval("cloud_toot", 0.05f*speed, 1, EHandle(tootEnt), 20.0f, 100.0f, 3.0f, BRAP_LIFE);
}
} else if (arg == "braplong") {
g_Scheduler.SetInterval("cloud_toot", 0.288f*speed, 48, EHandle(tootEnt), 10.0f, 20.0f, 3.0f, BRAP_LIFE*0.2f*speed);
g_Scheduler.SetTimeout("cloud_toot", 13.8f*speed, EHandle(tootEnt), 20.0f, 40.0f, 3.0f, BRAP_LIFE*0.5f);
g_Scheduler.SetTimeout("cloud_toot", 13.8f*speed, EHandle(tootEnt), 20.0f, 40.0f, 3.0f, BRAP_LIFE*0.5f);
g_Scheduler.SetTimeout("cloud_toot", 13.8f*speed, EHandle(tootEnt), 20.0f, 40.0f, 3.0f, BRAP_LIFE*0.5f);
g_Scheduler.SetTimeout("cloud_toot", 13.8f*speed, EHandle(tootEnt), 20.0f, 40.0f, 3.0f, BRAP_LIFE*0.5f);
g_Scheduler.SetTimeout("cloud_toot", 14.9f*speed, EHandle(tootEnt), 20.0f, 40.0f, 3.0f, BRAP_LIFE*0.5f);
g_Scheduler.SetTimeout("cloud_toot", 14.9f*speed, EHandle(tootEnt), 20.0f, 40.0f, 3.0f, BRAP_LIFE*0.5f);
g_Scheduler.SetTimeout("cloud_toot", 14.9f*speed, EHandle(tootEnt), 20.0f, 40.0f, 3.0f, BRAP_LIFE*0.5f);
g_Scheduler.SetTimeout("cloud_toot", 14.9f*speed, EHandle(tootEnt), 20.0f, 40.0f, 3.0f, BRAP_LIFE*0.5f);
} else if (arg == "tootrape") {
for (uint i = 0; i < 40; i++) {
g_Scheduler.SetInterval("cloud_toot", 0.05f*speed, 1, EHandle(tootEnt), 20.0f, 200.0f, 8.0f, BRAP_LIFE);
}
}
}
}
void do_sniff(CBasePlayer@ plr, string arg, float pitch) {
float sniff_time = 1.3f;
if (arg == "sniff") {
sniff_time = 1.3f;
}
else if (arg == "snifff") {
sniff_time = 1.0f;
}
else if (arg == "sniffrape") {
sniff_time = 4.0f;
}
g_sniffers[plr.entindex()] = g_Engine.time + (sniff_time * (100.0f/pitch));
}
void brap_precache() {
for (uint i = 0; i < brap_sprites.size(); i++) {
g_Game.PrecacheModel(brap_sprites[i]);
}
g_Game.PrecacheModel(cycler_model);
g_sniffers.resize(0);
g_sniffers.resize(g_Engine.maxClients+1);
}
void brap_think() {
array<Brap> new_braps;
array<CBaseEntity@> sniffSources;
for (uint i = 1; i < g_sniffers.size(); i++) {
if (g_sniffers[i] > g_Engine.time) {
CBasePlayer@ plr = g_PlayerFuncs.FindPlayerByIndex(i);
if (plr !is null) {
CBaseEntity@ tootEnt = getTootEnt(plr);
if (tootEnt !is null) {
sniffSources.insertLast(tootEnt);
}
}
}
}
for (uint i = 0; i < g_braps.size(); i++) {
CBaseEntity@ brap = g_braps[i].h_sprite;
CBaseEntity@ mdl = g_braps[i].h_model;
if (brap is null or mdl is null or g_braps[i].expire_time < g_Engine.time) {
g_EntityFuncs.Remove(g_braps[i].h_sprite);
g_EntityFuncs.Remove(g_braps[i].h_model);
continue;
}
if (sniffSources.size() > 0) {
for (uint k = 0; k < sniffSources.size(); k++) {
CBaseEntity@ sniffer = sniffSources[k];
bool isDucking = sniffer.pev.flags & FL_DUCKING != 0;
Vector sniffTarget = sniffer.pev.origin + Vector(0,0, isDucking ? 10 : 26);
if (!sniffer.IsAlive()) {
sniffTarget.z = sniffer.pev.origin.z - 35;
}
Vector sniffDelta = sniffTarget - mdl.pev.origin;
float dist = sniffDelta.Length();
if (dist > SNIFF_DISTANCE) {
continue;
}
mdl.pev.velocity = sniffDelta.Normalize() * (SNIFF_DISTANCE - dist)*0.5f;
float targetScale = BRAP_SPR_SCALE;
if (dist < INHALE_DIST) {
float newScale = dist != 0 ? (dist / INHALE_DIST) * BRAP_SPR_SCALE : 0.05f;
targetScale = Math.max(newScale, 0.001f);
}
if (brap.pev.scale > targetScale*1.2f) {
brap.pev.scale *= 0.8f;
} else if (brap.pev.scale < targetScale*0.8f) {
brap.pev.scale *= 1.2f;
}
if (dist < KILL_DIST and brap.pev.scale < BRAP_SPR_SCALE*0.1f) {
sniffer.TakeDamage(mdl.pev, mdl.pev, 1, DMG_NERVEGAS | DMG_SNIPER); // bypass armor
g_EntityFuncs.Remove(g_braps[i].h_sprite);
g_EntityFuncs.Remove(g_braps[i].h_model);
continue;
}
}
} else {
CBaseEntity@ otherBrap = null;
do {
@otherBrap = g_EntityFuncs.FindEntityInSphere(otherBrap, mdl.pev.origin, BRAP_SPREAD_DIST, "cycler", "classname");
if (otherBrap !is null and otherBrap.entindex() != mdl.entindex()) {
mdl.pev.velocity = mdl.pev.velocity + (mdl.pev.origin - otherBrap.pev.origin)*0.1f;
}
} while (otherBrap !is null);
mdl.pev.velocity = mdl.pev.velocity * 0.9f;
if (mdl.pev.velocity.Length() < 1) {
mdl.pev.velocity = Vector(0,0,0);
}
if (brap.pev.scale < BRAP_SPR_SCALE) {
brap.pev.scale *= 1.2f;
if (brap.pev.scale > BRAP_SPR_SCALE) {
brap.pev.scale = BRAP_SPR_SCALE;
}
}
}
float life_left = g_braps[i].expire_time - g_Engine.time;
if (life_left < 3.0f) {
brap.pev.renderamt = (life_left / 3.0f) * BRAP_RENDER_AMT;
}
new_braps.insertLast(g_braps[i]);
}
g_braps = new_braps;
}
void brap_unload() {
for (uint i = 0; i < g_braps.size(); i++) {
g_EntityFuncs.Remove(g_braps[i].h_sprite);
g_EntityFuncs.Remove(g_braps[i].h_model);
}
}