-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrpg_ctDoors.sp
203 lines (178 loc) · 6.15 KB
/
rpg_ctDoors.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
/*
T-RP
Copyright (C) 2017 Christian Ziegler
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/>.
*/
#pragma semicolon 1
#define PLUGIN_AUTHOR "Totenfluch"
#define PLUGIN_VERSION "1.00"
#include <sourcemod>
#include <sdktools>
#include <rpg_jobs_core>
#include <rpg_inventory_core>
#include <tCrime>
#pragma newdecls required
int g_iPlayerPrevButtons[MAXPLAYERS + 1];
int g_iSelectedDoorRef[MAXPLAYERS + 1];
public Plugin myinfo =
{
name = "[T-RP] CT Doors",
author = PLUGIN_AUTHOR,
description = "Allows Police Officers to lock/unlock doors and prisoners escape",
version = PLUGIN_VERSION,
url = "https://totenfluch.de"
};
public void OnPluginStart() {
HookEvent("round_start", onRoundStart);
}
public void onRoundStart(Handle event, const char[] name, bool dontBroadcast) {
lockDoors("jail_door");
}
public void OnClientPostAdminCheck(int client) {
g_iPlayerPrevButtons[client] = 0;
g_iSelectedDoorRef[client] = -1;
}
public Action OnPlayerRunCmd(int client, int &iButtons, int &iImpulse, float fVelocity[3], float fAngles[3], int &iWeapon, int &tickcount) {
if (!isValidClient(client))
return;
if (IsPlayerAlive(client)) {
if (!(g_iPlayerPrevButtons[client] & IN_USE) && iButtons & IN_USE) {
int ent = GetClientAimTarget(client, false);
if (IsValidEntity(ent) && ent > 64) {
if (HasEntProp(ent, Prop_Data, "m_iName")) {
char uniqueId[64];
GetEntPropString(ent, Prop_Data, "m_iName", uniqueId, sizeof(uniqueId));
if (/*(StrContains(uniqueId, "ct_p_") != -1) || */StrContains(uniqueId, "jail_door") != -1) {
if (jobs_isActiveJob(client, "Police")) {
ctDoorMenu(client, ent);
} else {
if (inventory_hasPlayerItem(client, "Lockpick"))
openCriminalMenu(client, ent);
}
}
}
}
}
g_iPlayerPrevButtons[client] = iButtons;
}
}
public void ctDoorMenu(int client, int ent) {
g_iSelectedDoorRef[client] = EntIndexToEntRef(ent);
Menu ctMenu = CreateMenu(ctMenuHandler);
SetMenuTitle(ctMenu, "CT Door");
AddMenuItem(ctMenu, "x", "Ignore");
AddMenuItem(ctMenu, "unlock", "Unlock Door");
AddMenuItem(ctMenu, "lock", "Lock Door");
DisplayMenu(ctMenu, client, 60);
}
public int ctMenuHandler(Handle menu, MenuAction action, int client, int item) {
if (action == MenuAction_Select) {
char cValue[32];
GetMenuItem(menu, item, cValue, sizeof(cValue));
if (StrEqual(cValue, "x"))
return;
int doorEnt = EntRefToEntIndex(g_iSelectedDoorRef[client]);
float playerPos[3];
float entPos[3];
if (!isValidClient(client))
return;
if (!IsValidEntity(doorEnt))
return;
GetClientAbsOrigin(client, playerPos);
GetEntPropVector(doorEnt, Prop_Data, "m_vecOrigin", entPos);
if (GetVectorDistance(playerPos, entPos) > 175.0) {
PrintToChat(client, "[-T-] Door is too far away (%.2f/150.0)", GetVectorDistance(playerPos, entPos));
return;
}
if (StrEqual(cValue, "lock")) {
AcceptEntityInput(doorEnt, "lock", -1);
PrintToChat(client, "[-T-] CT Door locked");
} else if (StrEqual(cValue, "unlock")) {
AcceptEntityInput(doorEnt, "unlock", -1);
PrintToChat(client, "[-T-] Door unlocked");
}
}
if (action == MenuAction_End) {
delete menu;
}
}
public void openCriminalMenu(int client, int ent) {
g_iSelectedDoorRef[client] = EntIndexToEntRef(ent);
Menu criminalMenu = CreateMenu(criminalMenuHandler);
SetMenuTitle(criminalMenu, "CT Door");
AddMenuItem(criminalMenu, "x", "Ignore");
AddMenuItem(criminalMenu, "lockpick", "Lockpick Door");
DisplayMenu(criminalMenu, client, 60);
}
int g_iClientDoorTarget[MAXPLAYERS + 1];
public int criminalMenuHandler(Handle menu, MenuAction action, int client, int item) {
if (action == MenuAction_Select) {
char cValue[32];
GetMenuItem(menu, item, cValue, sizeof(cValue));
if (StrEqual(cValue, "x"))
return;
int doorEnt = EntRefToEntIndex(g_iSelectedDoorRef[client]);
float playerPos[3];
float entPos[3];
if (!isValidClient(client))
return;
if (!IsValidEntity(doorEnt))
return;
GetClientAbsOrigin(client, playerPos);
GetEntPropVector(doorEnt, Prop_Data, "m_vecOrigin", entPos);
if (GetVectorDistance(playerPos, entPos) > 175.0) {
PrintToChat(client, "[-T-] Door is too far away (%.2f/150.0)", GetVectorDistance(playerPos, entPos));
return;
}
if (StrEqual(cValue, "lockpick")) {
g_iClientDoorTarget[client] = EntIndexToEntRef(doorEnt);
jobs_startProgressBar(client, 100, "Lockpicking CT Door");
}
}
if (action == MenuAction_End) {
delete menu;
}
}
public void jobs_OnProgressBarInterrupted(int client, char info[64]) {
g_iClientDoorTarget[client] = -1;
}
public void jobs_OnProgressBarFinished(int client, char info[64]) {
if (StrEqual(info, "Lockpicking CT Door")) {
if (g_iClientDoorTarget[client] != -1) {
if (GetRandomInt(0, 10) == 2) {
AcceptEntityInput(EntRefToEntIndex(g_iClientDoorTarget[client]), "unlock", -1);
PrintToChat(client, "lockpicked CT Door...");
tCrime_addCrime(client, 300);
} else {
PrintToChat(client, "lockpicking CT Door failed");
tCrime_addCrime(client, 75);
}
if (GetRandomInt(0, 3) == 1) {
inventory_removePlayerItems(client, "Lockpick", 1, "Lockpick broke");
tCrime_addCrime(client, 50);
}
}
}
}
stock bool isValidClient(int client) {
return (1 <= client <= MaxClients && IsClientInGame(client));
}
public void lockDoors(char[] name) {
int entity = -1;
while ((entity = FindEntityByClassname(entity, "func_door")) != INVALID_ENT_REFERENCE) {
char uniqueId[64];
GetEntPropString(entity, Prop_Data, "m_iName", uniqueId, sizeof(uniqueId));
if (StrContains(uniqueId, name) != -1) {
AcceptEntityInput(entity, "lock", -1);
}
}
}