-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
cursedprojectiles.sp
115 lines (89 loc) · 3.68 KB
/
cursedprojectiles.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
/**
* Cursed Projectiles perk.
* Copyright (C) 2023 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 CURSED_PROJECTILES_TRANSFORM "halloween_ghost_flash"
#define SOUND_COURSE_PROJECTILE "misc/halloween/merasmus_disappear.wav"
#define Delay Float[0]
DEFINE_CALL_APPLY(CursedProjectiles)
public void CursedProjectiles_Init(const Perk perk)
{
PrecacheSound(SOUND_COURSE_PROJECTILE);
Events.OnEntitySpawned(perk, CursedProjectiles_OnProjectileSpawn, Homing_AptClass, Retriever_OwnerEntity);
}
void CursedProjectiles_ApplyPerk(const int client, const Perk perk)
{
Cache[client].Delay = perk.GetPrefFloat("delay", 1.0);
}
public void CursedProjectiles_OnProjectileSpawn(const int client, const int iProjectile)
{
CreateTimer(Cache[client].Delay, Timer_CursedProjectiles_Turn, EntIndexToEntRef(iProjectile));
}
public Action Timer_CursedProjectiles_Turn(Handle hTimer, int iRef)
{
int iProjectile = EntRefToEntIndex(iRef);
if (iProjectile <= MaxClients || !IsValidEntity(iProjectile))
return Plugin_Stop;
int client = GetEntPropEnt(iProjectile, Prop_Send, "m_hOwnerEntity");
if (!IsValidClient(client) || !IsPlayerAlive(client))
return Plugin_Stop;
CursedProjectiles_Turn(iProjectile, client);
return Plugin_Stop;
}
void CursedProjectiles_Turn(const int iOriginalProjectile, const int client)
{
float fPos[3], fVel[3];
GetEntPropVector(iOriginalProjectile, Prop_Send, "m_vecOrigin", fPos);
GetEntPropVector(iOriginalProjectile, Prop_Send, "m_vInitialVelocity", fVel);
int iLauncher = GetEntPropEnt(iOriginalProjectile, Prop_Send, "m_hOriginalLauncher");
AcceptEntityInput(iOriginalProjectile, "Kill");
int iProjectile = CursedProjectiles_Spawn(client, iLauncher, fPos, fVel);
if (iProjectile <= MaxClients)
return;
KILL_ENT_IN(iProjectile,3.0);
Homing_Push(iProjectile, HOMING_SELF_ORIG);
CreateEffect(fPos, CURSED_PROJECTILES_TRANSFORM);
EmitSoundToAll(SOUND_COURSE_PROJECTILE, iProjectile);
SDKHook(iProjectile, SDKHook_StartTouchPost, CursedProjectiles_ProjectileTouch);
}
int CursedProjectiles_Spawn(int client, int iLauncher, float fPos[3], float fVel[3])
{
int iProjectile = CreateEntityByName("tf_projectile_spellfireball");
if (iProjectile <= MaxClients)
return 0;
SetEntPropEnt(iProjectile, Prop_Send, "m_hOriginalLauncher", iLauncher);
SetEntPropVector(iProjectile, Prop_Send, "m_vInitialVelocity", fVel);
TeleportEntity(iProjectile, fPos, NULL_VECTOR, NULL_VECTOR);
int iTeam = GetOppositeTeamOf(client);
SetEntPropEnt(iProjectile, Prop_Send, "m_hOwnerEntity", 0);
SetEntProp(iProjectile, Prop_Send, "m_iTeamNum", iTeam, 1);
SetEntProp(iProjectile, Prop_Send, "m_nSkin", iTeam - 2);
DispatchSpawn(iProjectile);
return iProjectile;
}
public void CursedProjectiles_ProjectileTouch(int iProjectile, int client)
{
if (GetLauncher(iProjectile) != client)
return;
if (!IsValidClient(client))
return;
float fPos[3];
GetClientAbsOrigin(client, fPos);
CreateExplosion(fPos, 100.0, 1.0);
}
#undef CURSED_PROJECTILES_TRANSFORM
#undef SOUND_COURSE_PROJECTILE
#undef Delay