-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
sunlightspear.sp
251 lines (191 loc) · 6.85 KB
/
sunlightspear.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
/**
* Sunlight Spear perk.
* Copyright (C) 2024 Filip Tomaszewski
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define SOUND_CONJURE "misc/halloween/spell_lightning_ball_cast.wav"
#define TICK_INTERVAL 0.1
#define ElectrocuteEffect Int[0]
#define Ticks Int[1]
#define Slowdown Int[2]
#define AllySpeed Int[3]
#define NextAttack Float[0]
#define Rate Float[1]
#define Speed Float[2]
#define Damage Float[3]
static char g_sSoundZap[][] = {
"ambient/energy/zap1.wav",
"ambient/energy/zap2.wav",
"ambient/energy/zap3.wav",
};
DEFINE_CALL_APPLY(SunlightSpear)
public void SunlightSpear_Init(const Perk perk)
{
PrecacheSound(SOUND_CONJURE);
PrecacheSound(g_sSoundZap[0]);
PrecacheSound(g_sSoundZap[1]);
PrecacheSound(g_sSoundZap[2]);
Events.OnVoice(perk, SunlightSpear_OnVoice);
}
void SunlightSpear_ApplyPerk(const int client, const Perk perk)
{
Cache[client].Ticks = perk.GetPrefCell("ticks", 5);
Cache[client].Slowdown = ClampInt(RoundFloat(perk.GetPrefFloat("slowdown", 0.2) * 100), 0, 100);
Cache[client].AllySpeed = RoundFloat(perk.GetPrefFloat("ally_speed", 2.0) * 100);
Cache[client].NextAttack = GetEngineTime();
Cache[client].Rate = perk.GetPrefFloat("rate", 1.0);
Cache[client].Speed = perk.GetPrefFloat("speed", 1600.0);
Cache[client].Damage = perk.GetPrefFloat("damage", 10.0);
switch (TF2_GetClientTeam(client))
{
case TFTeam_Red:
Cache[client].ElectrocuteEffect = view_as<int>(TEParticles.ElectrocutedRed);
case TFTeam_Blue:
Cache[client].ElectrocuteEffect = view_as<int>(TEParticles.ElectrocutedBlue);
}
Notify.Attack(client);
}
void SunlightSpear_OnVoice(const int client)
{
float fTime = GetEngineTime();
if (fTime < Cache[client].NextAttack)
return;
Cache[client].NextAttack = fTime + Cache[client].Rate;
EmitSoundToAll(SOUND_CONJURE, client, _, _, _, 0.5, 160);
float fAng[3], fPos[3], fVel[3];
GetClientEyeAngles(client, fAng);
GetClientEyePosition(client, fPos);
fPos[2] -= 12.0;
GetAngleVectors(fAng, fVel, NULL_VECTOR, NULL_VECTOR);
ScaleVector(fVel, Cache[client].Speed);
int iTesla = CreateTesla(fPos);
if (iTesla <= MaxClients)
return;
KILL_ENT_IN(iTesla,10.0);
// prop_physics_override needs some sort of active func_* entity in its parent hierarchy in
// order to move with a "fly" movetype. An infinitely rotating func_door_rotating works well.
int iRot = CreateEntityByName("func_door_rotating");
if (iRot <= MaxClients)
return;
KILL_ENT_IN(iRot,10.0);
DispatchKeyValueVector(iRot, "origin", fPos);
DispatchKeyValue(iRot, "distance", "99999");
DispatchKeyValue(iRot, "spawnflags", "4104"); // passable | silent
DispatchSpawn(iRot);
AcceptEntityInput(iRot, "Open");
int iCarrier = CreateEntityByName("prop_physics_override");
if (iCarrier <= MaxClients)
return;
KILL_ENT_IN(iCarrier,10.0);
SetEntPropEnt(iCarrier, Prop_Send, "m_hOwnerEntity", client);
DispatchKeyValue(iCarrier, "model", MODEL_PROJECTILE);
SetEntityRenderMode(iCarrier, RENDER_TRANSCOLOR);
SetEntityRenderColor(iCarrier, .a=0);
DispatchSpawn(iCarrier);
ActivateEntity(iCarrier);
SetEntityMoveType(iCarrier, MOVETYPE_FLY);
TeleportEntity(iCarrier, fPos, NULL_VECTOR, fVel);
Parent(iTesla, iRot);
Parent(iRot, iCarrier);
static int iColor[4] = {255, 255, 128, 255};
TE_SetupBeamFollow(iTesla, Materials.Laser, Materials.Halo, 0.4, 20.0, 10.0, 1, iColor);
TE_SendToAll();
SDKHook(iCarrier, SDKHook_StartTouch, SunlightSpear_OnTouch);
}
public Action SunlightSpear_OnTouch(const int iProjectile, const int iVictim)
{
int iAttacker = GetEntPropEnt(iProjectile, Prop_Send, "m_hOwnerEntity");
if (!iAttacker)
return Plugin_Handled; // left the game
int iVictimUserId = -1;
if (1 <= iVictim <= MaxClients)
{
iVictimUserId = GetClientUserId(iVictim);
int iParticle = Cache[iAttacker].ElectrocuteEffect;
SendTEParticleAttached(view_as<TEParticleId>(iParticle), iVictim);
if (TF2_GetClientTeam(iAttacker) == TF2_GetClientTeam(iVictim))
{
TF2_AddCondition(iVictim, TFCond_SpeedBuffAlly, float(Cache[iAttacker].AllySpeed) / 100.0);
return Plugin_Handled;
}
SunlightSpear_DamageTick(iVictim, iAttacker, true);
float fSlowdown = 1.0 - float(Cache[iAttacker].Slowdown) / 100.0;
TF2_StunPlayer(iVictim, Cache[iAttacker].Ticks * TICK_INTERVAL, fSlowdown, TF_STUNFLAG_SLOWDOWN, iAttacker);
}
float fOrigin[3];
GetEntPropVector(iProjectile, Prop_Send, "m_vecOrigin", fOrigin);
SunlightSpear_ParticlesTick(fOrigin);
DataPack hData = new DataPack();
hData.WriteCell(Cache[iAttacker].Ticks);
hData.WriteFloat(fOrigin[0]);
hData.WriteFloat(fOrigin[1]);
hData.WriteFloat(fOrigin[2]);
hData.WriteCell(iVictimUserId);
hData.WriteCell(GetClientUserId(iAttacker));
CreateTimer(TICK_INTERVAL, Timer_SunlightSpear_Tick, hData, TIMER_REPEAT | TIMER_DATA_HNDL_CLOSE);
AcceptEntityInput(iProjectile, "KillHierarchy");
return Plugin_Handled;
}
public Action Timer_SunlightSpear_Tick(Handle hTimer, DataPack hData)
{
hData.Reset();
int iTicks = hData.ReadCell() - 1;
if (iTicks <= 0)
return Plugin_Stop;
float fOrigin[3];
fOrigin[0] = hData.ReadFloat();
fOrigin[1] = hData.ReadFloat();
fOrigin[2] = hData.ReadFloat();
SunlightSpear_ParticlesTick(fOrigin);
int iVictim = GetClientOfUserId(hData.ReadCell());
int iAttacker = GetClientOfUserId(hData.ReadCell());
if (!iVictim || !iAttacker)
return Plugin_Stop;
SunlightSpear_DamageTick(iVictim, iAttacker);
hData.Reset();
hData.WriteCell(iTicks);
return Plugin_Continue;
}
void SunlightSpear_DamageTick(const int iVictim, const int iAttacker, const bool bInitial=false)
{
if (!CanPlayerBeHurt(iVictim, iAttacker))
return;
float fDamage = Cache[iAttacker].Damage;
fDamage += fDamage * view_as<int>(bInitial);
TakeDamage(iVictim, iAttacker, iAttacker, fDamage, DMG_SHOCK);
EmitSoundToAll(g_sSoundZap[GetRandomInt(0, 2)], iVictim, _, _, _, _, GetRandomInt(90, 110));
}
void SunlightSpear_ParticlesTick(const float fOrigin[3])
{
float fPos[3], fDir[2];
for (int i = 0; i < 3; ++i)
{
float fRadius = GetRandomFloat(10.0, 30.0);
fDir[0] = GetRandomFloat(0.0, 2.0 * 3.1415);
fDir[1] = GetRandomFloat(0.0, 2.0 * 3.1415);
GetPointOnSphere(fOrigin, fDir, fRadius, fPos);
SendTEParticleWithPriority(TEParticles.ElectricBurst, fPos);
}
}
#undef SOUND_CONJURE
#undef TICK_INTERVAL
#undef ElectrocuteEffect
#undef Ticks
#undef Slowdown
#undef AllySpeed
#undef NextAttack
#undef Rate
#undef Speed
#undef Damage