This repository was archived by the owner on Jul 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathins_protectcache.sp
More file actions
182 lines (153 loc) · 4.64 KB
/
ins_protectcache.sp
File metadata and controls
182 lines (153 loc) · 4.64 KB
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
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
public Plugin:myinfo = {
name = "[INS] Protect Cache",
description = "Protect cache when there's counter attack",
author = "Neko-",
version = "1.0.2",
};
enum Teams
{
TEAM_NONE = 0,
TEAM_SPECTATORS,
TEAM_SECURITY,
TEAM_INSURGENTS,
};
int g_nObjResource;
int g_nCurrentActiveObj;
int g_nTotalObj;
int g_nInsurgentsLockedObj;
int g_nSecurityLockedObj;
int g_nObjectType;
bool g_bLoaded = false;
public OnPluginStart()
{
g_nObjResource = FindEntityByClassname(-1, "ins_objective_resource");
g_nCurrentActiveObj = FindSendPropInfo("CINSObjectiveResource", "m_nActivePushPointIndex");
g_nTotalObj = FindSendPropInfo("CINSObjectiveResource", "m_iNumControlPoints");
g_nInsurgentsLockedObj = FindSendPropInfo("CINSObjectiveResource", "m_bInsurgentsLocked");
g_nSecurityLockedObj = FindSendPropInfo("CINSObjectiveResource", "m_bSecurityLocked");
g_nObjectType = FindSendPropInfo("CINSObjectiveResource", "m_iObjectType");
//EventHookMode_Pre
HookEvent("round_start", Event_RoundStart);
HookEvent("object_destroyed", Event_ObjectDestroyed);
RegAdminCmd("protectcache", CacheInfo, ADMFLAG_KICK, "List cache info");
if(!g_bLoaded)
{
CreateTimer(5.0, Timer_Check,_ , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}
}
public OnMapStart()
{
g_bLoaded = false;
g_nObjResource = FindEntityByClassname(-1, "ins_objective_resource");
if(!g_bLoaded)
{
CreateTimer(5.0, Timer_Check,_ , TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE);
}
}
public Action:Timer_Check(Handle:Timer)
{
int acp = GetEntData(g_nObjResource, g_nCurrentActiveObj);
if(acp < 0) return Plugin_Continue;
int ncp = GetEntData(g_nObjResource, g_nTotalObj);
if((acp+1) != ncp)
{
int nObjType = GetEntData(g_nObjResource, g_nObjectType + (acp * 4));
if(nObjType == 0)
{
SetEntData(g_nObjResource, g_nInsurgentsLockedObj + acp, 0, 1);
SetEntData(g_nObjResource, g_nSecurityLockedObj + acp, 0, 1);
}
}
return Plugin_Continue;
}
public Action:Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
ResetCache();
}
public Action:Event_ObjectDestroyed(Handle:event, const String:name[], bool:dontBroadcast)
{
int nTeam = GetEventInt(event, "team");
int nEnt = GetEventInt(event, "index");
if(nTeam == view_as<int>(TEAM_INSURGENTS))
{
CreateTimer(1.0, ChangeCacheData, nEnt);
}
}
public Action ChangeCacheData(Handle timer, any:ent)
{
SetEntProp(ent, Prop_Data, "m_lifeState", 0);
SetEntProp(ent, Prop_Data, "m_iTeamNum", TEAM_SECURITY);
SetEntProp(ent, Prop_Data, "m_takedamage", 2, 1);
//SetEntProp(ent, Prop_Data, "m_iDamageCount", 0);
//SetEntProp(ent, Prop_Data, "m_SolidToPlayers", 0);
decl String:sModel[128];
GetEntPropString(ent, Prop_Data, "m_ModelName", sModel, sizeof(sModel));
ReplaceString(sModel, sizeof(sModel), "ins_01_destr", "sec_01");
SetEntityModel(ent, sModel);
}
public Action:CacheInfo(client, args)
{
SearchAllCache(client);
return Plugin_Handled;
}
void SearchAllCache(client)
{
new ent = -1;
new i = 1;
while(i == 1)
{
ent = FindEntityByClassname(ent,"obj_weapon_cache");
if(IsValidEntity(ent))
{
decl String:strEntName[32];
GetEntPropString(ent, Prop_Data, "m_iszControlPoint", strEntName, sizeof(strEntName));
decl String:targetname[64];
GetEntPropString(ent, Prop_Data, "m_iName", targetname, sizeof(targetname));
if((strlen(strEntName) > 0) && (strlen(targetname) > 0))
{
int nLifeState = GetEntProp(ent, Prop_Data, "m_lifeState");
int nTeam = GetEntProp(ent, Prop_Data, "m_iTeamNum");
ReplyToCommand(client, "%s %s: %d \nLifeState: %d \nTeam: %d\n", targetname, strEntName, ent, nLifeState, nTeam);
continue;
}
}
i = 0;
}
}
void ResetCache()
{
new ent = -1;
new i = 1;
while(i == 1)
{
ent = FindEntityByClassname(ent,"obj_weapon_cache");
if(IsValidEntity(ent))
{
decl String:strEntName[32];
GetEntPropString(ent, Prop_Data, "m_iszControlPoint", strEntName, sizeof(strEntName));
decl String:targetname[64];
GetEntPropString(ent, Prop_Data, "m_iName", targetname, sizeof(targetname));
if((strlen(strEntName) > 0) && (strlen(targetname) > 0))
{
SetEntProp(ent, Prop_Data, "m_lifeState", 0);
SetEntProp(ent, Prop_Data, "m_iTeamNum", TEAM_INSURGENTS);
continue;
}
}
i = 0;
}
}
bool:IsValidClient(client)
{
if ( !( 1 <= client <= MaxClients ) || !IsClientInGame(client) )
return false;
return true;
}
bool:IsCounterAttack()
{
bool ret = bool:GameRules_GetProp("m_bCounterAttack");
return ret;
}