ftt: Internal rewrite

This commit is contained in:
Jackzie 2021-09-23 08:45:27 -05:00
parent e2da73ba83
commit 498b4ecc7d
No known key found for this signature in database
GPG key ID: 1E834FE36520537A
5 changed files with 5128 additions and 398 deletions

Binary file not shown.

View file

@ -0,0 +1,237 @@
#define MAX_TROLL_NAME_LENGTH 32
#define MAX_TROLLS 25
//#define DEBUG 1
enum TrollModifier {
TrollMod_None = 0,
TrollMod_InstantFire = 1,
TrollMod_Repeat = 2
}
enum struct Troll {
char name[32];
char description[128];
bool runsOnce;
void GetID(char[] name, int length) {
strcopy(name, length, this.name);
ReplaceString(name, MAX_TROLL_NAME_LENGTH, " ", "", false);
}
}
Troll Trolls[MAX_TROLLS+1];
int ActiveTrolls[MAXPLAYERS+1];
StringMap trollKV;
char trollIds[MAX_TROLLS+1][MAX_TROLL_NAME_LENGTH];
int SetupTroll(const char[] name, const char description[128], bool hasMods) {
static int i = 0;
strcopy(Trolls[i].name, MAX_TROLL_NAME_LENGTH, name);
strcopy(Trolls[i].description, 128, description);
Trolls[i].runsOnce = !hasMods;
static char key[MAX_TROLL_NAME_LENGTH];
strcopy(key, MAX_TROLL_NAME_LENGTH, name);
ReplaceString(key, MAX_TROLL_NAME_LENGTH, " ", "", false);
strcopy(trollIds[i], MAX_TROLL_NAME_LENGTH, key);
trollKV.SetValue(key, i);
return i++;
}
// Gets the Troll enum struct via name
// Returns index of troll enum
int GetTroll(const char[] name, Troll troll) {
static int i = 0;
if(trollKV.GetValue(name, i)) {
troll = Trolls[i];
return i;
}
return -1;
}
// Gets the Troll enum struct via key index
// Returns index of troll enum
int GetTrollByKeyIndex(int index, Troll troll) {
// static char name[MAX_TROLL_NAME_LENGTH];
// trollIds.GetKey(index, name, sizeof(name));
troll = Trolls[index];
// return GetTroll(name, troll);
}
bool GetTrollID(int index, char name[MAX_TROLL_NAME_LENGTH]) {
if(index > MAX_TROLLS) return false;
strcopy(name, sizeof(name), trollIds[index]);
return true;
}
void ToggleTroll(int client, const char[] name) {
static Troll troll;
int index = GetTroll(name, troll);
ActiveTrolls[client] ^= 1 << view_as<int>(index);
}
void ApplyTroll(int victim, const char[] name, int activator, TrollModifier modifier, bool silent = false) {
static Troll troll;
int trollIndex = GetTroll(name, troll);
if(trollIndex == -1) {
PrintToServer("[FTT] %N attempted to apply unknown troll: %s", activator, name);
return;
}
if(GetClientTeam(victim) == 1) {
//Victim is spectating, find its bot
victim = FindIdlePlayerBot(victim);
}
ApplyAffect(victim, name, activator, modifier);
if(!silent) {
if(IsTrollActive(victim, name)) {
ShowActivity(victim, "deactivated troll \"%s\" on %N. ", troll.name, victim);
} else {
if(modifier == TrollMod_Repeat)
ShowActivity(victim, "activated troll \"%s\" on repeat for %N. ", troll.name, victim);
else
ShowActivity(victim, "activated troll \"%s\" for %N. ", troll.name, victim);
}
}
if(modifier == TrollMod_Repeat || modifier == TrollMod_None) {
ActiveTrolls[victim] ^= 1 << trollIndex;
}
}
void ApplyAffect(int victim, const char[] name, int activator, TrollModifier modifier) {
if(StrEqual(name, "ResetTroll")) {
ShowActivity(activator, "reset troll effects for %N. ", victim);
ActiveTrolls[victim] = 0;
return;
} else if(StrEqual(name, "SlowSpeed"))
SetEntPropFloat(victim, Prop_Send, "m_flLaggedMovementValue", 0.8);
else if(StrEqual(name, "HigherGravity"))
SetEntityGravity(victim, 1.3);
else if(StrEqual(name, "HalfPrimaryAmmo")) {
int current = GetPrimaryReserveAmmo(victim);
SetPrimaryReserveAmmo(victim, current / 2);
} else if(StrEqual(name, "UziRules")) {
DisableTroll(victim, "NoPickup");
DisableTroll(victim, "PrimaryDisable");
SDKHook(victim, SDKHook_WeaponCanUse, Event_ItemPickup);
} else if(StrEqual(name, "PrimaryDisable")) {
DisableTroll(victim, "UziRules");
DisableTroll(victim, "NoPickup");
SDKHook(victim, SDKHook_WeaponCanUse, Event_ItemPickup);
} else if(StrEqual(name, "NoPickup")) {
DisableTroll(victim, "UziRules");
DisableTroll(victim, "PrimaryDisable");
SDKHook(victim, SDKHook_WeaponCanUse, Event_ItemPickup);
} else if(StrEqual(name, "Clumsy")) {
int wpn = GetClientSecondaryWeapon(victim);
bool hasMelee = DoesClientHaveMelee(victim);
if(hasMelee) {
float pos[3];
int clients[4];
GetClientAbsOrigin(victim, pos);
int clientCount = GetClientsInRange(pos, RangeType_Visibility, clients, sizeof(clients));
for(int i = 0; i < clientCount; i++) {
if(clients[i] != victim) {
float targPos[3];
GetClientAbsOrigin(clients[i], targPos);
SDKHooks_DropWeapon(victim, wpn, targPos);
// g_iTrollUsers[victim] = mode;
CreateTimer(0.2, Timer_GivePistol);
return;
}
}
SDKHooks_DropWeapon(victim, wpn);
}
} else if(StrEqual(name, "CameTooEarly")) {
ReplyToCommand(activator, "This troll mode is not implemented.");
} else if(StrEqual(name, "KillMeSoftly")) {
static char wpn[32];
GetClientWeaponName(victim, 4, wpn, sizeof(wpn));
if(StrEqual(wpn, "weapon_adrenaline") || StrEqual(wpn, "weapon_pain_pills")) {
ClientCommand(victim, "slot5");
g_bPendingItemGive[victim] = true;
}else{
ReplyToCommand(activator, "User does not have pills or adrenaline");
return;
}
//TODO: Implement TrollMod_Repeat
return;
} else if(StrEqual(name, "ThrowItAll")) {
if(modifier == TrollMod_InstantFire)
ThrowAllItems(victim);
if(hThrowTimer == INVALID_HANDLE && modifier == TrollMod_Repeat) {
hThrowTimer = CreateTimer(hThrowItemInterval.FloatValue, Timer_ThrowTimer, _, TIMER_REPEAT);
}
} else if(StrEqual(name, "Swarm")) {
if(modifier == TrollMod_InstantFire) {
L4D2_RunScript("RushVictim(GetPlayerFromUserID(%d), %d)", victim, 15000);
}else if(modifier == TrollMod_Repeat) {
}else{
ReplyToCommand(activator, "Invalid modifier for mode.");
return;
}
} else if(StrEqual(name, "GunJam")) {
int wpn = GetClientWeaponEntIndex(victim, 0);
if(wpn > -1)
SDKHook(wpn, SDKHook_Reload, Event_WeaponReload);
else
ReplyToCommand(activator, "Victim does not have a primary weapon.");
} else if(StrEqual(name, "VomitPlayer"))
L4D_CTerrorPlayer_OnVomitedUpon(victim, victim);
else {
#if defined DEBUG
PrintToServer("[FTT] Possibly invalid troll, no action: %s", name);
ReplyToCommand(activator, "[FTT/Debug] If nothing occurs, this troll possibly was not implemented correctly. ");
#endif
}
}
bool IsTrollActive(int client, const char[] troll) {
if(ActiveTrolls[client] == 0) return false;
static int i = 0;
if(trollKV.GetValue(troll, i)) {
return ((ActiveTrolls[client] >> i) & 1) == 1;
}
ThrowError("Troll \"%s\" does not exist", troll);
return false; //errors instead but compiler no like
}
void DisableTroll(int client, const char[] troll) {
if(IsTrollActive(client, troll)) {
ToggleTroll(client, troll);
}
}
void SetupTrolls() {
trollKV = new StringMap();
SetupTroll("Reset Troll", "Resets the user, removes all troll effects", false);
SetupTroll("Special Magnet", "Attracts ALL specials to any alive target with this troll enabled", false);
SetupTroll("Tank Magnet", "Attracts ALL tanks to any alive target with this troll enabled", false);
SetupTroll("Witch Magnet", "All witches when startled will target any player with this troll", false);
SetupTroll("Vomit Player", "Shortcut to sm_vomitplayer. vomits the player.", false);
SetupTroll("ThrowItAll", "Player throws all their items at nearby player, periodically", true);
SetupTroll("Vocalize Gag", "Prevents player from sending any vocalizations (even automatic)", false);
SetupTroll("No Profanity", "Replaces some words with random phrases", false);
SetupTroll("Swarm", "Swarms a player with zombies. Requires swarm plugin", false);
SetupTroll("UziRules", "Picking up a weapon gives them a UZI instead", false);
SetupTroll("Slow Speed", "Sets player speed to 0.8x of normal speed", false);
SetupTroll("Higher Gravity", "Sets player gravity to 1.3x of normal gravity", false);
SetupTroll("Half Primary Ammo", "Cuts their primary reserve ammo in half", false);
SetupTroll("PrimaryDisable", "Player cannot pickup any weapons, only melee/pistols", true);
SetupTroll("Clusmy", "Player drops axe periodically or on demand", true);
SetupTroll("iCantSpellNoMore", "Chat messages letter will randomly changed with wrong letters", false);
SetupTroll("KillMeSoftly", "Make player eat or waste pills whenever possible", false);
SetupTroll("GunJam", "On reload, small chance their gun gets jammed - Can't reload.", false);
SetupTroll("NoPickup", "Prevents a player from picking up ANY (new) item. Use ThrowItAll to make them drop", true);
SetupTroll("Honk", "Honk", false);
SetupTroll("No Shove", "Prevents a player from shoving", false);
SetupTroll("Damage Boost", "Makes a player take more damage than normal", false);
SetupTroll("Temp Health Quick Drain", "Makes a player's temporarily health drain very quickly", false);
SetupTroll("Slow Drain", "Will make the player slowly lose health over time", false);
SetupTroll("CameTooEarly", "When they shoot, random chance they empty whole clip", true);
SetupTroll("Meow", "Makes the player meow", false);
//INFO: UP MAX_TROLLS when adding new trolls!
}

