-
Notifications
You must be signed in to change notification settings - Fork 0
/
TF2_Ignite_Light.sp
274 lines (235 loc) · 8.42 KB
/
TF2_Ignite_Light.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
#pragma semicolon 1
//Includes:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <tf2_stocks>
#define PLUGIN_VERSION "1.4"
#define MAX_STRENGTH 13
new Handle:g_hEnabled;
new Handle:g_hBrightness;
new g_iFlamethrower[MAXPLAYERS+1] = -1;
new g_iFlamethrowerTrash[MAXPLAYERS+1] = -1;
new g_bHooked[MAXPLAYERS+1] = false;
public Plugin:myinfo = {
name = "[TF2] Ignite Light",
author = "Peanut",
description = "Adds dynamic lighting to the Pyro's flamethrower, Original by: Mecha the Slag",
version = PLUGIN_VERSION,
url = "https://discord.gg/7sRn8Bt"
};
bool g_bHasDynamicLight[MAXPLAYERS + 1] = { false, ... };
public APLRes AskPluginLoad2()
{
EngineVersion g_engineversion = GetEngineVersion();
if (g_engineversion != Engine_TF2)
{
SetFailState("This isn't TF2, try TF2 next time");
}
return APLRes_Success;
}
public OnPluginStart() {
RegConsoleCmd("sm_firelighting", Command_AllowLight);
CreateConVar("ignitelight_version", PLUGIN_VERSION, "[TF2] Ignite Light version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
g_hEnabled = CreateConVar("ignitelight_enable", "1", "Enable/disable the [TF2] Ignite Light plugin.", FCVAR_PLUGIN|FCVAR_NOTIFY);
g_hBrightness = CreateConVar("ignitelight_brightness", "5", "This CVar is unsued in this version", FCVAR_PLUGIN|FCVAR_NOTIFY);
HookEvent("player_spawn", PlayerSpawn);
HookEvent("player_death", PlayerDeath);
for(int i = 1; i <= MaxClients; i++) {
if(IsClientInGame(i)) {
OnClientPutInServer(i);
}
}
}
public Action Command_AllowLight(int client, int args)
{
g_bHasDynamicLight[client] = !g_bHasDynamicLight[client];
if(g_bHasDynamicLight[client]) {
ReplyToCommand(client, "[SM] Dynamic Light Enabled");
} else {
ReplyToCommand(client, "[SM] Dynamic Light Disabled");
}
return Plugin_Handled;
}
stock bool:IsValidClient(iClient) {
if (iClient <= 0) return false;
if (iClient > MaxClients) return false;
if (!IsClientConnected(iClient)) return false;
return IsClientInGame(iClient);
}
public OnClientPutInServer(iClient) {
ResetClient(iClient);
g_bHasDynamicLight[iClient] = false;
SDKHook(iClient, SDKHook_PreThink, OnPreThink);
}
public OnClientDisconnect(iClient) {
ResetClient(iClient);
HookClient(iClient, false);
}
public OnPreThink(iClient) {
if (!GetConVarBool(g_hEnabled)) return;
if (!g_bHasDynamicLight[iClient]) return;
new iEntity;
decl String:strWeapon[52];
GetClientWeapon(iClient, strWeapon, sizeof(strWeapon));
new Float:fStrength = GetFlamethrowerStrength(iClient);
if (fStrength > 0.0) {
// If no light is present, let's spawn it
if (g_iFlamethrower[iClient] == -1) {
iEntity = CreateLightEntity(iClient);
if (IsLightEntity(iEntity)) {
KillFlamethrowerTrash(iClient);
g_iFlamethrower[iClient] = iEntity;
}
}
// If the light is already there, let's increase its strength
iEntity = g_iFlamethrower[iClient];
if (IsLightEntity(iEntity)) {
AdjustLight(iClient, iEntity);
}
}
else {
// if there is a light, let's trash it
if (g_iFlamethrower[iClient] != -1) {
iEntity = g_iFlamethrower[iClient];
if (IsLightEntity(iEntity)) {
// If there's already trash, kill the trash
KillFlamethrowerTrash(iClient);
g_iFlamethrowerTrash[iClient] = iEntity;
}
g_iFlamethrower[iClient] = -1;
}
// decrease the trash's strength
iEntity = g_iFlamethrowerTrash[iClient];
if (IsLightEntity(iEntity)) {
if (fStrength <= 0.0) {
KillFlamethrowerTrash(iClient);
} else {
AdjustLight(iClient, iEntity);
}
}
}
}
ResetClient(iClient) {
new iLight;
iLight = g_iFlamethrower[iClient];
if (IsLightEntity(iLight)) RemoveEdict(iLight);
KillFlamethrowerTrash(iClient);
g_iFlamethrower[iClient] = -1;
}
CreateLightEntity(iClient) {
if (!IsValidClient(iClient)) return -1;
if (!IsPlayerAlive(iClient)) return -1;
new iEntity = CreateEntityByName("light_dynamic");
if (IsValidEntity(iEntity)) {
DispatchKeyValue(iEntity, "inner_cone", "0");
DispatchKeyValue(iEntity, "cone", "80");
DispatchKeyValue(iEntity, "brightness", "0");
DispatchKeyValueFloat(iEntity, "spotlight_radius", 240.0);
DispatchKeyValueFloat(iEntity, "distance", 250.0);
DispatchKeyValue(iEntity, "_light", "255 100 10 255");
DispatchKeyValue(iEntity, "pitch", "-90");
DispatchKeyValue(iEntity, "style", "5");
DispatchSpawn(iEntity);
decl Float:fPos[3];
decl Float:fAngle[3];
decl Float:fAngle2[3];
decl Float:fForward[3];
decl Float:fOrigin[3];
GetClientEyePosition(iClient, fPos);
GetClientEyeAngles(iClient, fAngle);
GetClientEyeAngles(iClient, fAngle2);
fAngle2[0] = 0.0;
fAngle2[2] = 0.0;
GetAngleVectors(fAngle2, fForward, NULL_VECTOR, NULL_VECTOR);
ScaleVector(fForward, 100.0);
fForward[2] = 0.0;
AddVectors(fPos, fForward, fOrigin);
fAngle[0] += 90.0;
fOrigin[2] -= 100.0;
TeleportEntity(iEntity, fOrigin, fAngle, NULL_VECTOR);
decl String:strName[32];
Format(strName, sizeof(strName), "target%i", iClient);
DispatchKeyValue(iClient, "targetname", strName);
DispatchKeyValue(iEntity, "parentname", strName);
SetVariantString("!activator");
AcceptEntityInput(iEntity, "SetParent", iClient, iEntity, 0);
SetVariantString("head");
AcceptEntityInput(iEntity, "SetParentAttachmentMaintainOffset", iClient, iEntity, 0);
AcceptEntityInput(iEntity, "TurnOn");
}
return iEntity;
}
public PlayerDeath(Handle:hEvent, String:strName[], bool:bDontBroadcast) {
new iClient = GetClientOfUserId(GetEventInt(hEvent, "userid"));
ResetClient(iClient);
HookClient(iClient, false);
}
public PlayerSpawn(Handle:hEvent, String:strName[], bool:bDontBroadcast) {
new iClient = GetClientOfUserId(GetEventInt(hEvent, "userid"));
ResetClient(iClient);
HookClient(iClient);
}
HookClient(iClient, bHook = true) {
if (bHook && !g_bHooked[iClient]) {
SDKHook(iClient, SDKHook_PreThink, OnPreThink);
}
if (!bHook && g_bHooked[iClient]) {
SDKUnhook(iClient, SDKHook_PreThink, OnPreThink);
}
g_bHooked[iClient] = bHook;
}
stock bool:IsLightEntity(iEntity) {
if (iEntity > 0) {
if (IsValidEdict(iEntity)) {
decl String:strClassname[32];
GetEdictClassname(iEntity, strClassname, sizeof(strClassname));
if (StrEqual(strClassname, "light_dynamic", false)) return true;
}
}
return false;
}
stock bool:IsFlamethrower(iEntity) {
if (iEntity > 0) {
if (IsValidEdict(iEntity)) {
decl String:strClassname[32];
GetEdictClassname(iEntity, strClassname, sizeof(strClassname));
if (StrEqual(strClassname, "tf_weapon_flamethrower", false)) return true;
}
}
return false;
}
KillFlamethrowerTrash(iClient) {
if (g_iFlamethrowerTrash[iClient] != -1) {
new iEntity = g_iFlamethrowerTrash[iClient];
if (IsLightEntity(iEntity)) RemoveEdict(iEntity);
g_iFlamethrowerTrash[iClient] = -1;
}
}
AdjustLight(iClient, iEntity) {
new Float:fValue;
new iValue;
fValue = GetFlamethrowerStrength(iClient) * float(GetConVarInt(g_hBrightness));
iValue = RoundFloat(fValue);
SetVariantInt(iValue);
AcceptEntityInput(iEntity, "Brightness");
}
Float:GetFlamethrowerStrength(iClient) {
if (!IsValidClient(iClient)) return 0.0;
if (!IsPlayerAlive(iClient)) return 0.0;
new iEntity = GetEntPropEnt(iClient, Prop_Send, "m_hActiveWeapon");
if (IsFlamethrower(iEntity)) {
new iStrength = GetEntProp(iEntity, Prop_Send, "m_iActiveFlames");
new iWeaponState = GetEntProp(iEntity, Prop_Send, "m_iWeaponState");
// PrintToChatAll("Weapon state: %d", iWeaponState);
if(iWeaponState == 1) {
return 0.5;
} else if(iWeaponState > 1) {
return 1.0;
}
// new Float:fStrength = (float(iStrength) / float(MAX_STRENGTH));
// if (fStrength > 1.0) fStrength = 1.0;
// return fStrength;
}
return 0.0;
}