Use troll instance cache for magnet, use flag for random chance

This commit is contained in:
Jackzie 2021-10-04 23:20:29 -05:00
parent 0c86d26438
commit 4bb94de1c6
No known key found for this signature in database
GPG key ID: 1E834FE36520537A

View file

@ -78,6 +78,11 @@ public Action L4D2_OnChooseVictim(int attacker, int &curTarget) {
// ========================= // =========================
// OVERRIDE VICTIM // OVERRIDE VICTIM
// ========================= // =========================
static Troll spMagnet;
static Troll tankMagnet;
if(!spMagnet.id) GetTroll("Special Magnet", spMagnet);
if(!tankMagnet.id) GetTroll("Tank Magnet", tankMagnet);
if(hMagnetChance.FloatValue < GetRandomFloat()) return Plugin_Continue; if(hMagnetChance.FloatValue < GetRandomFloat()) return Plugin_Continue;
L4D2Infected class = view_as<L4D2Infected>(GetEntProp(attacker, Prop_Send, "m_zombieClass")); L4D2Infected class = view_as<L4D2Infected>(GetEntProp(attacker, Prop_Send, "m_zombieClass"));
int existingTarget = GetClientOfUserId(g_iAttackerTarget[attacker]); int existingTarget = GetClientOfUserId(g_iAttackerTarget[attacker]);
@ -101,7 +106,11 @@ public Action L4D2_OnChooseVictim(int attacker, int &curTarget) {
if((class == L4D2Infected_Tank && hMagnetTargetMode.IntValue & 2 == 2) || hMagnetTargetMode.IntValue & 1 == 1 ) continue; if((class == L4D2Infected_Tank && hMagnetTargetMode.IntValue & 2 == 2) || hMagnetTargetMode.IntValue & 1 == 1 ) continue;
} }
if(class == L4D2Infected_Tank && IsTrollActive(i, "Tank Magnet") || (class != L4D2Infected_Tank && IsTrollActive(i, "Special Magnet"))) { if(class == L4D2Infected_Tank && tankMagnet.IsActive(i) || (class != L4D2Infected_Tank && spMagnet.IsActive(i))) {
if(class == L4D2Infected_Tank) {
if(!WillMagnetRun(tankMagnet, i)) return Plugin_Continue;
} else if(!WillMagnetRun(spMagnet, i)) return Plugin_Continue;
GetClientAbsOrigin(i, survPos); GetClientAbsOrigin(i, survPos);
float dist = GetVectorDistance(survPos, spPos, true); float dist = GetVectorDistance(survPos, spPos, true);
if(closestClient == -1 || dist < closestDistance) { if(closestClient == -1 || dist < closestDistance) {
@ -119,6 +128,17 @@ public Action L4D2_OnChooseVictim(int attacker, int &curTarget) {
} }
return Plugin_Continue; return Plugin_Continue;
} }
bool WillMagnetRun(const Troll troll, int i) {
if(troll.activeFlagClients[i] == 0) return true;
float cChance = 1.0;
//Skip first bit as it is ('Always')
if(troll.activeFlagClients[i] & 2) // 2nd: 50%
cChance = 0.5;
else if(troll.activeFlagClients[i] & 4) //3rd: 10%
cChance = 0.1;
return GetRandomFloat() <= cChance;
}
public Action L4D2_OnEntityShoved(int client, int entity, int weapon, float vecDir[3], bool bIsHighPounce) { public Action L4D2_OnEntityShoved(int client, int entity, int weapon, float vecDir[3], bool bIsHighPounce) {
if(client > 0 && client <= MaxClients && IsTrollActive(client, "No Shove") && hShoveFailChance.FloatValue > GetRandomFloat()) { if(client > 0 && client <= MaxClients && IsTrollActive(client, "No Shove") && hShoveFailChance.FloatValue > GetRandomFloat()) {
return Plugin_Handled; return Plugin_Handled;
@ -141,7 +161,7 @@ public Action OnClientSayCommand(int client, const char[] command, const char[]
PrintToServer("%N: %s", client, sArgs); PrintToServer("%N: %s", client, sArgs);
return Plugin_Handled; return Plugin_Handled;
}else if(IsTrollActive(client, "iCantSpellNoMore")) { }else if(IsTrollActive(client, "iCantSpellNoMore")) {
int type = GetRandomInt(1, trollKV.Size + 8); int type = GetRandomInt(1, 13 + 5);
char letterSrc, replaceChar; char letterSrc, replaceChar;
switch(type) { switch(type) {
case 1: { case 1: {
@ -196,6 +216,10 @@ public Action OnClientSayCommand(int client, const char[] command, const char[]
letterSrc = 'e'; letterSrc = 'e';
replaceChar = 'r'; replaceChar = 'r';
} }
case 14: {
letterSrc = 'w';
replaceChar = 'h';
}
default: default:
return Plugin_Continue; return Plugin_Continue;
@ -413,23 +437,28 @@ void EntityCreateCallback(int entity) {
if(!HasEntProp(entity, Prop_Send, "m_hOwnerEntity") || !IsValidEntity(entity)) return; if(!HasEntProp(entity, Prop_Send, "m_hOwnerEntity") || !IsValidEntity(entity)) return;
static char class[16]; static char class[16];
static Troll badThrow;
if(!badThrow.id) {
GetTroll("Bad Throw", badThrow);
}
GetEntityClassname(entity, class, sizeof(class)); GetEntityClassname(entity, class, sizeof(class));
int entOwner = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity"); int entOwner = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity");
if(entOwner > 0 && entOwner <= MaxClients) { if(entOwner > 0 && entOwner <= MaxClients) {
if(IsTrollActive(entOwner, "Bad Throw")) { if(badThrow.IsActive(entOwner)) {
static float pos[3]; static float pos[3];
GetClientEyePosition(entOwner, pos); GetClientEyePosition(entOwner, pos);
if(StrContains(class, "vomitjar", true) > -1) { if(badThrow.IsFlagActive(entOwner, Flag_1) && StrContains(class, "vomitjar", true) > -1) {
AcceptEntityInput(entity, "Kill"); AcceptEntityInput(entity, "Kill");
if(hBadThrowHitSelf.FloatValue > 0.0 && GetRandomFloat() > hBadThrowHitSelf.FloatValue) { if(hBadThrowHitSelf.FloatValue > 0.0 && GetRandomFloat() <= hBadThrowHitSelf.FloatValue) {
L4D_CTerrorPlayer_OnVomitedUpon(entOwner, entOwner); L4D_CTerrorPlayer_OnVomitedUpon(entOwner, entOwner);
EmitSoundToAll("weapons/ceda_jar/ceda_jar_explode.wav", entOwner); EmitSoundToAll("weapons/ceda_jar/ceda_jar_explode.wav", entOwner);
FindClosestClient(entOwner, false, pos); FindClosestClient(entOwner, false, pos);
} }
SpawnItem("vomitjar", pos); SpawnItem("vomitjar", pos);
} else if(StrContains(class, "molotov", true) > -1) { } else if(badThrow.IsFlagActive(entOwner, Flag_2) && StrContains(class, "molotov", true) > -1) {
// Burn them if no one near :) // Burn them if no one near :)
if(hBadThrowHitSelf.FloatValue > 0.0 && GetRandomFloat() > hBadThrowHitSelf.FloatValue) { if(hBadThrowHitSelf.FloatValue > 0.0 && GetRandomFloat() <= hBadThrowHitSelf.FloatValue) {
GetClientAbsOrigin(entOwner, pos); GetClientAbsOrigin(entOwner, pos);
if(IsAnyPlayerNear(entOwner, 500.0)) { if(IsAnyPlayerNear(entOwner, 500.0)) {
AcceptEntityInput(entity, "Kill"); AcceptEntityInput(entity, "Kill");
@ -441,8 +470,8 @@ void EntityCreateCallback(int entity) {
SpawnItem("molotov", pos); SpawnItem("molotov", pos);
AcceptEntityInput(entity, "Kill"); AcceptEntityInput(entity, "Kill");
} }
} else if(StrContains(class, "pipe_bomb", true) > -1) { } else if(badThrow.IsFlagActive(entOwner, Flag_3) && StrContains(class, "pipe_bomb", true) > -1) {
if(hBadThrowHitSelf.FloatValue > 0.0 && GetRandomFloat() > hBadThrowHitSelf.FloatValue) if(hBadThrowHitSelf.FloatValue > 0.0 && GetRandomFloat() <= hBadThrowHitSelf.FloatValue)
TeleportEntity(entity, pos, NULL_VECTOR, NULL_VECTOR); TeleportEntity(entity, pos, NULL_VECTOR, NULL_VECTOR);
SpawnItem("pipe_bomb", pos); SpawnItem("pipe_bomb", pos);
} }
@ -460,4 +489,4 @@ int FindClosestVisibleClient(int source) {
public bool TraceEntityFilterPlayer(int entity, int mask, any data) { public bool TraceEntityFilterPlayer(int entity, int mask, any data) {
return data != entity && entity <= MaxClients && GetClientTeam(entity) == 2 && IsPlayerAlive(entity); return data != entity && entity <= MaxClients && GetClientTeam(entity) == 2 && IsPlayerAlive(entity);
} }