Add new native to apply troll

This commit is contained in:
Jackz 2022-11-22 09:08:22 -06:00
parent 460a7ee62c
commit 8d70b55217
No known key found for this signature in database
GPG key ID: E0BBD94CF657F603
5 changed files with 59 additions and 3 deletions

Binary file not shown.

View file

@ -0,0 +1,18 @@
#if defined _ftt_included_
#endinput
#endif
#define _ftt_included_
enum TrollModifier {
TrollMod_Invalid = 0,
TrollMod_Instant = 1 << 0,
TrollMod_Constant = 1 << 1,
TrollMod_PlayerOnly = 1 << 2, // Does the troll only work on players, not bots? If set, troll only applied on real user. If not, troll applied to both bot and idler
}
native void ApplyTroll(int victim, const char[] name, TrollModifier modifier = TrollMod_Invalid, int flags, int activator, bool silent = false);
forward void OnTrollApplied(int victim, const char[] trollName, int flags = 0, int activator = 0);
forward void OnTrollMarked(int activator, int victim);

View file

@ -193,12 +193,13 @@ enum struct Troll {
/////// TROLL ACTIVATION
void Activate(int client, int activator, trollModifier modifier = TrollMod_Invalid, int flags = 0) {
void Activate(int client, int activator, trollModifier modifier = TrollMod_Invalid, int flags = 0, bool silent = false) {
if(modifier == TrollMod_Invalid) modifier = this.GetDefaultMod();
// Sadly, unable to pass in <this> to ApplyTroll, so it has to do unnecessary lookup via string
ApplyTroll(client, this.name, activator, modifier, flags);
ApplyTroll(client, this.name, activator, modifier, flags, silent);
}
void Toggle(int client, int flags) {
ToggleTroll(client, this.name, flags);
}
@ -371,6 +372,13 @@ void ApplyTroll(int victim, const char[] name, int activator, trollModifier modi
LogAction(activator, victim, "\"%L\" deactivated {yellow}\"%s\"{default} on \"%L\"", activator, troll.name, victim);
} else {
static char flagName[MAX_TROLL_FLAG_LENGTH];
// strcopy(flagName, sizeof(flagName), troll.name)
// Call_StartForward(g_TrollAppliedForward);
// Call_PushCell(victim);
// Call_PushString(flagName);
// Call_PushCell(flags);
// Call_PushCell(activator);
// Call_Finish();
flagName[0] = '\0';
for(int i = 0; i < 32; i++) {
if(flags & (1 << i)) {
@ -445,3 +453,25 @@ public void SetCategory(const char[] newCat) {
void GetCategory(int category, char[] buffer, int size) {
categories.GetString(category, buffer, size);
}
public int Native_ApplyTroll(Handle plugin, int numParams) {
int victim = GetNativeCell(1);
char name[MAX_TROLL_NAME_LENGTH];
GetNativeString(2, name, sizeof(name));
trollModifier modifier = view_as<trollModifier>(GetNativeCell(3));
if(view_as<int>(modifier) < 0) {
ThrowNativeError(SP_ERROR_NATIVE, "Provided modifier is invalid (out of range)");
}
int flags = GetNativeCell(4);
int activator = GetNativeCell(5);
int index = GetTrollID(name);
if(index > 0) {
Trolls[index].Activate(victim, activator, modifier, flags, GetNativeCell(7));
} else {
ThrowNativeError(SP_ERROR_NATIVE, "Could not find troll with name \"%s\"", name);
}
return 0;
}

View file

@ -12,6 +12,7 @@ enum L4D2Infected
};
GlobalForward g_PlayerMarkedForward;
GlobalForward g_TrollAppliedForward;
Handle g_hWitchAttack;
int g_iWitchAttackVictim;
Handle hThrowTimer;

View file

@ -30,6 +30,11 @@ public Plugin myinfo =
url = "https://github.com/Jackzmc/sourcemod-plugins"
};
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) {
CreateNative("ApplyTroll", Native_ApplyTroll);
return APLRes_Success;
}
public void OnPluginStart() {
EngineVersion g_Game = GetEngineVersion();
@ -38,7 +43,9 @@ public void OnPluginStart() {
}
LoadTranslations("common.phrases");
g_PlayerMarkedForward = new GlobalForward("FTT_OnClientMarked", ET_Ignore, Param_Cell, Param_Cell);
g_PlayerMarkedForward = new GlobalForward("OnTrollMarked", ET_Ignore, Param_Cell, Param_Cell);
g_TrollAppliedForward = new GlobalForward("OnTrollApplied", ET_Ignore, Param_Cell, Param_Cell);
// Load core things (trolls & phrases):
REPLACEMENT_PHRASES = new StringMap();