mirror of
https://github.com/Jackzmc/sourcemod-plugins.git
synced 2025-05-05 22:33:20 +00:00
l4d2_population_control: Fix precache crash by preventing model overwrites on load
This commit is contained in:
parent
c1c4df5bf4
commit
4a99d6bf48
2 changed files with 53 additions and 9 deletions
Binary file not shown.
|
@ -21,15 +21,36 @@ public Plugin myinfo =
|
|||
static ConVar hPercentTotal;
|
||||
static ConVar hPercentClown;
|
||||
static ConVar hPercentMud;
|
||||
static ConVar hPercentCeda;
|
||||
static ConVar hPercentWorker;
|
||||
static ConVar hPercentRiot;
|
||||
static ConVar hPercentJimmy;
|
||||
static ConVar hPercentFallen;
|
||||
|
||||
#define COMMON_MODELS_COUNT 2
|
||||
static bool IsDoneLoading;
|
||||
|
||||
#define COMMON_MODELS_COUNT 6
|
||||
static char INFECTED_MODELS[COMMON_MODELS_COUNT][] = {
|
||||
"models/infected/common_male_clown.mdl",
|
||||
"models/infected/common_male_mud.mdl"
|
||||
"models/infected/common_male_clown.mdl", //clown
|
||||
"models/infected/common_male_mud.mdl", //mud
|
||||
"models/infected/common_male_ceda.mdl", //ceda
|
||||
"models/infected/common_male_riot.mdl", //riot
|
||||
"models/infected/common_male_jimmy.mdl", //jimmy
|
||||
"models/infected/common_male_fallen_survivor.mdl", //fallen
|
||||
|
||||
};
|
||||
static char WORKER_MODELS[3][] = {
|
||||
"models/infected/common_worker_male01.mdl",
|
||||
"models/infected/common_male_roadcrew.mdl",
|
||||
"models/infected/common_male_roadcrew_rain.mdl"
|
||||
};
|
||||
enum CommonTypes {
|
||||
Common_Clown,
|
||||
Common_Mud
|
||||
Common_Mud,
|
||||
Common_Ceda,
|
||||
Common_Riot,
|
||||
Common_Jimmy,
|
||||
Common_Worker = -1,
|
||||
};
|
||||
|
||||
public void OnPluginStart() {
|
||||
|
@ -41,16 +62,30 @@ public void OnPluginStart() {
|
|||
hPercentTotal = CreateConVar("l4d2_population_global_chance", "1.0", "The % chance that any the below chances occur.\n0.0 = NEVER, 1.0: ALWAYS");
|
||||
hPercentClown = CreateConVar("l4d2_population_clowns", "0.0", "The % chance that a common spawns as a clown.\n0.0 = OFF, 1.0 = ALWAYS", FCVAR_NONE, true, 0.0, true, 1.0);
|
||||
hPercentMud = CreateConVar("l4d2_population_mud", "0.0", "The % chance that a common spawns as a mud zombie.\n0.0 = OFF, 1.0 = ALWAYS", FCVAR_NONE, true, 0.0, true, 1.0);
|
||||
}
|
||||
hPercentCeda = CreateConVar("l4d2_population_ceda", "0.0", "The % chance that a common spawns as a ceda zombie.\n0.0 = OFF, 1.0 = ALWAYS", FCVAR_NONE, true, 0.0, true, 1.0);
|
||||
hPercentWorker = CreateConVar("l4d2_population_worker", "0.0", "The % chance that a common spawns as a worker zombie.\n0.0 = OFF, 1.0 = ALWAYS", FCVAR_NONE, true, 0.0, true, 1.0);
|
||||
hPercentRiot = CreateConVar("l4d2_population_riot", "0.0", "The % chance that a common spawns as a riot zombie.\n0.0 = OFF, 1.0 = ALWAYS", FCVAR_NONE, true, 0.0, true, 1.0);
|
||||
hPercentJimmy = CreateConVar("l4d2_population_jimmy", "0.0", "The % chance that a common spawns as a Jimmy Gibs Jr. zombie.\n0.0 = OFF, 1.0 = ALWAYS", FCVAR_NONE, true, 0.0, true, 1.0);
|
||||
|
||||
AutoExecConfig(true, "l4d2_population_control");
|
||||
}
|
||||
public void OnMapStart() {
|
||||
for(int i = 0; i < COMMON_MODELS_COUNT; i++) {
|
||||
PrintToServer(">>> Precache %s", INFECTED_MODELS[i]);
|
||||
PrecacheModel(INFECTED_MODELS[i], true);
|
||||
}
|
||||
for(int i = 0; i < 3; i++) {
|
||||
PrintToServer(">>> Precache %s", INFECTED_MODELS[i]);
|
||||
PrecacheModel(WORKER_MODELS[i], true);
|
||||
}
|
||||
IsDoneLoading = true;
|
||||
}
|
||||
public void OnMapEnd() {
|
||||
IsDoneLoading = false;
|
||||
}
|
||||
|
||||
public void OnEntityCreated(int entity, const char[] classname) {
|
||||
if (StrEqual(classname, "infected")) {
|
||||
if (StrEqual(classname, "infected") && IsDoneLoading) {
|
||||
char m_ModelName[PLATFORM_MAX_PATH];
|
||||
GetEntPropString(entity, Prop_Data, "m_ModelName", m_ModelName, sizeof(m_ModelName));
|
||||
if(GetRandomFloat() <= hPercentTotal.FloatValue) {
|
||||
|
@ -59,6 +94,15 @@ public void OnEntityCreated(int entity, const char[] classname) {
|
|||
SetEntityModel(entity, INFECTED_MODELS[Common_Clown]);
|
||||
}else if(spawnPercentage <= hPercentMud.FloatValue) {
|
||||
SetEntityModel(entity, INFECTED_MODELS[Common_Mud]);
|
||||
}else if(spawnPercentage <= hPercentCeda.FloatValue) {
|
||||
SetEntityModel(entity, INFECTED_MODELS[Common_Ceda]);
|
||||
}else if(spawnPercentage <= hPercentWorker.FloatValue) {
|
||||
//worker has multiple models:
|
||||
SetEntityModel(entity, WORKER_MODELS[GetRandomInt(0,2)]);
|
||||
}else if(spawnPercentage <= hPercentRiot.FloatValue) {
|
||||
SetEntityModel(entity, INFECTED_MODELS[Common_Riot]);
|
||||
}else if(spawnPercentage <= hPercentJimmy.FloatValue) {
|
||||
SetEntityModel(entity, INFECTED_MODELS[Common_Jimmy]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue