-
Notifications
You must be signed in to change notification settings - Fork 3
/
gfldm-anim.sp
665 lines (558 loc) · 21.3 KB
/
gfldm-anim.sp
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
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
// Copyright (C) 2020 dreae
//
// This file is part of gfl-dm-pack.
//
// gfl-dm-pack is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// gfl-dm-pack is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with gfl-dm-pack. If not, see <http://www.gnu.org/licenses/>.
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <gfldm>
#include <gfldm-anim>
public Plugin myinfo = {
name = "GFLDM Animation",
author = "Dreae",
description = "Helpers for timing scripted events",
version = GFLDM_VERSION,
url = "https://github.com/GFLClan/gfl-dm-pack"
};
#define EXPLODE_SOUND_LOUD "ambient/explosions/explode_9.wav"
#define EXPLODE_SOUND "ambient/explosions/explode_8.wav"
#define SNDCHAN_AMBIENT 8
#define TESLA_SPRITE "sprites/physbeam.vmt"
int explosion_sprite;
int smoke_sprite;
int lightning_sprite;
public void OnPluginStart() {
GFLDM_DefineVersion("gfldm_anim_version");
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) {
CreateNative("GFLDM_StartAnimAll", native_CreateAnimation);
CreateNative("GFLDM_StartAnimOne", native_CreateSingleAnimation);
CreateNative("GFLDMAnimation.AddTimedCallback", native_AddAnimCallback);
CreateNative("GFLDMAnimation.AddExplosion", native_AddExplosion);
CreateNative("GFLDMAnimation.AddLightning", native_AddLightning);
CreateNative("GFLDMAnimation.AddAmbientSound", native_AddAmbientSound);
CreateNative("GFLDMAnimation.AddSound", native_AddSound);
CreateNative("GFLDMAnimation.AddFire", native_AddFire);
CreateNative("GFLDMAnimation.AddTesla", native_AddTesla);
CreateNative("GFLDMAnimation.Play", native_Play);
CreateNative("GFLDMAnimation.TE_Send", native_TE_Send);
CreateNative("GFLDMAnimation.EmitAmbientSound", native_EmitAmbientSound);
CreateNative("GFLDMAnimation.EmitSound", native_EmitSound);
CreateNative("GFLDMHudElement.GFLDMHudElement", native_HudElement);
CreateNative("GFLDMHudElement.SetColor", native_SetColor);
CreateNative("GFLDMHudElement.Draw", native_Draw);
CreateNative("GFLDMHudElement.Clear", native_Clear);
CreateNative("GFLDMHudElement.CloseTrie", native_CloseHud);
RegPluginLibrary("gfldm-anim");
}
public void OnMapStart() {
PrecacheSound(EXPLODE_SOUND_LOUD, true);
PrecacheSound(EXPLODE_SOUND, true);
explosion_sprite = PrecacheModel("sprites/plasma.vmt");
smoke_sprite = PrecacheModel("sprites/steam1.vmt");
lightning_sprite = PrecacheModel("sprites/lgtning.vmt");
PrecacheModel(TESLA_SPRITE);
}
public any native_HudElement(Handle plugin, int num_params) {
int client = GetNativeCell(1);
float x = GetNativeCell(2);
float y = GetNativeCell(3);
int default_color[4] = {255, 255, 255, 255};
StringMap hud = new StringMap();
hud.SetValue("client", client);
hud.SetValue("synchronizer", CreateHudSynchronizer());
hud.SetValue("x", x);
hud.SetValue("y", y);
hud.SetArray("color", default_color, sizeof(default_color));
return hud;
}
public any native_SetColor(Handle plugin, int num_params) {
StringMap hud = GFLDM_GetNativeHandle(1);
int color[4];
GetNativeArray(2, color, sizeof(color));
hud.SetArray("color", color, sizeof(color));
}
public any native_Draw(Handle plugin, int num_params) {
StringMap hud = GFLDM_GetNativeHandle(1);
float hold_time = GetNativeCell(2);
int client;
if (hud.GetValue("client", client) && GFLDM_IsValidClient(client)) {
Handle synchronizer;
hud.GetValue("synchronizer", synchronizer);
float x, y;
hud.GetValue("x", x);
hud.GetValue("y", y);
int color[4];
hud.GetArray("color", color, sizeof(color));
char buffer[1024];
int written;
SetGlobalTransTarget(client);
FormatNativeString(0, 3, 4, sizeof(buffer), written, buffer);
SetGlobalTransTarget(LANG_SERVER);
SetHudTextParams(x, y, hold_time, color[0], color[1], color[2], color[3]);
ShowSyncHudText(client, synchronizer, buffer);
}
}
public any native_Clear(Handle plugin, int num_params) {
StringMap hud = GFLDM_GetNativeHandle(1);
int client;
if (hud.GetValue("client", client) && GFLDM_IsValidClient(client)) {
Handle synchronizer;
hud.GetValue("synchronizer", synchronizer);
ClearSyncHud(client, synchronizer);
}
}
public any native_CloseHud(Handle plugin, int num_params) {
StringMap hud = GFLDM_GetNativeHandle(1);
Handle synchronizer;
if (hud.GetValue("synchronizer", synchronizer) && synchronizer != INVALID_HANDLE) {
delete synchronizer;
}
delete hud;
}
public any native_CreateAnimation(Handle plugin, int numParams) {
DataPack anim = new DataPack();
anim.WriteCell(AnimTarget_All);
anim.WriteCell(0);
return anim;
}
public any native_CreateSingleAnimation(Handle plugin, int numParams) {
int target = GetNativeCell(1);
DataPack anim = new DataPack();
anim.WriteCell(AnimTarget_One);
anim.WriteCell(target);
return anim;
}
public int native_AddAnimCallback(Handle plugin, int numParams) {
DataPack self = GFLDM_GetNativeHandle(1);
AnimationFunction callback = GetNativeCell(2);
DataPack anim_data = GFLDM_GetNativeHandle(3);
float delay = GetNativeCell(4);
DataPack frame_data = MakeFrameData(self, plugin, callback, anim_data);
self.WriteFloat(delay);
self.WriteCell(frame_data);
return 0;
}
public int native_AddExplosion(Handle plugin, int numParams) {
float pos[3];
DataPack self = GFLDM_GetNativeHandle(1);
GetNativeArray(2, pos, sizeof(pos));
float delay = GetNativeCell(3);
ExplosionType type = GetNativeCell(4);
DataPack anim_data = new DataPack();
anim_data.WriteFloat(pos[0]);
anim_data.WriteFloat(pos[1]);
anim_data.WriteFloat(pos[2]);
anim_data.Reset();
DataPack frame_data;
if (type == ExplosionMassive) {
frame_data = MakeFrameData(self, INVALID_HANDLE, Anim_ExplodeMassive, anim_data);
} else {
frame_data = MakeFrameData(self, INVALID_HANDLE, Anim_ExplodeNormal, anim_data);
}
self.WriteFloat(delay);
self.WriteCell(frame_data);
return 0;
}
public int native_AddLightning(Handle plugin, int numParams) {
float origin[3], dest[3];
DataPack self = GFLDM_GetNativeHandle(1);
GetNativeArray(2, origin, sizeof(origin));
GetNativeArray(3, dest, sizeof(dest));
float delay = GetNativeCell(4);
DataPack anim_data = new DataPack();
anim_data.WriteFloat(origin[0]);
anim_data.WriteFloat(origin[1]);
anim_data.WriteFloat(origin[2]);
anim_data.WriteFloat(dest[0]);
anim_data.WriteFloat(dest[1]);
anim_data.WriteFloat(dest[2]);
anim_data.Reset();
DataPack frame_data = MakeFrameData(self, INVALID_HANDLE, Anim_Lightning, anim_data);
self.WriteFloat(delay);
self.WriteCell(frame_data);
return 0;
}
public int native_AddAmbientSound(Handle plugin, int numParams) {
float origin[3];
char sound_file[PLATFORM_MAX_PATH];
DataPack self = GFLDM_GetNativeHandle(1);
GetNativeArray(2, origin, sizeof(origin));
GetNativeString(3, sound_file, sizeof(sound_file));
float delay = GetNativeCell(4);
int level = GetNativeCell(5);
float volume = GetNativeCell(6);
DataPack anim_data = new DataPack();
anim_data.WriteFloat(origin[0]);
anim_data.WriteFloat(origin[1]);
anim_data.WriteFloat(origin[2]);
anim_data.WriteString(sound_file);
anim_data.WriteCell(level);
anim_data.WriteFloat(volume);
anim_data.Reset();
DataPack frame_data = MakeFrameData(self, INVALID_HANDLE, Anim_EmitAmbient, anim_data);
self.WriteFloat(delay);
self.WriteCell(frame_data);
return 0;
}
public int native_AddSound(Handle plugin, int numParams) {
char sound_file[PLATFORM_MAX_PATH];
DataPack self = GFLDM_GetNativeHandle(1);
GetNativeString(2, sound_file, sizeof(sound_file));
float delay = GetNativeCell(3);
int level = GetNativeCell(4);
float volume = GetNativeCell(5);
DataPack anim_data = new DataPack();
anim_data.WriteString(sound_file);
anim_data.WriteCell(level);
anim_data.WriteFloat(volume);
anim_data.Reset();
DataPack frame_data = MakeFrameData(self, INVALID_HANDLE, Anim_EmitSound, anim_data);
self.WriteFloat(delay);
self.WriteCell(frame_data);
return 0;
}
public int native_AddFire(Handle plugin, int numParams) {
DataPack self = GFLDM_GetNativeHandle(1);
if (GetAnimTarget(self) != AnimTarget_All) {
ThrowNativeError(SP_ERROR_NATIVE, "'AddFire' may only be used on animations created with 'GFLDM_StartAnimAll'");
}
float origin[3];
GetNativeArray(2, origin, sizeof(origin));
float lifetime = GetNativeCell(3);
float delay = GetNativeCell(4);
float firesize = GetNativeCell(5);
DataPack anim_data = new DataPack();
anim_data.WriteFloat(origin[0]);
anim_data.WriteFloat(origin[1]);
anim_data.WriteFloat(origin[2]);
anim_data.WriteFloat(lifetime);
anim_data.WriteFloat(firesize);
anim_data.Reset();
DataPack frame_data = MakeFrameData(self, INVALID_HANDLE, Anim_Fire, anim_data);
self.WriteFloat(delay);
self.WriteCell(frame_data);
return 0;
}
public int native_AddTesla(Handle plugin, int numParams) {
DataPack self = GFLDM_GetNativeHandle(1);
if (GetAnimTarget(self) != AnimTarget_All) {
ThrowNativeError(SP_ERROR_NATIVE, "'AddTesla' may only be used on animations created with 'GFLDM_StartAnimAll'");
}
float origin[3];
GetNativeArray(2, origin, sizeof(origin));
float lifetime = GetNativeCell(3);
float delay = GetNativeCell(4);
float radius = GetNativeCell(5);
float interval_min = GetNativeCell(6);
float interval_max = GetNativeCell(7);
int beamcount_min = GetNativeCell(8);
int beamcount_max = GetNativeCell(9);
float thick_min = GetNativeCell(10);
float thick_max = GetNativeCell(11);
float lifetime_min = GetNativeCell(12);
float lifetime_max = GetNativeCell(13);
DataPack anim_data = new DataPack();
anim_data.WriteFloat(origin[0]);
anim_data.WriteFloat(origin[1]);
anim_data.WriteFloat(origin[2]);
anim_data.WriteFloat(lifetime);
anim_data.WriteFloat(radius);
anim_data.WriteFloat(interval_min);
anim_data.WriteFloat(interval_max);
anim_data.WriteCell(beamcount_min);
anim_data.WriteCell(beamcount_max);
anim_data.WriteFloat(thick_min);
anim_data.WriteFloat(thick_max);
anim_data.WriteFloat(lifetime_min);
anim_data.WriteFloat(lifetime_max);
anim_data.Reset();
DataPack frame_data = MakeFrameData(self, INVALID_HANDLE, Anim_Tesla, anim_data);
self.WriteFloat(delay);
self.WriteCell(frame_data);
return 0;
}
AnimationTarget GetAnimTarget(DataPack anim) {
DataPackPos pos = anim.Position;
anim.Reset();
AnimationTarget target = anim.ReadCell();
anim.Position = pos;
return target;
}
int GetAnimClient(DataPack anim) {
DataPackPos pos = anim.Position;
anim.Reset();
anim.ReadCell();
int client = anim.ReadCell();
anim.Position = pos;
return client;
}
DataPack MakeFrameData(DataPack anim, Handle plugin, Function callback, DataPack anim_data) {
DataPack frame_data = new DataPack();
frame_data.WriteCell(plugin);
frame_data.WriteFunction(callback);
frame_data.WriteCell(anim);
frame_data.WriteCell(anim_data);
frame_data.Reset();
return frame_data;
}
public int native_Play(Handle plugin, int numParams) {
DataPack self = GFLDM_GetNativeHandle(1);
self.Reset();
self.ReadCell();
self.ReadCell();
float max_delay = 0.0;
DataPack cleanup_data = new DataPack();
do {
float delay = self.ReadFloat();
if (delay > max_delay) {
max_delay = delay;
}
DataPack frame_data = self.ReadCell();
cleanup_data.WriteCell(frame_data);
CreateTimer(delay, Timer_PlayFrame, frame_data, TIMER_FLAG_NO_MAPCHANGE);
} while (self.IsReadable(0));
cleanup_data.WriteCell(self);
cleanup_data.Reset();
CreateTimer(max_delay + 1.0, Timer_Cleanup, cleanup_data);
}
public int native_TE_Send(Handle plugin, int numParams) {
DataPack self = GFLDM_GetNativeHandle(1);
AnimationTarget target = GetAnimTarget(self);
if (target == AnimTarget_All) {
TE_SendToAll();
} else {
int client = GetAnimClient(self);
if (GFLDM_IsValidClient(client, false)) {
TE_SendToClient(client);
}
}
}
public int native_EmitAmbientSound(Handle plugin, int numParams) {
DataPack self = GFLDM_GetNativeHandle(1);
float origin[3];
GetNativeArray(2, origin, sizeof(origin));
char path[PLATFORM_MAX_PATH];
GetNativeString(3, path, sizeof(path));
int level = GetNativeCell(4);
float volume = GetNativeCell(5);
AnimationTarget target = GetAnimTarget(self);
if (target == AnimTarget_All) {
EmitSoundToAll(path, SOUND_FROM_WORLD, SNDCHAN_AMBIENT, level, _, volume, _, _, origin);
} else {
int client = GetAnimClient(self);
if (GFLDM_IsValidClient(client, false)) {
EmitSoundToClient(client, path, SOUND_FROM_WORLD, SNDCHAN_AMBIENT, level, _, volume, _, _, origin);
}
}
}
public int native_EmitSound(Handle plugin, int numParams) {
DataPack self = GFLDM_GetNativeHandle(1);
char path[PLATFORM_MAX_PATH];
GetNativeString(2, path, sizeof(path));
int level = GetNativeCell(3);
float volume = GetNativeCell(4);
AnimationTarget target = GetAnimTarget(self);
if (target == AnimTarget_All) {
EmitSoundToAll(path, SOUND_FROM_PLAYER, SNDCHAN_AUTO, level, _, volume);
} else {
int client = GetAnimClient(self);
if (GFLDM_IsValidClient(client, false)) {
EmitSoundToClient(client, path, SOUND_FROM_PLAYER, SNDCHAN_AUTO, level, _, volume);
}
}
}
Action Timer_PlayFrame(Handle timer, any data) {
DataPack frame_data = data;
Handle plugin = frame_data.ReadCell();
Function callback = frame_data.ReadFunction();
GFLDMAnimation anim = frame_data.ReadCell();
DataPack anim_data = frame_data.ReadCell();
Call_StartFunction(plugin, callback);
Call_PushCell(anim);
Call_PushCell(anim_data);
Call_Finish();
delete anim_data;
}
Action Timer_Cleanup(Handle time, any data) {
DataPack cleanup_data = data;
do {
DataPack frame_data = cleanup_data.ReadCell();
delete frame_data;
} while(cleanup_data.IsReadable(0));
delete cleanup_data;
}
void Anim_ExplodeMassive(GFLDMAnimation anim, DataPack anim_data) {
float origin[3];
origin[0] = anim_data.ReadFloat();
origin[1] = anim_data.ReadFloat();
origin[2] = anim_data.ReadFloat();
float normal[3] = {0.0, 0.0, 1.0};
TE_SetupEnergySplash(origin, normal, false);
TE_SetupExplosion(origin, explosion_sprite, 5.0, 5, 0, 150, 140, normal);
anim.TE_Send();
TE_SetupSmoke(origin, smoke_sprite, 10.0, 3);
anim.TE_Send();
anim.EmitAmbientSound(origin, EXPLODE_SOUND_LOUD, SNDLEVEL_GUNFIRE);
}
void Anim_ExplodeNormal(GFLDMAnimation anim, DataPack anim_data) {
float origin[3];
origin[0] = anim_data.ReadFloat();
origin[1] = anim_data.ReadFloat();
origin[2] = anim_data.ReadFloat();
float normal[3] = {0.0, 0.0, 1.0};
TE_SetupExplosion(origin, explosion_sprite, 5.0, 1, 0, 50, 40, normal);
anim.TE_Send();
TE_SetupSmoke(origin, smoke_sprite, 10.0, 3);
anim.TE_Send();
anim.EmitAmbientSound(origin, EXPLODE_SOUND);
}
void Anim_Lightning(GFLDMAnimation anim, DataPack anim_data) {
float origin[3], dest[3];
origin[0] = anim_data.ReadFloat();
origin[1] = anim_data.ReadFloat();
origin[2] = anim_data.ReadFloat();
dest[0] = anim_data.ReadFloat();
dest[1] = anim_data.ReadFloat();
dest[2] = anim_data.ReadFloat();
float normal[3];
SubtractVectors(dest, origin, normal);
NormalizeVector(normal, normal);
TE_Start("GaussExplosion");
TE_WriteVector("m_vecOrigin[0]", dest);
TE_WriteNum("m_nType", 1);
TE_WriteVector("m_vecDirection", normal);
anim.TE_Send();
int color[4] = {255, 255, 255, 255};
TE_SetupBeamPoints(origin, dest, lightning_sprite, 0, 0, 0, 0.2, 20.0, 10.0, 0, 1.0, color, 3);
anim.TE_Send();
}
void Anim_EmitAmbient(GFLDMAnimation anim, DataPack anim_data) {
float origin[3];
origin[0] = anim_data.ReadFloat();
origin[1] = anim_data.ReadFloat();
origin[2] = anim_data.ReadFloat();
char path[PLATFORM_MAX_PATH];
anim_data.ReadString(path, sizeof(path));
int level = anim_data.ReadCell();
float volume = anim_data.ReadFloat();
anim.EmitAmbientSound(origin, path, level, volume);
}
void Anim_EmitSound(GFLDMAnimation anim, DataPack anim_data) {
char path[PLATFORM_MAX_PATH];
anim_data.ReadString(path, sizeof(path));
int level = anim_data.ReadCell();
float volume = anim_data.ReadFloat();
anim.EmitSound(path, level, volume);
}
void Anim_Fire(GFLDMAnimation anim, DataPack anim_data) {
float origin[3];
origin[0] = anim_data.ReadFloat();
origin[1] = anim_data.ReadFloat();
origin[2] = anim_data.ReadFloat();
float lifetime = anim_data.ReadFloat();
float firesize = anim_data.ReadFloat();
int fire = CreateEntityByName("env_fire");
if(IsValidEdict(fire)) {
char s_firesize[12];
FloatToString(firesize, s_firesize, sizeof(s_firesize));
DispatchKeyValue(fire, "damagescale", "0.0");
DispatchKeyValue(fire, "Name", NULL_STRING);
DispatchKeyValue(fire, "health", "1000");
DispatchKeyValue(fire, "fireattack", "0");
DispatchKeyValue(fire, "firetype", "0");
DispatchKeyValue(fire, "flags", "136");
DispatchSpawn(fire);
DispatchKeyValue(fire, "firesize", s_firesize);
TeleportEntity(fire, origin, NULL_VECTOR, NULL_VECTOR);
ActivateEntity(fire);
AcceptEntityInput(fire, "StartFire");
CreateTimer(lifetime, Timer_KillEnt, fire, TIMER_FLAG_NO_MAPCHANGE);
} else {
LogError("Failed to create entity env_fire!");
}
}
void Anim_Tesla(GFLDMAnimation anim, DataPack anim_data) {
float origin[3];
origin[0] = anim_data.ReadFloat();
origin[1] = anim_data.ReadFloat();
origin[2] = anim_data.ReadFloat();
float lifetime = anim_data.ReadFloat();
float radius = anim_data.ReadFloat();
float interval_min = anim_data.ReadFloat();
float interval_max = anim_data.ReadFloat();
int beamcount_min = anim_data.ReadCell();
int beamcount_max = anim_data.ReadCell();
float thick_min = anim_data.ReadFloat();
float thick_max = anim_data.ReadFloat();
float lifetime_min = anim_data.ReadFloat();
float lifetime_max = anim_data.ReadFloat();
int tesla = CreateEntityByName("point_tesla");
if (IsValidEdict(tesla)) {
char s_beam_min[12], s_beam_max[12];
IntToString(beamcount_min, s_beam_min, sizeof(s_beam_min));
IntToString(beamcount_max, s_beam_max, sizeof(s_beam_max));
DispatchKeyValueFloat(tesla, "m_flRadius", radius);
DispatchKeyValue(tesla, "m_SoundName", "DoSpark");
DispatchKeyValue(tesla, "beamcount_min", s_beam_min);
DispatchKeyValue(tesla, "beamcount_max", s_beam_max);
DispatchKeyValue(tesla, "texture", TESLA_SPRITE);
DispatchKeyValue(tesla, "m_Color", "255 255 255");
DispatchKeyValueFloat(tesla, "thick_min", thick_min);
DispatchKeyValueFloat(tesla, "thick_max", thick_max);
DispatchKeyValueFloat(tesla, "lifetime_min", lifetime_min);
DispatchKeyValueFloat(tesla, "lifetime_max", lifetime_max);
DispatchKeyValueFloat(tesla, "interval_min", interval_min);
DispatchKeyValueFloat(tesla, "interval_max", interval_max);
DispatchSpawn(tesla);
TeleportEntity(tesla, origin, NULL_VECTOR, NULL_VECTOR);
AcceptEntityInput(tesla, "TurnOn");
AcceptEntityInput(tesla, "DoSpark");
DataPack spark_data = new DataPack();
spark_data.WriteFloat(interval_min);
spark_data.WriteFloat(interval_max);
spark_data.WriteCell(tesla);
CreateTimer(GetRandomFloat(interval_min, interval_max), Timer_Spark, spark_data);
CreateTimer(lifetime, Timer_KillEnt, tesla, TIMER_FLAG_NO_MAPCHANGE);
} else {
LogError("Failed to create point_tesla");
}
}
Action Timer_Spark(Handle timer, any data) {
DataPack spark_data = data;
spark_data.Reset();
float lifetime_min = spark_data.ReadFloat();
float lifetime_max = spark_data.ReadFloat();
int tesla = spark_data.ReadCell();
if (IsValidEdict(tesla)) {
if (AcceptEntityInput(tesla, "DoSpark")){
CreateTimer(GetRandomFloat(lifetime_min, lifetime_max), Timer_Spark, spark_data);
} else {
delete spark_data;
}
} else {
delete spark_data;
}
return Plugin_Stop;
}
Action Timer_KillEnt(Handle timer, any data) {
int ent = data;
if(IsValidEdict(ent)) {
AcceptEntityInput(ent, "Kill");
RemoveEdict(ent);
}
return Plugin_Stop;
}