/
ttt_fakebody.sp
240 lines (200 loc) · 7.2 KB
/
ttt_fakebody.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
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
#include <ttt_shop>
#include <ttt>
#include <multicolors>
#define SHORT_NAME "fakebody"
#define PLUGIN_NAME TTT_PLUGIN_NAME ... " - Items: Fake Body"
ConVar g_cPrice = null;
ConVar g_cShowFakeMessage = null;
ConVar g_cDeleteFakeBodyAfterFound = null;
ConVar g_cAllowProofByTraitors = null;
ConVar g_cShowTraitorAsDead = null;
ConVar g_cCount = null;
ConVar g_cPrio = null;
ConVar g_cLongName = null;
int g_iPCount[MAXPLAYERS + 1] = { 0, ... };
ConVar g_cPluginTag = null;
char g_sPluginTag[PLATFORM_MAX_PATH] = "";
public Plugin myinfo =
{
name = PLUGIN_NAME,
author = TTT_PLUGIN_AUTHOR,
description = TTT_PLUGIN_DESCRIPTION,
version = TTT_PLUGIN_VERSION,
url = TTT_PLUGIN_URL
};
public void OnPluginStart()
{
TTT_IsGameCSGO();
TTT_LoadTranslations();
TTT_StartConfig("fakebody");
CreateConVar("ttt2_fakebody_version", TTT_PLUGIN_VERSION, TTT_PLUGIN_DESCRIPTION, FCVAR_NOTIFY | FCVAR_DONTRECORD | FCVAR_REPLICATED);
g_cLongName = AutoExecConfig_CreateConVar("fb_name", "Fakebody", "The name of the Fakebody in the Shop");
g_cPrice = AutoExecConfig_CreateConVar("fb_price", "9000", "The amount of credits a fake body costs as traitor. 0 to disable.");
g_cCount = AutoExecConfig_CreateConVar("fb_count", "1", "The amount of usages for fake bodys per round as traitor. 0 to disable.");
g_cPrio = AutoExecConfig_CreateConVar("fb_sort_prio", "0", "The sorting priority of the fake body in the shop menu.");
g_cAllowProofByTraitors = AutoExecConfig_CreateConVar("fb_allow_proof_by_all", "1", "Allow fake body scan for traitors players?");
g_cShowFakeMessage = AutoExecConfig_CreateConVar("fb_show_fake_message", "0", "Show the fake message (XXX has found a fake body)?");
g_cDeleteFakeBodyAfterFound = AutoExecConfig_CreateConVar("fb_delete_fakebody_after_found", "0", "Delete fake body after found?");
g_cShowTraitorAsDead = AutoExecConfig_CreateConVar("fb_show_traitor_as_dead", "1", "Show traitor as dead after fakebody found?");
TTT_EndConfig();
HookEvent("player_spawn", Event_PlayerSpawn);
}
public void TTT_OnLatestVersion(const char[] version)
{
TTT_CheckVersion(TTT_PLUGIN_VERSION, TTT_GetCommitsCount());
}
public void OnClientDisconnect(int client)
{
ResetFB(client);
}
public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
if (TTT_IsClientValid(client))
{
ResetFB(client);
}
}
public void OnConfigsExecuted()
{
g_cPluginTag = FindConVar("ttt_plugin_tag");
g_cPluginTag.AddChangeHook(OnConVarChanged);
g_cPluginTag.GetString(g_sPluginTag, sizeof(g_sPluginTag));
}
public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
if (convar == g_cPluginTag)
{
g_cPluginTag.GetString(g_sPluginTag, sizeof(g_sPluginTag));
}
}
public void TTT_OnShopReady()
{
RegisterItem();
}
void RegisterItem()
{
char sBuffer[MAX_ITEM_LENGTH];
g_cLongName.GetString(sBuffer, sizeof(sBuffer));
TTT_RegisterCustomItem(SHORT_NAME, sBuffer, g_cPrice.IntValue, TTT_TEAM_TRAITOR, g_cPrio.IntValue);
}
public Action TTT_OnItemPurchased(int client, const char[] itemshort, bool count, int price)
{
if (TTT_IsClientValid(client) && IsPlayerAlive(client))
{
if (StrEqual(itemshort, SHORT_NAME, false))
{
if (g_iPCount[client] >= g_cCount.IntValue)
{
char sBuffer[MAX_ITEM_LENGTH];
g_cLongName.GetString(sBuffer, sizeof(sBuffer));
CPrintToChat(client, "%s %T", g_sPluginTag, "Bought All", client, sBuffer, g_cCount.IntValue);
return Plugin_Stop;
}
if (!SpawnFakeBody(client))
{
return Plugin_Stop;
}
if (count)
{
g_iPCount[client]++;
}
}
}
return Plugin_Continue;
}
void ResetFB(int client)
{
g_iPCount[client] = 0;
}
bool SpawnFakeBody(int client)
{
char sModel[256];
float pos[3];
char sName[32];
GetClientModel(client, sModel, sizeof(sModel));
GetClientEyePosition(client, pos);
Format(sName, sizeof(sName), "fake_body_%d", GetClientUserId(client));
int iEntity = CreateEntityByName("prop_ragdoll");
DispatchKeyValue(iEntity, "model", sModel); //TODO: Add option to change model (random model)
DispatchKeyValue(iEntity, "targetname", sName);
SetEntProp(iEntity, Prop_Data, "m_nSolidType", SOLID_VPHYSICS);
SetEntProp(iEntity, Prop_Data, "m_CollisionGroup", COLLISION_GROUP_PLAYER);
SetEntityMoveType(iEntity, MOVETYPE_NONE);
AcceptEntityInput(iEntity, "DisableMotion");
if (DispatchSpawn(iEntity))
{
pos[2] -= 16.0;
TeleportEntity(iEntity, pos, NULL_VECTOR, NULL_VECTOR);
SetEntProp(iEntity, Prop_Data, "m_CollisionGroup", COLLISION_GROUP_DEBRIS_TRIGGER);
AcceptEntityInput(iEntity, "EnableMotion");
SetEntityMoveType(iEntity, MOVETYPE_VPHYSICS);
int iRagdollC[Ragdolls];
iRagdollC[Ent] = EntIndexToEntRef(iEntity);
iRagdollC[Victim] = GetClientUserId(client);
iRagdollC[VictimTeam] = TTT_GetClientRole(client);
GetClientName(client, iRagdollC[VictimName], MAX_NAME_LENGTH);
iRagdollC[Scanned] = false;
iRagdollC[Attacker] = 0;
iRagdollC[AttackerTeam] = TTT_TEAM_TRAITOR;
Format(iRagdollC[AttackerName], MAX_NAME_LENGTH, "Fake!");
iRagdollC[GameTime] = 0.0;
Format(iRagdollC[Weaponused], MAX_NAME_LENGTH, "Fake!");
iRagdollC[Found] = false;
TTT_SetRagdoll(iRagdollC[0]);
return true;
}
return false;
}
public Action TTT_OnBodyCheck(int client, int[] iRagdollC)
{
if (!TTT_IsClientValid(client))
{
return Plugin_Continue;
}
if (StrEqual(iRagdollC[Weaponused], "Fake!", false))
{
if (!g_cAllowProofByTraitors.BoolValue)
{
if (TTT_GetClientRole(client) == TTT_TEAM_TRAITOR)
{
return Plugin_Stop;
}
}
LoopValidClients(j)
{
if (g_cShowFakeMessage.BoolValue&& !iRagdollC[Found])
{
CPrintToChat(j, "%s %T", g_sPluginTag, "Found Fake", j, client);
}
else if (!g_cShowFakeMessage.BoolValue && !iRagdollC[Found])
{
CPrintToChat(j, "%s %T", g_sPluginTag, "Found Traitor", j, client, iRagdollC[VictimName]);
}
else if (iRagdollC[Found])
{
return Plugin_Stop;
}
}
if (g_cShowTraitorAsDead.BoolValue)
{
TTT_SetFoundStatus(GetClientOfUserId(iRagdollC[Victim]), true);
}
iRagdollC[Found] = true;
if (g_cDeleteFakeBodyAfterFound.BoolValue)
{
AcceptEntityInput(iRagdollC[Ent], "Kill");
}
if (!g_cDeleteFakeBodyAfterFound .BoolValue&& !g_cShowFakeMessage.BoolValue)
{
SetEntityRenderColor(iRagdollC[Ent], 255, 0, 0, 255);
}
return Plugin_Changed;
}
return Plugin_Continue;
}