View file

@ -1,93 +1,8 @@
#define AUTOPUNISH_FLOW_MIN_DISTANCE 5000.0
#define AUTOPUNISH_MODE_COUNT 3
#define TROLL_MODE_COUNT 25
// #define TROLL_MODE_COUNT 26
//
enum trollMode {
Troll_Reset = 0, //0
Troll_SlowSpeed, //1
Troll_HigherGravity, //2
Troll_HalfPrimaryAmmo, //3
Troll_UziRules, //4
Troll_PrimaryDisable, //5
Troll_SlowDrain, //6
Troll_Clumsy, //7
Troll_iCantSpellNoMore, //8
Troll_CameTooEarly, //9
Troll_KillMeSoftly, //10
Troll_ThrowItAll, //11
Troll_GunJam, //12
Troll_NoPickup, //13
Troll_Swarm, //14
Troll_Honk, //15, //TODO: Modify sounds :)
Troll_SpecialMagnet, //16
Troll_TankMagnet, //17
Troll_NoShove, //18
Troll_DamageBoost, //19
Troll_TempHealthQuickDrain, //20
Troll_VomitPlayer, //21
Troll_VocalizeGag,
Troll_Meow,
Troll_WitchMagnet
}
enum TrollModifier {
TrollMod_None = 0,
TrollMod_InstantFire = 1,
TrollMod_Repeat = 2
}
char TROLL_MODES_NAMES[TROLL_MODE_COUNT][32] = {
"Reset User", //0
"Slow Speed", //1
"Higher Gravity", //2
"Half Primary Ammo", //3
"UziRules", //4
"PrimaryDisable", //5
"SlowDrain", //6
"Clusmy", //7
"iCantSpellNoMore", //8
"CameTooEarly", //9
"KillMeSoftly", //10
"ThrowItAll", //11
"GunJam", //12
"NoPickup",
"Swarm",
"Honk",
"Special Magnet",
"Tank Magnet",
"No Shove",
"Damage Boost",
"Temp Quick Drain",
"Vomit Player",
"Vocalize Gag",
"Meow",
"Witch Magnet"
};
char TROLL_MODES_DESCRIPTIONS[TROLL_MODE_COUNT][128] = {
"Resets the user, removes all troll effects", //0
"Sets player speed to 0.8x of normal speed", //1
"Sets player gravity to 1.3x of normal gravity", //2
"Cuts their primary reserve ammo in half", //3
"Picking up a weapon gives them a UZI instead", //4
"Player cannot pickup any weapons, only melee/pistols", //5
"Player slowly loses health", //6
"Player drops axe periodically or on demand", //7
"Chat messages letter will randomly changed with wrong letters ", //8
"When they shoot, random chance they empty whole clip", //9
"Make player eat or waste pills whenever possible", //10
"Player throws all their items at nearby player, periodically", //11
"On reload, small chance their gun gets jammed - Can't reload.", //12
"Prevents a player from picking up ANY (new) item. Use ThrowItAll to make them drop",
"Swarms a player with zombies. Requires swarm plugin",
"Honk",
"Attracts ALL specials to any alive target with this troll enabled",
"Attracts ALL tanks to any alive target with this troll enabled",
"Prevents a player from shoving",
"Makes a player take more damage than normal",
"Makes a player's temporarily health drain very quickly",
"Shortcut to sm_vomitplayer. vomits the player.",
"Prevents player from sending any vocalizations (even automatic)",
"Makes the player meow",
"All witches when startled will target any player with this troll"
};
enum L4D2Infected
{
@ -101,7 +16,7 @@ enum L4D2Infected
L4D2Infected_Witch = 7,
L4D2Infected_Tank = 8
};
int g_iTrollUsers[MAXPLAYERS+1], g_iAttackerTarget[MAXPLAYERS+1];
int g_iAttackerTarget[MAXPLAYERS+1];
int autoPunished = -1, autoPunishMode, lastButtonUser, lastCrescendoUser;
bool g_bPendingItemGive[MAXPLAYERS+1], g_PendingBanTroll[MAXPLAYERS+1];
GlobalForward g_PlayerMarkedForward;
@ -119,163 +34,12 @@ bool bChooseVictimAvailable = false; //For charge player feature, is it availabl
int g_iAmmoTable; //Loads the ammo table to get ammo amounts
int gChargerVictim = -1; //For charge player feature
//Applies the selected trollMode to the victim.
//Modifiers are as followed: 0 -> Both (fire instant, and timer), 1 -> Fire Once, 2 -> Start timer
void ApplyModeToClient(int client, int victim, trollMode mode, TrollModifier modifier, bool silent = false) {
ResetClient(victim, false);
if(view_as<int>(mode) > TROLL_MODE_COUNT || view_as<int>(mode) < 0) {
ReplyToCommand(client, "Unknown troll mode ID '%d'. Pick a mode between 1 and %d", mode, TROLL_MODE_COUNT - 1);
return;
}
float ZERO_VECTOR[3] = {0.0, 0.0, 0.0};
if(GetClientTeam(victim) == 1) {
//Victim is spectating, find its bot
victim = FindIdlePlayerBot(victim);
}
//bool activating = !HasTrollMode(victim, mode);
switch(mode) {
case Troll_iCantSpellNoMore: {}
case Troll_Honk: {}
case Troll_TankMagnet: {}
case Troll_WitchMagnet: {}
case Troll_SpecialMagnet: {}
case Troll_NoShove: {}
case Troll_SlowDrain: {}
case Troll_TempHealthQuickDrain: {}
case Troll_Meow: {}
case Troll_VomitPlayer: {
L4D_CTerrorPlayer_OnVomitedUpon(victim, victim);
}
case Troll_Reset: {
ShowActivity(client, "reset troll effects for %N. ", victim);
g_iTrollUsers[victim] = Troll_Reset;
return;
}
case Troll_SlowSpeed:
SetEntPropFloat(victim, Prop_Send, "m_flLaggedMovementValue", 0.8);
case Troll_HigherGravity:
SetEntityGravity(victim, 1.3);
case Troll_HalfPrimaryAmmo: {
//TODO: Implement modifier code
int current = GetPrimaryReserveAmmo(victim);
SetPrimaryReserveAmmo(victim, current / 2);
}
case Troll_UziRules: {
TurnOffTrollMode(victim, Troll_NoPickup);
TurnOffTrollMode(victim, Troll_PrimaryDisable);
SDKHook(victim, SDKHook_WeaponCanUse, Event_ItemPickup);
}
case Troll_PrimaryDisable: {
TurnOffTrollMode(victim, Troll_UziRules);
TurnOffTrollMode(victim, Troll_NoPickup);
SDKHook(victim, SDKHook_WeaponCanUse, Event_ItemPickup);
}
case Troll_NoPickup: {
TurnOffTrollMode(victim, Troll_UziRules);
TurnOffTrollMode(victim, Troll_PrimaryDisable);
SDKHook(victim, SDKHook_WeaponCanUse, Event_ItemPickup);
}
case Troll_Clumsy: {
//TODO: Implement modifier code
int wpn = GetClientSecondaryWeapon(victim);
bool hasMelee = DoesClientHaveMelee(victim);
if(hasMelee) {
float pos[3];
int clients[4];
GetClientAbsOrigin(victim, pos);
int clientCount = GetClientsInRange(pos, RangeType_Visibility, clients, sizeof(clients));
for(int i = 0; i < clientCount; i++) {
if(clients[i] != victim) {
float targPos[3];
GetClientAbsOrigin(clients[i], targPos);
SDKHooks_DropWeapon(victim, wpn, targPos);
g_iTrollUsers[victim] = mode;
CreateTimer(0.2, Timer_GivePistol);
return;
}
}
SDKHooks_DropWeapon(victim, wpn);
}
}
case Troll_CameTooEarly:
//TODO: Implement modifier code
ReplyToCommand(client, "This troll mode is not implemented.");
case Troll_KillMeSoftly: {
char wpn[32];
GetClientWeaponName(victim, 4, wpn, sizeof(wpn));
if(StrEqual(wpn, "weapon_adrenaline") || StrEqual(wpn, "weapon_pain_pills")) {
ClientCommand(victim, "slot5");
g_bPendingItemGive[victim] = true;
}else{
ReplyToCommand(client, "User does not have pills or adrenaline");
return;
}
//TODO: Implement TrollMod_Repeat
return;
}
case Troll_ThrowItAll: {
if(modifier == TrollMod_InstantFire)
ThrowAllItems(victim);
if(hThrowTimer == INVALID_HANDLE && modifier == TrollMod_Repeat) {
PrintToServer("Created new throw item timer");
hThrowTimer = CreateTimer(hThrowItemInterval.FloatValue, Timer_ThrowTimer, _, TIMER_REPEAT);
}
}
case Troll_Swarm: {
if(modifier == TrollMod_InstantFire) {
L4D2_RunScript("RushVictim(GetPlayerFromUserID(%d), %d)", victim, 15000);
}else if(modifier == TrollMod_Repeat) {
}else{
ReplyToCommand(client, "Invalid modifier for mode.");
return;
}
}
case Troll_GunJam: {
int wpn = GetClientWeaponEntIndex(victim, 0);
if(wpn > -1)
SDKHook(wpn, SDKHook_Reload, Event_WeaponReload);
else
ReplyToCommand(client, "Victim does not have a primary weapon.");
} default: {
ReplyToCommand(client, "This trollMode is not implemented.");
PrintToServer("Troll Mode #%d not implemented (%s)", mode, TROLL_MODES_NAMES[mode]);
}
}
if(!silent) {
if(HasTrollMode(victim, mode)) {
ShowActivity(client, "deactivated troll \"%s\" on %N. ", TROLL_MODES_NAMES[mode], victim);
}else{
if(modifier == TrollMod_Repeat)
ShowActivity(client, "activated troll \"%s\" on repeat for %N. ", TROLL_MODES_NAMES[mode], victim);
else
ShowActivity(client, "activated troll \"%s\" for %N. ", TROLL_MODES_NAMES[mode], victim);
}
}
//If instant fire mod not provided (aka instead of no modifiers which equals both) OR repeat turned on, set bit:
if(modifier == TrollMod_Repeat || modifier == TrollMod_None) {
g_iTrollUsers[victim] ^= 1 << view_as<int>(mode) -1;
}
}
bool HasTrollMode(int client, trollMode mode) {
return ((g_iTrollUsers[client] >> view_as<int>(mode) - 1) & 1) == 1;
}
void ToggleTrollMode(int client, trollMode mode) {
g_iTrollUsers[client] ^= 1 << view_as<int>(mode) -1;
}
void TurnOffTrollMode(int client, trollMode mode) {
if(HasTrollMode(client, mode)) {
ToggleTrollMode(client, mode);
}
}
#include <feedthetrolls/base>
void ResetClient(int victim, bool wipe = true) {
if(wipe) g_iTrollUsers[victim] = Troll_Reset;
if(wipe) ActiveTrolls[victim] = 0;
SetEntityGravity(victim, 1.0);
SetEntPropFloat(victim, Prop_Send, "m_flLaggedMovementValue", 1.0);
SDKUnhook(victim, SDKHook_WeaponCanUse, Event_ItemPickup);
@ -286,14 +50,13 @@ void ResetClient(int victim, bool wipe = true) {
void ActivateAutoPunish(int client) {
if(hAutoPunish.IntValue & 2 == 2)
ApplyModeToClient(0, lastButtonUser, Troll_SpecialMagnet, TrollMod_None);
ApplyTroll(lastButtonUser, "SpecialMagnet", 0, TrollMod_None);
if(hAutoPunish.IntValue & 1 == 1)
ApplyModeToClient(0, lastButtonUser, Troll_TankMagnet, TrollMod_None);
ApplyTroll(lastButtonUser, "TankMagnet", 0, TrollMod_None);
if(hAutoPunish.IntValue & 8 == 8)
ApplyModeToClient(0, lastButtonUser, Troll_VomitPlayer, TrollMod_None);
ApplyTroll(lastButtonUser, "VomitPlayer", 0, TrollMod_None);
else if(hAutoPunish.IntValue & 4 == 4)
ApplyModeToClient(0, lastButtonUser, Troll_Swarm, TrollMod_None);
ApplyTroll(lastButtonUser, "Swarm", 0, TrollMod_None);
if(hAutoPunishExpire.IntValue > 0) {
CreateTimer(60.0 * hAutoPunishExpire.FloatValue, Timer_ResetAutoPunish, GetClientOfUserId(lastButtonUser));
}
@ -346,3 +109,132 @@ stock int FindIdlePlayerBot(int client) {
stock bool IsPlayerIncapped(int client) {
return GetEntProp(client, Prop_Send, "m_isIncapacitated") == 1;
}
char SPECIAL_NAMES[][] = {
"Smoker", "Boomer", "Hunter", "Spitter", "Jockey", "Charger", "Witch"
};
stock int GetSpecialType(const char[] input) {
for(int i = 0; i < sizeof(SPECIAL_NAMES); i++) {
if(strcmp(SPECIAL_NAMES[i], input, false) == 0) return i + 1;
}
return -1;
}
stock bool FindSuitablePosition(int target, const float pos[3], float outputPos[3], float minDistance = 19000.0, int tries = 100) {
outputPos = pos;
for(int i = tries; i > 0; i--) {
// int nav = L4D_GetNearestNavArea(pos);
// L4D_FindRandomSpot(nav, testPos);
// float dist = GetVectorDistance(testPos, pos, true);
outputPos[0] += GetRandomFloat(-30.0, 30.0);
outputPos[1] += GetRandomFloat(-30.0, 30.0);
float dist = GetVectorDistance(outputPos, pos, true);
if(dist >= minDistance && L4D2Direct_GetTerrorNavArea(outputPos) != Address_Null) { //5m^2
return true;
}
}
return false;
}
#define MAX_PHRASES_PER_WORD 8
#define MAX_PHRASE_LENGTH 191
StringMap REPLACEMENT_PHRASES;
//TODO: Load from cfg
/* Example:
exWord
{
"1" "phrase1"
"2" "phrase2"
}
*/
void LoadPhrases() {
KeyValues kv = new KeyValues("Phrases");
ArrayList phrases = new ArrayList(ByteCountToCells(MAX_PHRASE_LENGTH));
char sPath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sPath, sizeof(sPath), "data/ftt_phrases.cfg");
if(!FileExists(sPath) || !kv.ImportFromFile(sPath)) {
delete kv;
PrintToServer("[FTT] Could not load phrase list from data/ftt_phrases.cfg");
return;
}
static char word[32];
char phrase[MAX_PHRASE_LENGTH];
// Go through all the words:
kv.GotoFirstSubKey();
int i = 0;
static char buffer[4];
do {
kv.GetSectionName(word, sizeof(word));
phrases.Clear();
for(;;) {
IntToString(++i, buffer, sizeof(buffer));
kv.GetString(buffer, phrase, MAX_PHRASE_LENGTH, "_null");
if(strcmp(phrase, "_null") == 0) break;
phrases.PushString(phrase);
}
i = 0;
REPLACEMENT_PHRASES.SetValue(word, phrases.Clone(), true);
} while (kv.GotoNextKey(false));
delete kv;
}
float GetIdealMinDistance(int specialType) {
switch(specialType) {
// /*Boomer*/ case 2: return 1200.0;
/*Charger*/ case 6: return 19000.0;
/*Smoker*/ case 1: return 20000.0;
default:
return 12000.0;
}
}
public Action Timer_Kill(Handle h, int client) {
AcceptEntityInput(client, "Kill");
}
//TODO: Add Insta-Witch
bool SpawnSpecialInFace(int target, int specialType) {
static float pos[3], ang[3];
static float testPos[3];
testPos = pos;
GetClientAbsOrigin(target, pos);
GetClientEyeAngles(target, ang);
if(specialType != 5 && specialType != 2) { //If charger/hunter, find a suitable area that is at least 5 m away
float minDistance = GetIdealMinDistance(specialType);
GetHorizontalPositionFromOrigin(pos, ang, minDistance, testPos);
FindSuitablePosition(target, pos, testPos, minDistance, 100);
pos = testPos;
} else { // Else spawn a little bit off, and above (above for jockeys)
pos[2] += 10.0;
pos[0] += 5.0;
}
pos[2] += 1.0;
NegateVector(ang);
int special = (specialType == 7) ? L4D2_SpawnWitch(pos, ang) : L4D2_SpawnSpecial(specialType, pos, ang);
if(special == -1) return false;
if(specialType == 7)
SetWitchTarget(special, target);
else
g_iAttackerTarget[special] = GetClientUserId(target);
if(specialType == 2) { //Kill boomer
ForcePlayerSuicide(special);
}
return true;
}
bool SpawnSpecialNear(int target, int specialType) {
static float pos[3];
if(L4D_GetRandomPZSpawnPosition(target, specialType, 10, pos)) {
int special = (specialType == 7) ? L4D2_SpawnWitch(pos, ZERO_VECTOR) : L4D2_SpawnSpecial(specialType, pos, ZERO_VECTOR);
if(special == -1) return false;
if(specialType == 7)
SetWitchTarget(special, target);
else
g_iAttackerTarget[special] = GetClientUserId(target);
return true;
}
return false;
}

File diff suppressed because it is too large Load diff

View file

@ -49,6 +49,10 @@ public void OnPluginStart() {
g_PlayerMarkedForward = new GlobalForward("FTT_OnClientMarked", ET_Ignore, Param_Cell, Param_Cell);
REPLACEMENT_PHRASES = new StringMap();
LoadPhrases();
SetupTrolls();
GameData data = new GameData("l4d2_behavior");
StartPrepSDKCall(SDKCall_Raw);
@ -75,6 +79,9 @@ public void OnPluginStart() {
RegAdminCmd("sm_mark", Command_MarkPendingTroll, ADMFLAG_KICK, "Marks a player as to be banned on disconnect");
RegAdminCmd("sm_ftc", Command_FeedTheCrescendoTroll, ADMFLAG_KICK, "Applies a manual punish on the last crescendo activator");
RegAdminCmd("sm_witch_attack", Command_WitchAttack, ADMFLAG_CHEATS, "Makes all witches target a player");
RegAdminCmd("sm_insta", Command_InstaSpecial, ADMFLAG_KICK, "Spawns a special that targets them, close to them.");
RegAdminCmd("sm_instaface", Command_InstaSpecialFace, ADMFLAG_KICK, "Spawns a special that targets them, right in their face.");
RegAdminCmd("sm_inface", Command_InstaSpecialFace, ADMFLAG_KICK, "Spawns a special that targets them, right in their face.");
HookEvent("player_disconnect", Event_PlayerDisconnect);
HookEvent("player_death", Event_PlayerDeath);
@ -103,7 +110,7 @@ public void OnMapEnd() {
}
public void OnMapStart() {
AddFileToDownloadsTable("sound/custom/meow1.mp3");
PrecacheSound("sound/custom/meow1.mp3");
PrecacheSound("custom/meow1.mp3");
lastButtonUser = -1;
HookEntityOutput("func_button", "OnPressed", Event_ButtonPress);
@ -129,7 +136,7 @@ public void Event_PlayerDisconnect(Event event, const char[] name, bool dontBroa
}
}
steamids[client][0] = '\0';
g_iTrollUsers[client] = 0;
ActiveTrolls[client] = 0;
g_iAttackerTarget[client] = 0;
}
public Action Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast) {
@ -138,7 +145,7 @@ public Action Event_PlayerDeath(Event event, const char[] name, bool dontBroadca
}
public Action Event_WeaponReload(int weapon) {
int client = GetEntPropEnt(weapon, Prop_Send, "m_hOwner");
if(HasTrollMode(client,Troll_GunJam)) {
if(IsTrollActive(client, "GunJam")) {
float dec = GetRandomFloat(0.0, 1.0);
if(FloatCompare(dec, 0.50) == -1) { //10% chance gun jams
return Plugin_Stop;
@ -196,7 +203,7 @@ 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 && HasTrollMode(i, Troll_TankMagnet) || (class != L4D2Infected_Tank && HasTrollMode(i, Troll_SpecialMagnet))) {
if(class == L4D2Infected_Tank && IsTrollActive(i, "TankMagnet") || (class != L4D2Infected_Tank && IsTrollActive(i, "SpecialMagnet"))) {
GetClientAbsOrigin(i, survPos);
float dist = GetVectorDistance(survPos, spPos, true);
if(closestClient == -1 || dist < closestDistance) {
@ -215,14 +222,15 @@ public Action L4D2_OnChooseVictim(int attacker, int &curTarget) {
return Plugin_Continue;
}
public Action L4D2_OnEntityShoved(int client, int entity, int weapon, float vecDir[3], bool bIsHighPounce) {
if(client > 0 && client <= MaxClients && HasTrollMode(client, Troll_NoShove) && hShoveFailChance.FloatValue > GetRandomFloat()) {
if(client > 0 && client <= MaxClients && IsTrollActive(client, "NoShove") && hShoveFailChance.FloatValue > GetRandomFloat()) {
return Plugin_Handled;
}
return Plugin_Continue;
}
public Action OnClientSayCommand(int client, const char[] command, const char[] sArgs) {
if(HasTrollMode(client, Troll_Honk)) {
char strings[32][7];
if(sArgs[0] == '@') return Plugin_Continue;
if(IsTrollActive(client, "Honk")) {
static char strings[32][7];
int words = ExplodeString(sArgs, " ", strings, sizeof(strings), 5);
for(int i = 0; i < words; i++) {
if(GetRandomFloat() <= 0.8) strings[i] = "honk";
@ -234,8 +242,8 @@ public Action OnClientSayCommand(int client, const char[] command, const char[]
CPrintToChatAll("{blue}%N {default}: %s", client, message);
PrintToServer("%N: %s", client, sArgs);
return Plugin_Handled;
}else if(HasTrollMode(client, Troll_iCantSpellNoMore)) {
int type = GetRandomInt(1, TROLL_MODE_COUNT + 8);
}else if(IsTrollActive(client, "iCantSpellNoMore")) {
int type = GetRandomInt(1, trollKV.Size + 8);
char letterSrc, replaceChar;
switch(type) {
case 1: {
@ -308,14 +316,40 @@ public Action OnClientSayCommand(int client, const char[] command, const char[]
PrintToServer("%N: %s", client, sArgs);
CPrintToChatAll("{blue}%N {default}: %s", client, newMessage);
return Plugin_Handled;
}else if(IsTrollActive(client, "NoProfanity")) {
//TODO: Check all replacement words, if none were replaced then do full word
//TODO: Lowercase .getstring
static char strings[32][MAX_PHRASE_LENGTH];
ArrayList phrases;
bool foundWord = false;
int words = ExplodeString(sArgs, " ", strings, 32, MAX_PHRASE_LENGTH);
for(int i = 0; i < words; i++) {
if(REPLACEMENT_PHRASES.GetValue(strings[i], phrases) && phrases.Length > 0) {
foundWord = true;
int c = phrases.GetString(GetRandomInt(0, phrases.Length - 1), strings[i], MAX_PHRASE_LENGTH);
PrintToServer("replacement: %s (%d)", strings[i], c);
}
}
int length = MAX_PHRASE_LENGTH * words;
char[] message = new char[length];
if(foundWord) {
ImplodeStrings(strings, 32, " ", message, length);
} else {
REPLACEMENT_PHRASES.GetValue("_Full Message Phrases", phrases);
phrases.GetString(GetRandomInt(0, phrases.Length - 1), message, MAX_PHRASE_LENGTH);
}
CPrintToChatAll("{blue}%N {default}: %s", client, message);
PrintToServer("%N: %s", client, sArgs);
return Plugin_Handled;
}
return Plugin_Continue;
}
public Action Event_ItemPickup(int client, int weapon) {
if(HasTrollMode(client,Troll_NoPickup)) {
if(IsTrollActive(client, "NoPickup")) {
return Plugin_Stop;
}else{
char wpnName[64];
static char wpnName[64];
GetEdictClassname(weapon, wpnName, sizeof(wpnName));
if(StrContains(wpnName, "rifle") > -1
|| StrContains(wpnName, "smg") > -1
@ -324,8 +358,8 @@ public Action Event_ItemPickup(int client, int weapon) {
|| StrContains(wpnName, "shotgun") > -1
) {
//If 4: Only UZI, if 5: Can't switch.
if(HasTrollMode(client,Troll_UziRules)) {
char currentWpn[32];
if(IsTrollActive(client, "UziRules")) {
static char currentWpn[32];
GetClientWeaponName(client, 0, currentWpn, sizeof(currentWpn));
if(StrEqual(wpnName, "weapon_smg", true)) {
return Plugin_Continue;
@ -335,10 +369,10 @@ public Action Event_ItemPickup(int client, int weapon) {
int flags = GetCommandFlags("give");
SetCommandFlags("give", flags & ~FCVAR_CHEAT);
FakeClientCommand(client, "give smg");
SetCommandFlags("give", flags|FCVAR_CHEAT);
SetCommandFlags("give", flags);
return Plugin_Stop;
}
}else if(HasTrollMode(client,Troll_PrimaryDisable)) {
}else if(IsTrollActive(client, "PrimaryDisable")) {
return Plugin_Stop;
}
return Plugin_Continue;
@ -347,6 +381,7 @@ public Action Event_ItemPickup(int client, int weapon) {
}
}
}
public Action OnPlayerRunCmd(int client, int& buttons, int& impulse, float vel[3], float angles[3], int& weapon, int& subtype, int& cmdnum, int& tickcount, int& seed, int mouse[2]) {
if(g_bPendingItemGive[client] && !(buttons & IN_ATTACK2)) {
int target = GetClientAimTarget(client, true);
@ -367,7 +402,7 @@ public Action Event_TakeDamage(int victim, int& attacker, int& inflictor, float&
return Plugin_Stop;
}
if(HasTrollMode(attacker, Troll_DamageBoost)) {
if(IsTrollActive(attacker, "DamageBoost")) {
damage * 2;
return Plugin_Changed;
}
@ -391,12 +426,12 @@ public Action SoundHook(int[] clients, int& numClients, char sample[PLATFORM_MAX
lastButtonUser = -1;
}else if(numClients > 0 && entity > 0 && entity <= MaxClients) {
if(StrContains(sample, "survivor\\voice") > -1) {
if(HasTrollMode(entity, Troll_Honk)) {
if(IsTrollActive(entity, "Honk")) {
strcopy(sample, sizeof(sample), "player/footsteps/clown/concrete1.wav");
return Plugin_Changed;
} else if(HasTrollMode(entity, Troll_VocalizeGag)) {
} else if(IsTrollActive(entity, "VocalizeGag")) {
return Plugin_Handled;
} else if(HasTrollMode(entity, Troll_Meow)) {
} else if(IsTrollActive(entity, "Meow")) {
strcopy(sample, sizeof(sample), "custom/meow1.mp3");
return Plugin_Changed;
}
@ -418,7 +453,7 @@ public Action Event_WitchVictimSet(Event event, const char[] name, bool dontBroa
continue;
}
if(HasTrollMode(i, Troll_WitchMagnet)) {
if(IsTrollActive(i, "WitchMagnet")) {
GetClientAbsOrigin(i, survPos);
float dist = GetVectorDistance(survPos, witchPos, true);
if(closestClient == -1 || dist < closestDistance) {
@ -464,6 +499,121 @@ public void Change_ThrowInterval(ConVar convar, const char[] oldValue, const cha
// COMMANDS
///////////////////////////////////////////////////////////////////////////////
public Action Command_InstaSpecial(int client, int args) {
if(args < 1) {
Menu menu = new Menu(Insta_PlayerHandler);
menu.SetTitle("Choose a player");
for(int i = 1; i < MaxClients; i++) {
if(IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) == 2) {
static char userid[8], display[16];
Format(userid, sizeof(userid), "%d|0", GetClientUserId(i));
GetClientName(i, display, sizeof(display));
menu.AddItem(userid, display);
}
}
menu.ExitButton = true;
menu.Display(client, 0);
} else {
char arg1[32], arg2[32] = "jockey";
GetCmdArg(1, arg1, sizeof(arg1));
if(args >= 2) {
GetCmdArg(2, arg2, sizeof(arg2));
}
char target_name[MAX_TARGET_LENGTH];
int target_list[MAXPLAYERS], target_count;
bool tn_is_ml;
if ((target_count = ProcessTargetString(
arg1,
client,
target_list,
MaxClients,
COMMAND_FILTER_ALIVE,
target_name,
sizeof(target_name),
tn_is_ml)) <= 0
) {
/* This function replies to the admin with a failure message */
ReplyToTargetError(client, target_count);
return Plugin_Handled;
}
int specialType = GetSpecialType(arg2);
static float pos[3];
if(specialType == -1) {
ReplyToCommand(client, "Unknown special \"%s\"", arg2);
return Plugin_Handled;
}
for (int i = 0; i < target_count; i++) {
int target = target_list[i];
if(GetClientTeam(target) == 2) {
SpawnSpecialNear(target, specialType);
}else{
ReplyToTargetError(client, target_count);
}
}
ShowActivity(client, "spawned Insta-%s™ near %s", arg2, target_name);
}
return Plugin_Handled;
}
public Action Command_InstaSpecialFace(int client, int args) {
if(args < 1) {
Menu menu = new Menu(Insta_PlayerHandler);
menu.SetTitle("Choose a player");
for(int i = 1; i < MaxClients; i++) {
if(IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) == 2) {
static char userid[8], display[16];
Format(userid, sizeof(userid), "%d|1", GetClientUserId(i));
GetClientName(i, display, sizeof(display));
menu.AddItem(userid, display);
}
}
menu.ExitButton = true;
menu.Display(client, 0);
} else {
char arg1[32], arg2[32] = "jockey";
GetCmdArg(1, arg1, sizeof(arg1));
if(args >= 2) {
GetCmdArg(2, arg2, sizeof(arg2));
}
char target_name[MAX_TARGET_LENGTH];
int target_list[MAXPLAYERS], target_count;
bool tn_is_ml;
if ((target_count = ProcessTargetString(
arg1,
client,
target_list,
MaxClients,
COMMAND_FILTER_ALIVE,
target_name,
sizeof(target_name),
tn_is_ml)) <= 0
) {
/* This function replies to the admin with a failure message */
ReplyToTargetError(client, target_count);
return Plugin_Handled;
}
int specialType = GetSpecialType(arg2);
static float pos[3];
if(specialType == -1) {
ReplyToCommand(client, "Unknown special \"%s\"", arg2);
return Plugin_Handled;
}
for (int i = 0; i < target_count; i++) {
int target = target_list[i];
if(GetClientTeam(target) == 2) {
SpawnSpecialInFace(target, specialType);
}else{
ReplyToTargetError(client, target_count);
}
}
ShowActivity(client, "spawned Insta-%s™ on %s", arg2, target_name);
}
return Plugin_Handled;
}
public Action Command_WitchAttack(int client, int args) {
if(args < 1) {
ReplyToCommand(client, "Usage: sm_witch_attack <user>");
@ -540,7 +690,7 @@ public Action Command_ResetUser(int client, int args) {
}
for (int i = 0; i < target_count; i++) {
if(g_iTrollUsers[target_list[i]] > 0) {
if(ActiveTrolls[target_list[i]] > 0) {
ResetClient(target_list[i], true);
ShowActivity(client, "reset troll effects on \"%N\". ", target_list[i]);
}
@ -548,13 +698,14 @@ public Action Command_ResetUser(int client, int args) {
}
return Plugin_Handled;
}
public Action Command_ApplyUser(int client, int args) {
if(args < 2) {
Menu menu = new Menu(ChoosePlayerHandler);
menu.SetTitle("Choose a player");
for(int i = 1; i < MaxClients; i++) {
if(IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) == 2) {
char userid[8], display[16];
static char userid[8], display[16];
Format(userid, sizeof(userid), "%d", GetClientUserId(i));
GetClientName(i, display, sizeof(display));
menu.AddItem(userid, display);
@ -569,10 +720,9 @@ public Action Command_ApplyUser(int client, int args) {
GetCmdArg(3, arg3, sizeof(arg3));
bool silent = StrEqual(arg3, "silent") || StrEqual(arg3, "quiet") || StrEqual(arg3, "mute");
int mode = StringToInt(arg2);
if(mode == 0) {
ReplyToCommand(client, "Not a valid mode. Must be greater than 0. Usage: sm_fta <player> <mode>. Use sm_ftr <player> to reset.");
static char name[MAX_TROLL_NAME_LENGTH];
if(!GetTrollID(StringToInt(arg2), name)) {
ReplyToCommand(client, "Not a valid mode. Must be greater than 0. Usage: sm_fta [player] [mode]. Use sm_ftr <player> to reset.");
}else{
char target_name[MAX_TARGET_LENGTH];
int target_list[MAXPLAYERS], target_count;
@ -594,32 +744,40 @@ public Action Command_ApplyUser(int client, int args) {
for (int i = 0; i < target_count; i++) {
if(IsClientInGame(target_list[i]) && GetClientTeam(target_list[i]) == 2)
ApplyModeToClient(client, target_list[i], view_as<trollMode>(mode), TrollMod_None, silent);
ApplyTroll(target_list[i], name, client,TrollMod_None, silent);
}
}
}
return Plugin_Handled;
}
public Action Command_ListModes(int client, int args) {
for(int mode = 0; mode < TROLL_MODE_COUNT; mode++) {
ReplyToCommand(client, "%d. %s - %s", mode, TROLL_MODES_NAMES[mode], TROLL_MODES_DESCRIPTIONS[mode]);
static char name[MAX_TROLL_NAME_LENGTH];
static Troll troll;
for(int i = 0; i <= MAX_TROLLS; i++) {
GetTrollByKeyIndex(i, troll);
ReplyToCommand(client, "%d. %s - %s", i, troll.name, troll.description);
}
return Plugin_Handled;
}
public Action Command_ListTheTrolls(int client, int args) {
int count = 0;
char modeListArr[TROLL_MODE_COUNT][32];
char modeList[255];
//TODO: Update
char[][] modeListArr = new char[MAX_TROLLS+1][MAX_TROLL_NAME_LENGTH];
static char modeList[255];
for(int i = 1; i < MaxClients; i++) {
if(IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i) && g_iTrollUsers[i] > 0) {
if(IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i) && ActiveTrolls[i] > 0) {
int modeCount = 0;
for(int mode = 1; mode < TROLL_MODE_COUNT; mode++) {
//If troll mode exists:
if(HasTrollMode(i, view_as<trollMode>(mode))) {
modeListArr[modeCount] = TROLL_MODES_NAMES[mode];
static char name[MAX_TROLL_NAME_LENGTH];
for(int j = 1; j <= MAX_TROLLS; j++) {
GetTrollID(j, name);
if(IsTrollActive(i, name)) {
strcopy(modeListArr[modeCount], MAX_TROLL_NAME_LENGTH, name);
modeCount++;
}
}
ImplodeStrings(modeListArr, modeCount, ", ", modeList, sizeof(modeList));
ReplyToCommand(client, "%N | %s", i, modeList);
count++;
@ -635,7 +793,7 @@ public Action Command_MarkPendingTroll(int client, int args) {
if(args == 0) {
Menu menu = new Menu(ChooseMarkedTroll);
menu.SetTitle("Choose a troll to mark");
char userid[8], display[16];
static char userid[8], display[16];
for(int i = 1; i < MaxClients; i++) {
if(IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) == 2) {
AdminId admin = GetUserAdmin(i);
@ -690,13 +848,61 @@ public Action Command_FeedTheTrollMenu(int client, int args) {
ReplyToCommand(client, "sm_mark - Marks the user to be banned on disconnect, prevents their FF.");
return Plugin_Handled;
}
///////////////////////////////////////////////////////////////////////////////
// MENU HANDLER
///////////////////////////////////////////////////////////////////////////////
public int Insta_PlayerHandler(Menu menu, MenuAction action, int client, int param2) {
/* If an option was selected, tell the client about the item. */
if (action == MenuAction_Select) {
static char info[16];
menu.GetItem(param2, info, sizeof(info));
static char str[2][8];
ExplodeString(info, "|", str, 2, 8, false);
int userid = StringToInt(str[0]);
int instaMode = StringToInt(str[1]);
Menu spMenu = new Menu(Insta_SpecialHandler);
spMenu.SetTitle("Choose a Insta-Special™");
for(int i = 1; i <= 6; i++) {
static char id[8];
Format(id, sizeof(id), "%d|%d|%d", userid, instaMode, i);
spMenu.AddItem(id, SPECIAL_NAMES[i-1]);
}
spMenu.ExitButton = true;
spMenu.Display(client, 0);
} else if (action == MenuAction_End)
delete menu;
}
public int Insta_SpecialHandler(Menu menu, MenuAction action, int client, int param2) {
/* If an option was selected, tell the client about the item. */
if (action == MenuAction_Select) {
static char info[16];
menu.GetItem(param2, info, sizeof(info));
static char str[3][8];
ExplodeString(info, "|", str, 3, 8, false);
int target = GetClientOfUserId(StringToInt(str[0]));
bool inFace = StrEqual(str[1], "1");
int special = StringToInt(str[2]);
if(inFace) {
SpawnSpecialInFace(target, special);
ShowActivity(client, "spawned Insta-%s™ near %N", SPECIAL_NAMES[special-1], target);
} else {
SpawnSpecialNear(target, special);
ShowActivity(client, "spawned Insta-%s™ near %N", SPECIAL_NAMES[special-1], target);
}
} else if (action == MenuAction_End)
delete menu;
}
public int ChooseMarkedTroll(Menu menu, MenuAction action, int activator, int param2) {
if (action == MenuAction_Select) {
char info[16];
static char info[16];
menu.GetItem(param2, info, sizeof(info));
int target = GetClientOfUserId(StringToInt(info));
ToggleMarkPlayer(activator, target);
@ -707,69 +913,79 @@ public int ChooseMarkedTroll(Menu menu, MenuAction action, int activator, int pa
public int ChoosePlayerHandler(Menu menu, MenuAction action, int param1, int param2) {
/* If an option was selected, tell the client about the item. */
if (action == MenuAction_Select) {
char info[16];
static char info[16];
menu.GetItem(param2, info, sizeof(info));
int userid = StringToInt(info);
Menu trollMenu = new Menu(ChooseModeMenuHandler);
trollMenu.SetTitle("Choose a troll mode");
for(int i = 0; i < TROLL_MODE_COUNT; i++) {
char id[8];
//TODO: Update
static char id[8];
static char name[MAX_TROLL_NAME_LENGTH];
for(int i = 0; i <= MAX_TROLLS; i++) {
GetTrollID(i, name);
// int trollIndex = GetTrollByKeyIndex(i, troll);
// Pass key index
Format(id, sizeof(id), "%d|%d", userid, i);
trollMenu.AddItem(id, TROLL_MODES_NAMES[i]);
trollMenu.AddItem(id, name);
}
trollMenu.ExitButton = true;
trollMenu.Display(param1, 0);
} else if (action == MenuAction_End)
delete menu;
}
public int ChooseModeMenuHandler(Menu menu, MenuAction action, int param1, int param2) {
/* If an option was selected, tell the client about the item. */
if (action == MenuAction_Select) {
char info[16];
static char info[16];
menu.GetItem(param2, info, sizeof(info));
char str[2][8];
static char str[2][8];
ExplodeString(info, "|", str, 2, 8, false);
int userid = StringToInt(str[0]);
int client = GetClientOfUserId(userid);
trollMode mode = view_as<trollMode>(StringToInt(str[1]));
int keyIndex = StringToInt(str[1]);
static Troll troll;
static char trollID[MAX_TROLL_NAME_LENGTH];
GetTrollByKeyIndex(keyIndex, troll);
troll.GetID(trollID, MAX_TROLL_NAME_LENGTH);
//If mode has an option to be single-time fired/continous/both, prompt:
if(mode == Troll_Clumsy
|| mode ==Troll_ThrowItAll
|| mode == Troll_PrimaryDisable
|| mode == Troll_CameTooEarly
|| mode == Troll_Swarm
) {
if(!troll.runsOnce) {
Menu modiferMenu = new Menu(ChooseTrollModiferHandler);
modiferMenu.SetTitle("Choose Troll Modifer Option");
char singleUse[16], multiUse[16], bothUse[16];
Format(singleUse, sizeof(singleUse), "%d|%d|1", userid, mode);
Format(multiUse, sizeof(multiUse), "%d|%d|2", userid, mode);
Format(bothUse, sizeof(bothUse), "%d|%d|3", userid, mode);
static char singleUse[16], multiUse[16], bothUse[16];
Format(singleUse, sizeof(singleUse), "%d|%d|1", userid, keyIndex);
Format(multiUse, sizeof(multiUse), "%d|%d|2", userid, keyIndex);
Format(bothUse, sizeof(bothUse), "%d|%d|3", userid, keyIndex);
modiferMenu.AddItem(singleUse, "Activate once");
modiferMenu.AddItem(multiUse, "Activate Periodically");
modiferMenu.AddItem(bothUse, "Activate Periodically & Instantly");
modiferMenu.ExitButton = true;
modiferMenu.Display(param1, 0);
} else {
ApplyModeToClient(param1, client, mode, TrollMod_None);
ApplyTroll(client, trollID, param1, TrollMod_None);
}
} else if (action == MenuAction_End)
delete menu;
}
public int ChooseTrollModiferHandler(Menu menu, MenuAction action, int param1, int param2) {
if (action == MenuAction_Select) {
char info[16];
static char info[16];
menu.GetItem(param2, info, sizeof(info));
char str[3][8];
static char str[3][8];
ExplodeString(info, "|", str, 3, 8, false);
int client = GetClientOfUserId(StringToInt(str[0]));
trollMode mode = view_as<trollMode>(StringToInt(str[1]));
int keyIndex = StringToInt(str[1]);
static Troll troll;
static char trollID[MAX_TROLL_NAME_LENGTH];
GetTrollByKeyIndex(keyIndex, troll);
troll.GetID(trollID, MAX_TROLL_NAME_LENGTH);
int modifier = StringToInt(str[2]);
if(modifier == 2 || modifier == 3)
ApplyModeToClient(param1, client, mode, TrollMod_Repeat);
ApplyTroll(client, trollID, param1, TrollMod_Repeat);
else
ApplyModeToClient(param1, client, mode, TrollMod_InstantFire);
ApplyTroll(client, trollID, param1, TrollMod_InstantFire);
} else if (action == MenuAction_End)
delete menu;
}
@ -777,6 +993,7 @@ public int ChooseTrollModiferHandler(Menu menu, MenuAction action, int param1, i
public void StopItemGive(int client) {
g_bPendingItemGive[client] = false;
}
///////////////////////////////////////////////////////////////////////////////
// TIMERS
///////////////////////////////////////////////////////////////////////////////
@ -784,25 +1001,26 @@ public void StopItemGive(int client) {
public Action Timer_ThrowTimer(Handle timer) {
int count = 0;
for(int i = 1; i < MaxClients; i++) {
if(IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i) &&HasTrollMode(i,Troll_ThrowItAll)) {
if(IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i) && IsTrollActive(i, "ThrowItAll")) {
ThrowAllItems(i);
count++;
}
}
return count > 0 ? Plugin_Continue : Plugin_Stop;
}
public Action Timer_Main(Handle timer) {
static int loop;
for(int i = 1; i <= MaxClients; i++) {
if(IsClientConnected(i) && IsClientInGame(i) && IsPlayerAlive(i)) {
if(HasTrollMode(i, Troll_SlowDrain)) {
if(IsTrollActive(i, "SlowDrain")) {
if(loop % 4 == 0) {
int hp = GetClientHealth(i);
if(hp > 50) {
SetEntProp(i, Prop_Send, "m_iHealth", hp - 1);
}
}
}else if(HasTrollMode(i, Troll_TempHealthQuickDrain)) {
}else if(IsTrollActive(i, "TempHealthQuickDrain")) {
if(loop % 2 == 0) {
float bufferTime = GetEntPropFloat(i, Prop_Send, "m_healthBufferTime");
float buffer = GetEntPropFloat(i, Prop_Send, "m_healthBuffer");
@ -813,7 +1031,7 @@ public Action Timer_Main(Handle timer) {
SetEntPropFloat(i, Prop_Send, "m_healthBufferTime", bufferTime - 7.0);
}
}
}else if(HasTrollMode(i, Troll_Swarm)) {
}else if(IsTrollActive(i, "Swarm")) {
L4D2_RunScript("RushVictim(GetPlayerFromUserID(%d), %d)", GetClientUserId(i), 15000);
}
}
@ -845,7 +1063,7 @@ public Action Timer_ThrowWeapon(Handle timer, Handle pack) {
int wpn = EntRefToEntIndex(wpnRef);
if(wpn != INVALID_ENT_REFERENCE) {
if(slot == 1) {
char name[16];
static char name[16];
GetEdictClassname(wpn, name, sizeof(name));
if(!StrEqual(name, "weapon_pistol", false)) {
SDKHooks_DropWeapon(victim, wpn, dest);
@ -861,9 +1079,9 @@ public Action Timer_ResetAutoPunish(Handle timer, int user) {
int client = GetClientOfUserId(user);
if(client) {
if(hAutoPunish.IntValue & 2 == 2)
TurnOffTrollMode(client, Troll_SpecialMagnet);
DisableTroll(client, "SpecialMagnet");
if(hAutoPunish.IntValue & 1 == 1)
TurnOffTrollMode(client, Troll_TankMagnet);
DisableTroll(client, "TankMagnet");
}
}
@ -901,6 +1119,7 @@ void ThrowAllItems(int victim) {
}
}
bool IsPlayerFarDistance(int client, float distance) {
int farthestClient = -1, secondClient = -1;
float highestFlow, secondHighestFlow;
@ -965,16 +1184,14 @@ stock bool SetPrimaryReserveAmmo(int client, int amount) {
stock void SendChatToAll(int client, const char[] message) {
char nameBuf[MAX_NAME_LENGTH];
for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i) || IsFakeClient(i))
{
continue;
}
for (int i = 1; i <= MaxClients; i++) {
if (IsClientInGame(i) && IsFakeClient(i)) {
FormatActivitySource(client, i, nameBuf, sizeof(nameBuf));
PrintToChat(i, "\x03 %s : \x01%s", nameBuf, message);
}
}
}
stock float GetTempHealth(int client) {
//First filter -> Must be a valid client, successfully in-game and not an spectator (The dont have health).
if(!client || !IsValidEntity(client) || !IsClientInGame(client)|| !IsPlayerAlive(client) || IsClientObserver(client)) {
@ -990,7 +1207,9 @@ stock float GetTempHealth(int client) {
float buffer = GetEntPropFloat(client, Prop_Send, "m_healthBuffer");
//In case the buffer is 0 or less, we set the temporal health as 0, because the client has not used any pills or adrenaline yet
if(buffer > 0.0) {
if(buffer <= 0.0) return 0.0;
//This is the difference between the time we used the temporal item, and the current time
float difference = GetGameTime() - GetEntPropFloat(client, Prop_Send, "m_healthBufferTime");
@ -1003,7 +1222,4 @@ stock float GetTempHealth(int client) {
//Then we do the calcs
return buffer - (difference / constant);
}else{
return 0.0;
}
}