forked from jeremyvillanuevar/scripting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLMC_L4D2_RandomSpawns.sp
More file actions
453 lines (397 loc) · 12.7 KB
/
LMC_L4D2_RandomSpawns.sp
File metadata and controls
453 lines (397 loc) · 12.7 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
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
/*
* LMC_L4D2_RandomSpawns - Makes lmc models random for humans&ai
* Copyright (C) 2019 LuxLuma acceliacat@gmail.com
*
* 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 <https://www.gnu.org/licenses/>.
*/
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#define REQUIRE_PLUGIN
#include <LMCL4D2CDeathHandler>
#include <LMCL4D2SetTransmit>
#include <LMCCore>
#undef REQUIRE_PLUGIN
#pragma newdecls required
#define PLUGIN_NAME "LMC_L4D2_RandomSpawns"
#define PLUGIN_VERSION "1.0.1"
#define HUMAN_MODEL_PATH_SIZE 10
#define SPECIAL_MODEL_PATH_SIZE 7
#define UNCOMMON_MODEL_PATH_SIZE 5
#define COMMON_MODEL_PATH_SIZE 33
enum ZOMBIECLASS
{
ZOMBIECLASS_SMOKER = 1,
ZOMBIECLASS_BOOMER,
ZOMBIECLASS_HUNTER,
ZOMBIECLASS_SPITTER,
ZOMBIECLASS_JOCKEY,
ZOMBIECLASS_CHARGER,
ZOMBIECLASS_UNKNOWN,
ZOMBIECLASS_TANK,
}
enum LMCModelSectionType
{
LMCModelSectionType_Human = 0,
LMCModelSectionType_Special,
LMCModelSectionType_UnCommon,
LMCModelSectionType_Common
};
static const char sHumanPaths[HUMAN_MODEL_PATH_SIZE+1][] =
{
"models/survivors/survivor_gambler.mdl",
"models/survivors/survivor_producer.mdl",
"models/survivors/survivor_coach.mdl",
"models/survivors/survivor_mechanic.mdl",
"models/survivors/survivor_namvet.mdl",
"models/survivors/survivor_teenangst.mdl",
"models/survivors/survivor_teenangst_light.mdl",
"models/survivors/survivor_biker.mdl",
"models/survivors/survivor_biker_light.mdl",
"models/survivors/survivor_manager.mdl",
"models/npcs/rescue_pilot_01.mdl"
};
enum LMCHumanModelType
{
LMCHumanModelType_Nick = 0,
LMCHumanModelType_Rochelle,
LMCHumanModelType_Coach,
LMCHumanModelType_Ellis,
LMCHumanModelType_Bill,
LMCHumanModelType_Zoey,
LMCHumanModelType_ZoeyLight,
LMCHumanModelType_Francis,
LMCHumanModelType_FrancisLight,
LMCHumanModelType_Louis,
LMCHumanModelType_Pilot
};
static const char sSpecialPaths[SPECIAL_MODEL_PATH_SIZE+1][] =
{
"models/infected/witch.mdl",
"models/infected/witch_bride.mdl",
"models/infected/boomer.mdl",
"models/infected/boomette.mdl",
"models/infected/hunter.mdl",
"models/infected/smoker.mdl",
"models/infected/hulk.mdl",
"models/infected/hulk_dlc3.mdl"
};
enum LMCSpecialModelType
{
LMCSpecialModelType_Witch = 0,
LMCSpecialModelType_WitchBride,
LMCSpecialModelType_Boomer,
LMCSpecialModelType_Boomette,
LMCSpecialModelType_Hunter,
LMCSpecialModelType_Smoker,
LMCSpecialModelType_Tank,
LMCSpecialModelType_TankDLC3
};
static const char sUnCommonPaths[UNCOMMON_MODEL_PATH_SIZE+1][] =
{
"models/infected/common_male_riot.mdl",
"models/infected/common_male_mud.mdl",
"models/infected/common_male_ceda.mdl",
"models/infected/common_male_clown.mdl",
"models/infected/common_male_jimmy.mdl",
"models/infected/common_male_fallen_survivor.mdl"
};
enum LMCUnCommonModelType
{
LMCUnCommonModelType_RiotCop = 0,
LMCUnCommonModelType_MudMan,
LMCUnCommonModelType_Ceda,
LMCUnCommonModelType_Clown,
LMCUnCommonModelType_Jimmy,
LMCUnCommonModelType_Fallen
};
static const char sCommonPaths[COMMON_MODEL_PATH_SIZE+1][] =
{
"models/infected/common_male_tshirt_cargos.mdl",
"models/infected/common_male_tankTop_jeans.mdl",
"models/infected/common_male_dressShirt_jeans.mdl",
"models/infected/common_female_tankTop_jeans.mdl",
"models/infected/common_female_tshirt_skirt.mdl",
"models/infected/common_male_roadcrew.mdl",
"models/infected/common_male_tankTop_overalls.mdl",
"models/infected/common_male_tankTop_jeans_rain.mdl",
"models/infected/common_female_tankTop_jeans_rain.mdl",
"models/infected/common_male_roadcrew_rain.mdl",
"models/infected/common_male_tshirt_cargos_swamp.mdl",
"models/infected/common_male_tankTop_overalls_swamp.mdl",
"models/infected/common_female_tshirt_skirt_swamp.mdl",
"models/infected/common_male_formal.mdl",
"models/infected/common_female_formal.mdl",
"models/infected/common_military_male01.mdl",
"models/infected/common_police_male01.mdl",
"models/infected/common_male_baggagehandler_01.mdl",
"models/infected/common_tsaagent_male01.mdl",
"models/infected/common_shadertest.mdl",
"models/infected/common_female_nurse01.mdl",
"models/infected/common_surgeon_male01.mdl",
"models/infected/common_worker_male01.mdl",
"models/infected/common_morph_test.mdl",
"models/infected/common_male_biker.mdl",
"models/infected/common_female01.mdl",
"models/infected/common_male01.mdl",
"models/infected/common_male_suit.mdl",
"models/infected/common_patient_male01_l4d2.mdl",
"models/infected/common_male_polo_jeans.mdl",
"models/infected/common_female_rural01.mdl",
"models/infected/common_male_rural01.mdl",
"models/infected/common_male_pilot.mdl",
"models/infected/common_test.mdl"
};
#define CvarIndexes 7
static const char sSharedCvarNames[CvarIndexes][] =
{
"lmc_allowtank",
"lmc_allowhunter",
"lmc_allowsmoker",
"lmc_allowboomer",
"lmc_allowSurvivors",
"lmc_allow_tank_model_use",
"lmc_precache_prevent"
};
static Handle hCvar_ArrayIndex[CvarIndexes] = {INVALID_HANDLE, ...};
static bool g_bAllowTank = false;
static bool g_bAllowHunter = true;
static bool g_bAllowSmoker = true;
static bool g_bAllowBoomer = true;
static bool g_bAllowSurvivors = true;
static bool g_bTankModel = false;
static Handle hCvar_RNGHumans = INVALID_HANDLE;
static Handle hCvar_Survivors = INVALID_HANDLE;
static Handle hCvar_Infected = INVALID_HANDLE;
static bool g_bRNGHumans = false;
static int g_iChanceSurvivor = 10;
static int g_iChanceInfected = 20;
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
if(GetEngineVersion() != Engine_Left4Dead2 )
{
strcopy(error, err_max, "Plugin only supports Left 4 Dead 2");
return APLRes_SilentFailure;
}
return APLRes_Success;
}
public Plugin myinfo =
{
name = PLUGIN_NAME,
author = "Lux",
description = "Makes lmc models random for humans&ai",
version = PLUGIN_VERSION,
url = "https://forums.alliedmods.net/showthread.php?p=2607394"
};
public void OnPluginStart()
{
CreateConVar("lmc_l4d2_randomspawns_version", PLUGIN_VERSION, "LMC_RandomAiSpawns_Version", FCVAR_DONTRECORD|FCVAR_NOTIFY);
hCvar_RNGHumans = CreateConVar("lmc_rng_humans", "0", "Allow humans to be considered by rng, menu selection will overwrite this in LMC_Menu_Choosing", FCVAR_NOTIFY, true, 0.0, true, 1.0);
hCvar_Survivors = CreateConVar("lmc_rng_model_survivor", "10", "(0 = disable custom models)chance on which will get a custom model", FCVAR_NOTIFY, true, 0.0, true, 100.0);
hCvar_Infected = CreateConVar("lmc_rng_model_infected", "20", "(0 = disable custom models)chance on which will get a custom model", FCVAR_NOTIFY, true, 0.0, true, 100.0);
HookConVarChange(hCvar_RNGHumans, eConvarChanged);
HookConVarChange(hCvar_Survivors, eConvarChanged);
HookConVarChange(hCvar_Infected, eConvarChanged);
AutoExecConfig(true, "LMC_L4D2_RandomSpawns");
CvarsChanged();
HookEvent("player_spawn", ePlayerSpawn);
}
public void eConvarChanged(Handle hCvar, const char[] sOldVal, const char[] sNewVal)
{
CvarsChanged();
}
void CvarsChanged()
{
if(hCvar_ArrayIndex[0] != INVALID_HANDLE)
g_bAllowTank = GetConVarInt(hCvar_ArrayIndex[0]) > 0;
if(hCvar_ArrayIndex[1] != INVALID_HANDLE)
g_bAllowHunter = GetConVarInt(hCvar_ArrayIndex[1]) > 0;
if(hCvar_ArrayIndex[2] != INVALID_HANDLE)
g_bAllowSmoker = GetConVarInt(hCvar_ArrayIndex[2]) > 0;
if(hCvar_ArrayIndex[3] != INVALID_HANDLE)
g_bAllowBoomer = GetConVarInt(hCvar_ArrayIndex[3]) > 0;
if(hCvar_ArrayIndex[4] != INVALID_HANDLE)
g_bAllowSurvivors = GetConVarInt(hCvar_ArrayIndex[4]) > 0;
if(hCvar_ArrayIndex[5] != INVALID_HANDLE)
g_bTankModel = GetConVarInt(hCvar_ArrayIndex[5]) > 0;
g_bRNGHumans = GetConVarInt(hCvar_RNGHumans) > 0;
g_iChanceSurvivor = GetConVarInt(hCvar_Survivors);
g_iChanceInfected = GetConVarInt(hCvar_Infected);
}
void HookCvars()
{
for(int i = 0; i < CvarIndexes; i++)
{
if(hCvar_ArrayIndex[i] != INVALID_HANDLE)
continue;
if((hCvar_ArrayIndex[i] = FindConVar(sSharedCvarNames[i])) == INVALID_HANDLE)
{
PrintToServer("[LMC]Unable to find shared cvar \"%s\" using fallback value plugin:(%s)", sSharedCvarNames[i], PLUGIN_NAME);
continue;
}
HookConVarChange(hCvar_ArrayIndex[i], eConvarChanged);
}
}
public void OnMapStart()
{
bool bPrecacheModels = true;
if(FindConVar(sSharedCvarNames[6]) != INVALID_HANDLE)
{
char sCvarString[4096];
char sMap[66];
GetConVarString(FindConVar(sSharedCvarNames[6]), sCvarString, sizeof(sCvarString));
GetCurrentMap(sMap, sizeof(sMap));
Format(sMap, sizeof(sMap), ",%s,", sMap);
Format(sCvarString, sizeof(sCvarString), ",%s,", sCvarString);
if(StrContains(sCvarString, sMap, false) != -1)
bPrecacheModels = false;
if(!bPrecacheModels)
{
ReplaceString(sMap, sizeof(sMap), ",", "", false);
PrintToServer("[%s] \"%s\" Model Precaching Disabled.", PLUGIN_NAME, sMap);
}
}
if(bPrecacheModels)
{
int i;
for(i = 0; i <= HUMAN_MODEL_PATH_SIZE; i++)
PrecacheModel(sHumanPaths[i], true);
for(i = 0; i <= SPECIAL_MODEL_PATH_SIZE; i++)
PrecacheModel(sSpecialPaths[i], true);
for(i = 0; i <= UNCOMMON_MODEL_PATH_SIZE; i++)
PrecacheModel(sUnCommonPaths[i], true);
for(i = 0; i <= COMMON_MODEL_PATH_SIZE; i++)
PrecacheModel(sCommonPaths[i], true);
}
HookCvars();
CvarsChanged();
}
public void ePlayerSpawn(Handle hEvent, const char[] sEventName, bool bDontBroadcast)
{
int iUserID = GetEventInt(hEvent, "userid");
int iClient = GetClientOfUserId(iUserID);
if(iClient < 1 || iClient > MaxClients)
return;
if(!IsClientInGame(iClient) || !IsPlayerAlive(iClient))
return;
LMC_ResetRenderMode(iClient);
if(!g_bRNGHumans && !IsFakeClient(iClient))
return;
switch(GetClientTeam(iClient))
{
case 3:
{
switch(GetEntProp(iClient, Prop_Send, "m_zombieClass"))//1.4
{
case ZOMBIECLASS_SMOKER:
{
if(!g_bAllowSmoker)
return;
}
case ZOMBIECLASS_BOOMER:
{
if(!g_bAllowBoomer)
return;
}
case ZOMBIECLASS_HUNTER:
{
if(!g_bAllowHunter)
return;
}
case ZOMBIECLASS_CHARGER, ZOMBIECLASS_JOCKEY, ZOMBIECLASS_SPITTER, ZOMBIECLASS_UNKNOWN:
{
return;
}
case ZOMBIECLASS_TANK:
{
if(!g_bAllowTank)
return;
}
default:
{
return;
}
}
}
case 2:
{
if(!g_bAllowSurvivors)
return;
}
default:
{
return;
}
}
RequestFrame(NextFrame, iUserID);
}
public void NextFrame(int iUserID)
{
int iClient = GetClientOfUserId(iUserID);
if(iClient < 1 || !IsClientInGame(iClient) || !IsPlayerAlive(iClient))
return;
if(LMC_GetClientOverlayModel(iClient) > -1)
return;
char sModel[PLATFORM_MAX_PATH];
switch(GetClientTeam(iClient))
{
case 2:
if(GetRandomInt(1, 100) <= g_iChanceSurvivor)
if(!ChooseRNGModel(sModel))
return;
case 3:
if(GetRandomInt(1, 100) <= g_iChanceInfected)
if(!ChooseRNGModel(sModel))
return;
default:
return;
}
if(sModel[0] == '\0')
return;
if(!SameModel(iClient, sModel))
if(IsModelPrecached(sModel))
LMC_L4D2_SetTransmit(iClient, LMC_SetClientOverlayModel(iClient, sModel));
}
bool ChooseRNGModel(char sModel[PLATFORM_MAX_PATH])
{
switch(GetRandomInt(0, view_as<int>(LMCModelSectionType_Common)))
{
case LMCModelSectionType_Human:
strcopy(sModel, sizeof(sModel), sHumanPaths[GetRandomInt(0, HUMAN_MODEL_PATH_SIZE)]);
case LMCModelSectionType_Special:
{
int iRNG = GetRandomInt(0, SPECIAL_MODEL_PATH_SIZE);
if(!g_bTankModel)
if(iRNG == view_as<int>(LMCSpecialModelType_Tank) || iRNG == view_as<int>(LMCSpecialModelType_TankDLC3))
return false;
strcopy(sModel, sizeof(sModel), sSpecialPaths[iRNG]);
}
case LMCModelSectionType_UnCommon:
strcopy(sModel, sizeof(sModel), sUnCommonPaths[GetRandomInt(0, UNCOMMON_MODEL_PATH_SIZE)]);
case LMCModelSectionType_Common:
strcopy(sModel, sizeof(sModel), sCommonPaths[GetRandomInt(0, COMMON_MODEL_PATH_SIZE)]);
}
return true;
}
bool SameModel(int iClient, const char[] sPendingModel)
{
char sModel[PLATFORM_MAX_PATH];
GetEntPropString(iClient, Prop_Data, "m_ModelName", sModel, sizeof(sModel));
return StrEqual(sModel, sPendingModel, false);
}
public void LMC_OnClientModelApplied(int iClient, int iEntity, const char sModel[PLATFORM_MAX_PATH], bool bBaseReattach)
{
if(bBaseReattach)//if true because orignal overlay model has been killed
LMC_L4D2_SetTransmit(iClient, iEntity);
}