mirror of
https://github.com/Jackzmc/sourcemod-plugins.git
synced 2025-05-06 22:23:21 +00:00
ftt: Use activeFlagClients instead of global ActiveTrolls var
This commit is contained in:
parent
da41fdf7a0
commit
549ec36ba6
5 changed files with 71 additions and 52 deletions
|
@ -24,8 +24,6 @@ enum trollFlag {
|
|||
Flag_8 = 1 << 7,
|
||||
}
|
||||
|
||||
int ActiveTrolls[MAXPLAYERS+1];
|
||||
|
||||
StringMap trollKV;
|
||||
char trollIds[MAX_TROLLS+1][MAX_TROLL_NAME_LENGTH];
|
||||
|
||||
|
@ -81,10 +79,7 @@ enum struct Troll {
|
|||
}
|
||||
|
||||
bool IsFlagActive(int client, trollFlag flag) {
|
||||
if(ActiveTrolls[client] > 0 && IsTrollActive(client, this.name) && this.activeFlagClients[client] >= 0) {
|
||||
return this.activeFlagClients[client] & view_as<int>(flag) != 0;
|
||||
}
|
||||
return false;
|
||||
return this.activeFlagClients[client] & view_as<int>(flag) != 0;
|
||||
}
|
||||
|
||||
bool IsFlagNameActive(int client, const char[] flagName) {
|
||||
|
@ -120,7 +115,7 @@ enum struct Troll {
|
|||
}
|
||||
|
||||
bool IsActive(int client) {
|
||||
return IsTrollActive(client, this.name);
|
||||
return this.activeFlagClients[client] != -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,8 +125,11 @@ ArrayList categories;
|
|||
static int categoryID = -1;
|
||||
|
||||
void ResetClient(int victim, bool wipe = true) {
|
||||
if(wipe) //TODO: Remove legacy system, including this:
|
||||
ActiveTrolls[victim] = 0;
|
||||
if(wipe) {
|
||||
for(int i = 0; i < MAX_TROLLS; i++) {
|
||||
Trolls[i].activeFlagClients[victim] = -1;
|
||||
}
|
||||
}
|
||||
SetEntityGravity(victim, 1.0);
|
||||
SetEntPropFloat(victim, Prop_Send, "m_flLaggedMovementValue", 1.0);
|
||||
SDKUnhook(victim, SDKHook_WeaponCanUse, Event_ItemPickup);
|
||||
|
@ -168,13 +166,20 @@ int GetTroll(const char[] name, Troll troll) {
|
|||
}
|
||||
return -1;
|
||||
}
|
||||
int GetTrollIndex(const char[] name) {
|
||||
int GetTrollID(const char[] name) {
|
||||
static int i = 0;
|
||||
if(trollKV.GetValue(name, i)) {
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool IsAnyTrollActive(int victim) {
|
||||
for(int i = 0; i < MAX_TROLLS; i++) {
|
||||
if(Trolls[i].activeFlagClients[victim] >= 0) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// Gets the Troll enum struct via key index
|
||||
// Returns index of troll enum
|
||||
int GetTrollByKeyIndex(int index, Troll troll) {
|
||||
|
@ -186,9 +191,11 @@ int GetTrollByKeyIndex(int index, Troll troll) {
|
|||
|
||||
void ToggleTroll(int client, const char[] name, int flags = 0) {
|
||||
static Troll troll;
|
||||
int index = GetTroll(name, troll);
|
||||
ActiveTrolls[client] ^= 1 << view_as<int>(index);
|
||||
troll.activeFlagClients[client] = flags;
|
||||
GetTroll(name, troll);
|
||||
if(troll.IsActive(client))
|
||||
troll.activeFlagClients[client] = -1;
|
||||
else
|
||||
troll.activeFlagClients[client] = flags;
|
||||
}
|
||||
void ApplyTroll(int victim, const char[] name, int activator, trollModifier modifier, bool silent = false, int flags = 0) {
|
||||
static Troll troll;
|
||||
|
@ -225,9 +232,8 @@ void ApplyTroll(int victim, const char[] name, int activator, trollModifier modi
|
|||
}
|
||||
}
|
||||
if(modifier == TrollMod_Constant) {
|
||||
ActiveTrolls[victim] ^= 1 << trollIndex;
|
||||
Trolls[troll.id].activeFlagClients[victim] = flags;
|
||||
}
|
||||
Trolls[troll.id].activeFlagClients[victim] = flags;
|
||||
}
|
||||
|
||||
bool ApplyAffect(int victim, const Troll troll, int activator, trollModifier modifier, int flags) {
|
||||
|
@ -235,8 +241,7 @@ bool ApplyAffect(int victim, const Troll troll, int activator, trollModifier mod
|
|||
if(StrEqual(troll.name, "Reset User")) {
|
||||
LogAction(activator, victim, "\"%L\" reset all troll effects for \"%L\"", activator, victim);
|
||||
ShowActivityEx(activator, "[FTT] ", "reset troll effects for %N. ", victim);
|
||||
ActiveTrolls[victim] = 0;
|
||||
troll.activeFlagClients[victim] = 0;
|
||||
troll.activeFlagClients[victim] = -1;
|
||||
SetEntPropFloat(victim, Prop_Send, "m_flLaggedMovementValue", 1.0);
|
||||
SetEntityGravity(victim, 1.0);
|
||||
return false;
|
||||
|
@ -323,18 +328,20 @@ bool ApplyAffect(int victim, const Troll troll, int activator, trollModifier mod
|
|||
}
|
||||
|
||||
bool IsTrollActive(int client, const char[] troll) {
|
||||
if(ActiveTrolls[client] == 0) return false;
|
||||
if(troll[0] == '\0') {
|
||||
ThrowError("Troll name is empty");
|
||||
return false;
|
||||
}
|
||||
static int i = 0;
|
||||
if(trollKV.GetValue(troll, i)) {
|
||||
return ((ActiveTrolls[client] >> i) & 1) == 1;
|
||||
return Trolls[i].activeFlagClients[client] != -1;
|
||||
}
|
||||
ThrowError("Troll \"%s\" does not exist", troll);
|
||||
return false; //errors instead but compiler no like
|
||||
}
|
||||
|
||||
bool IsTrollActiveByRawID(int client, int id) {
|
||||
if(ActiveTrolls[client] == 0) return false;
|
||||
return ((ActiveTrolls[client] >> id) & 1) == 1;
|
||||
return Trolls[id].activeFlagClients[client] != -1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -205,11 +205,9 @@ public Action Command_ResetUser(int client, int args) {
|
|||
}
|
||||
|
||||
for (int i = 0; i < target_count; i++) {
|
||||
if(ActiveTrolls[target_list[i]] > 0) {
|
||||
ResetClient(target_list[i], true);
|
||||
LogAction(client, target_list[i], "\"%L\" reset all troll effects for \"%L\"", client, target_list[i]);
|
||||
ShowActivityEx(client, "[FTT] ", "reset troll effects for \"%N\". ", target_list[i]);
|
||||
}
|
||||
ResetClient(target_list[i], true);
|
||||
LogAction(client, target_list[i], "\"%L\" reset all troll effects for \"%L\"", client, target_list[i]);
|
||||
ShowActivityEx(client, "[FTT] ", "reset troll effects for \"%N\". ", target_list[i]);
|
||||
}
|
||||
}
|
||||
return Plugin_Handled;
|
||||
|
@ -328,7 +326,7 @@ public Action Command_ListTheTrolls(int client, int args) {
|
|||
static char modeList[255];
|
||||
static char name[MAX_TROLL_NAME_LENGTH];
|
||||
for(int i = 1; i <= MaxClients; i++) {
|
||||
if(IsClientConnected(i) && IsClientInGame(i) && GetClientTeam(i) > 1 && ActiveTrolls[i] > 0) {
|
||||
if(IsClientConnected(i) && IsClientInGame(i) && GetClientTeam(i) > 1 && IsAnyTrollActive(i)) {
|
||||
if(IsFakeClient(i)) {
|
||||
int player = GetRealClient(i);
|
||||
if(player != -1) i = player;
|
||||
|
|
|
@ -34,7 +34,7 @@ public void Event_PlayerDisconnect(Event event, const char[] name, bool dontBroa
|
|||
g_PendingBanTroll[client] = 0;
|
||||
}
|
||||
steamids[client][0] = '\0';
|
||||
ActiveTrolls[client] = 0;
|
||||
ResetClient(client, true);
|
||||
g_iAttackerTarget[client] = 0;
|
||||
}
|
||||
public Action Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast) {
|
||||
|
@ -78,10 +78,9 @@ public Action L4D2_OnChooseVictim(int attacker, int &curTarget) {
|
|||
// =========================
|
||||
// OVERRIDE VICTIM
|
||||
// =========================
|
||||
static Troll spMagnet;
|
||||
static Troll tankMagnet;
|
||||
if(!spMagnet.id) GetTroll("Special Magnet", spMagnet);
|
||||
if(!tankMagnet.id) GetTroll("Tank Magnet", tankMagnet);
|
||||
static int spMagnetID, tankMagnetID;
|
||||
if(spMagnetID == 0) spMagnetID = GetTrollID("Special Magnet");
|
||||
if(tankMagnetID == 0) tankMagnetID = GetTrollID("Tank Magnet");
|
||||
|
||||
if(hMagnetChance.FloatValue < GetRandomFloat()) return Plugin_Continue;
|
||||
L4D2Infected class = view_as<L4D2Infected>(GetEntProp(attacker, Prop_Send, "m_zombieClass"));
|
||||
|
@ -106,10 +105,10 @@ 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 && tankMagnet.IsActive(i) || (class != L4D2Infected_Tank && spMagnet.IsActive(i))) {
|
||||
if(class == L4D2Infected_Tank && Trolls[tankMagnetID].IsActive(i) || (class != L4D2Infected_Tank && Trolls[spMagnetID].IsActive(i))) {
|
||||
if(class == L4D2Infected_Tank) {
|
||||
if(!WillMagnetRun(tankMagnet, i)) return Plugin_Continue;
|
||||
} else if(!WillMagnetRun(spMagnet, i)) return Plugin_Continue;
|
||||
if(!WillMagnetRun(Trolls[tankMagnetID], i)) return Plugin_Continue;
|
||||
} else if(!WillMagnetRun(Trolls[spMagnetID], i)) return Plugin_Continue;
|
||||
|
||||
GetClientAbsOrigin(i, survPos);
|
||||
float dist = GetVectorDistance(survPos, spPos, true);
|
||||
|
@ -147,9 +146,9 @@ public Action L4D2_OnEntityShoved(int client, int entity, int weapon, float vecD
|
|||
}
|
||||
public Action OnClientSayCommand(int client, const char[] command, const char[] sArgs) {
|
||||
if(sArgs[0] == '@') return Plugin_Continue;
|
||||
static Troll honkTroll;
|
||||
if(!honkTroll.id) GetTroll("Honk / Meow", honkTroll);
|
||||
if(honkTroll.IsActive(client) && honkTroll.activeFlagClients[client] & 1) {
|
||||
static int honkID;
|
||||
if(honkID == 0) honkID = GetTrollID("Honk / Meow");
|
||||
if(Trolls[honkID].IsActive(client) && Trolls[honkID].activeFlagClients[client] & 1) {
|
||||
static char strings[32][7];
|
||||
int words = ExplodeString(sArgs, " ", strings, sizeof(strings), 5);
|
||||
for(int i = 0; i < words; i++) {
|
||||
|
@ -162,6 +161,17 @@ 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(IsTrollActive(client, "Reversed")) {
|
||||
int length = strlen(sArgs);
|
||||
char[] message = new char[length+1];
|
||||
int j = 0;
|
||||
for(int i = length - 1; i >= 0; i--) {
|
||||
message[j++] = sArgs[i];
|
||||
}
|
||||
message[j] = '\0';
|
||||
CPrintToChatAll("{blue}%N {default}: %s", client, message);
|
||||
PrintToServer("%N: %s", client, sArgs);
|
||||
return Plugin_Handled;
|
||||
}else if(IsTrollActive(client, "iCantSpellNoMore")) {
|
||||
int type = GetRandomInt(1, 13 + 5);
|
||||
char letterSrc, replaceChar;
|
||||
|
@ -320,7 +330,7 @@ public Action OnPlayerRunCmd(int client, int& buttons, int& impulse, float vel[3
|
|||
}
|
||||
static int invertedTrollIndex;
|
||||
if(invertedTrollIndex <= 0) {
|
||||
invertedTrollIndex = GetTrollIndex("Inverted Controls");
|
||||
invertedTrollIndex = GetTrollID("Inverted Controls");
|
||||
}
|
||||
if(IsTrollActiveByRawID(client, invertedTrollIndex)) {
|
||||
if(buttons & IN_MOVELEFT || buttons & IN_MOVERIGHT) {
|
||||
|
@ -381,13 +391,16 @@ 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) {
|
||||
static Troll honkTroll;
|
||||
if(!honkTroll.id) GetTroll("Honk / Meow", honkTroll);
|
||||
if(honkTroll.IsActive(entity)) {
|
||||
if(honkTroll.activeFlagClients[entity] & 1)
|
||||
static int honkID;
|
||||
if(honkID == 0) {
|
||||
honkID = GetTrollID("Honk / Meow");
|
||||
}
|
||||
if(Trolls[honkID].IsActive(entity)) {
|
||||
if(Trolls[honkID].activeFlagClients[entity] & 1)
|
||||
strcopy(sample, sizeof(sample), "player/footsteps/clown/concrete1.wav");
|
||||
else
|
||||
else if(Trolls[honkID].activeFlagClients[entity] & 2)
|
||||
strcopy(sample, sizeof(sample), "custom/meow1.mp3");
|
||||
else return Plugin_Continue;
|
||||
return Plugin_Changed;
|
||||
} else if(IsTrollActive(entity, "Vocalize Gag")) {
|
||||
return Plugin_Handled;
|
||||
|
@ -441,18 +454,18 @@ void EntityCreateCallback(int entity) {
|
|||
if(!HasEntProp(entity, Prop_Send, "m_hOwnerEntity") || !IsValidEntity(entity)) return;
|
||||
static char class[16];
|
||||
|
||||
static Troll badThrow;
|
||||
if(!badThrow.id) {
|
||||
GetTroll("Bad Throw", badThrow);
|
||||
static int badThrowID;
|
||||
if(badThrowID == 0) {
|
||||
badThrowID = GetTrollID("Bad Throw");
|
||||
}
|
||||
|
||||
GetEntityClassname(entity, class, sizeof(class));
|
||||
int entOwner = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity");
|
||||
if(entOwner > 0 && entOwner <= MaxClients) {
|
||||
if(badThrow.IsActive(entOwner)) {
|
||||
if(Trolls[badThrowID].IsActive(entOwner)) {
|
||||
static float pos[3];
|
||||
GetClientEyePosition(entOwner, pos);
|
||||
if(badThrow.IsFlagActive(entOwner, Flag_1) && StrContains(class, "vomitjar", true) > -1) {
|
||||
if(Trolls[badThrowID].IsFlagActive(entOwner, Flag_1) && StrContains(class, "vomitjar", true) > -1) {
|
||||
AcceptEntityInput(entity, "Kill");
|
||||
if(hBadThrowHitSelf.FloatValue > 0.0 && GetRandomFloat() <= hBadThrowHitSelf.FloatValue) {
|
||||
L4D_CTerrorPlayer_OnVomitedUpon(entOwner, entOwner);
|
||||
|
@ -460,7 +473,7 @@ void EntityCreateCallback(int entity) {
|
|||
FindClosestClient(entOwner, false, pos);
|
||||
}
|
||||
SpawnItem("vomitjar", pos);
|
||||
} else if(badThrow.IsFlagActive(entOwner, Flag_2) && StrContains(class, "molotov", true) > -1) {
|
||||
} else if(Trolls[badThrowID].IsFlagActive(entOwner, Flag_2) && StrContains(class, "molotov", true) > -1) {
|
||||
// Burn them if no one near :)
|
||||
if(hBadThrowHitSelf.FloatValue > 0.0 && GetRandomFloat() <= hBadThrowHitSelf.FloatValue) {
|
||||
GetClientAbsOrigin(entOwner, pos);
|
||||
|
@ -474,7 +487,7 @@ void EntityCreateCallback(int entity) {
|
|||
SpawnItem("molotov", pos);
|
||||
AcceptEntityInput(entity, "Kill");
|
||||
}
|
||||
} else if(badThrow.IsFlagActive(entOwner, Flag_3) && StrContains(class, "pipe_bomb", true) > -1) {
|
||||
} else if(Trolls[badThrowID].IsFlagActive(entOwner, Flag_3) && StrContains(class, "pipe_bomb", true) > -1) {
|
||||
if(hBadThrowHitSelf.FloatValue > 0.0 && GetRandomFloat() <= hBadThrowHitSelf.FloatValue)
|
||||
TeleportEntity(entity, pos, NULL_VECTOR, NULL_VECTOR);
|
||||
SpawnItem("pipe_bomb", pos);
|
||||
|
|
|
@ -36,9 +36,10 @@ void SetupTrolls() {
|
|||
SetupTroll("iCantSpellNoMore", "Chat messages letter will randomly changed with wrong letters", TrollMod_Constant);
|
||||
SetupTroll("No Profanity", "Replaces some words with random phrases", TrollMod_Constant);
|
||||
SetupTroll("Vocalize Gag", "Prevents player from sending any vocalizations (even automatic)", TrollMod_Constant);
|
||||
index = SetupTroll("Honk / Meow", "Honk", TrollMod_Constant, false);
|
||||
index = SetupTroll("Honk / Meow", "Honk or Meow", TrollMod_Constant, false);
|
||||
Trolls[index].AddFlag("Honk", true);
|
||||
Trolls[index].AddFlag("Meow", false);
|
||||
SetupTroll("Reversed", "Reserves their message", TrollMod_Constant);
|
||||
|
||||
SetCategory("Health");
|
||||
SetupTroll("Damage Boost", "Makes a player take more damage than normal", TrollMod_Constant);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue