forked from Pelipoika/TF2-Sniperlaser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsniperlaser_legacy.sp
122 lines (96 loc) · 3.17 KB
/
sniperlaser_legacy.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
#include <sdkhooks>
#include <tf2_stocks>
#pragma newdecls required
#define LASERBEAM "sprites/laserbeam.vmt"
ConVar g_cvarLaserEnabled;
int g_iEyeProp[MAXPLAYERS + 1];
public Plugin myinfo =
{
name = "[TF2] Sniperlaser",
author = "Pelipoika",
description = "Sniper rifles emit lasers",
version = "1.1",
url = ""
};
public void OnPluginStart()
{
g_cvarLaserEnabled = CreateConVar("tf2_sniperlaser_enabled", "1", "Sniper rifles emit lasers", _, true, 0.0, true, 1.0);
}
public void OnMapStart()
{
PrecacheModel(LASERBEAM);
}
public void OnClientPutInServer(int client)
{
g_iEyeProp[client] = INVALID_ENT_REFERENCE;
}
public void OnEntityCreated(int entity, const char[] classname)
{
if (StrEqual(classname, "env_sniperdot") && g_cvarLaserEnabled.BoolValue)
{
SDKHook(entity, SDKHook_SpawnPost, SpawnPost);
}
}
public Action SpawnPost(int entity)
{
RequestFrame(SpawnPostPost, entity);
}
public void SpawnPostPost(int ent)
{
if (IsValidEntity(ent))
{
int client = GetEntPropEnt(ent, Prop_Send, "m_hOwnerEntity");
if(client > 0 && client <= MaxClients && IsClientInGame(client))
{
if(GameRules_GetProp("m_bPlayingMannVsMachine") && TF2_GetClientTeam(client) != TFTeam_Red)
return;
TFTeam iTeam = TF2_GetClientTeam(client);
switch(iTeam)
{
case TFTeam_Red: ConnectWithBeam(client, ent, 255, 0, 0, 0.75, 1.0);
case TFTeam_Blue: ConnectWithBeam(client, ent, 0, 0, 255, 0.75, 1.0);
default: ConnectWithBeam(client, ent, 255, 255, 255, 1.0, 1.0);
}
}
}
}
public void TF2_OnConditionRemoved(int client, TFCond condition)
{
if(TF2_GetPlayerClass(client) == TFClass_Sniper && condition == TFCond_Zoomed)
{
int iEyeProp = EntRefToEntIndex(g_iEyeProp[client])
if(iEyeProp != INVALID_ENT_REFERENCE)
{
AcceptEntityInput(iEyeProp, "ClearParent");
AcceptEntityInput(iEyeProp, "Kill");
g_iEyeProp[client] = INVALID_ENT_REFERENCE;
}
}
}
stock int ConnectWithBeam(int client, int iEnt2, int iRed = 255, int iGreen = 255, int iBlue = 255, float fStartWidth = 1.0, float fEndWidth = 1.0)
{
int iEyeAttachment = CreateEntityByName("info_target");
DispatchSpawn(iEyeAttachment);
SetVariantString("!activator");
AcceptEntityInput(iEyeAttachment, "SetParent", client);
SetVariantString("righteye");
AcceptEntityInput(iEyeAttachment, "SetParentAttachment", client);
g_iEyeProp[client] = EntIndexToEntRef(iEyeAttachment);
int iBeam = CreateEntityByName("env_beam");
SetEntityModel(iBeam, LASERBEAM);
char sColor[16];
Format(sColor, sizeof(sColor), "%d %d %d 1", iRed, iGreen, iBlue);
DispatchKeyValue(iBeam, "rendercolor", sColor);
DispatchKeyValue(iBeam, "life", "0");
DispatchSpawn(iBeam);
SetEntPropEnt(iBeam, Prop_Send, "m_hAttachEntity", EntIndexToEntRef(iEyeAttachment));
SetEntPropEnt(iBeam, Prop_Send, "m_hAttachEntity", EntIndexToEntRef(iEnt2), 1);
SetEntProp(iBeam, Prop_Send, "m_nNumBeamEnts", 2);
SetEntProp(iBeam, Prop_Send, "m_nBeamType", 2);
SetEntPropFloat(iBeam, Prop_Data, "m_fWidth", fStartWidth);
SetEntPropFloat(iBeam, Prop_Data, "m_fEndWidth", fEndWidth);
AcceptEntityInput(iBeam, "TurnOn");
SetVariantString("!activator");
AcceptEntityInput(iBeam, "SetParent", iEnt2);
return iBeam;
}