Skip to content

Instantly share code, notes, and snippets.

@Jackzmc
Created July 27, 2022 04:07
Show Gist options
  • Save Jackzmc/c12b169610fd4a917bb28b127005d6b9 to your computer and use it in GitHub Desktop.
Save Jackzmc/c12b169610fd4a917bb28b127005d6b9 to your computer and use it in GitHub Desktop.
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
// #include <l4d2_behavior>
#include <actions>
Handle g_hWitchAttack;
public void OnPluginStart()
{
GameData data = new GameData("l4d2_behavior");
StartPrepSDKCall(SDKCall_Raw);
PrepSDKCall_SetFromConf(data, SDKConf_Signature, "WitchAttack::WitchAttack");
PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer, VDECODE_FLAG_ALLOWNULL | VDECODE_FLAG_ALLOWWORLD);
g_hWitchAttack = EndPrepSDKCall();
LoadTranslations("common.phrases");
delete data;
RegAdminCmd("sm_witch_attack", Command_WitchAttack, ADMFLAG_CHEATS);
}
public Action Command_WitchAttack(int client, int args) {
if(args < 1) {
ReplyToCommand(client, "Usage: sm_witch_attack <user> [# of witches or 0 for all]");
}else{
char arg1[32];
GetCmdArg(1, arg1, sizeof(arg1));
char target_name[MAX_TARGET_LENGTH];
int target_list[1], target_count;
bool tn_is_ml;
if ((target_count = ProcessTargetString(
arg1,
client,
target_list,
1,
COMMAND_FILTER_ALIVE, /* Only allow alive players */
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;
}
GetCmdArg(2, arg1, sizeof(arg1));
int maxCount = StringToInt(arg1);
if(maxCount < 0) maxCount = 0;
int count;
int target = target_list[0];
if(GetClientTeam(target) == 2) {
int witch = INVALID_ENT_REFERENCE;
while ((witch = FindEntityByClassname(witch, "witch")) != INVALID_ENT_REFERENCE) {
// WitchBehavior works best, but ideally any action?
BehaviorAction action = ActionsManager.GetAction(witch, "WitchBehavior");
if(action == INVALID_ACTION) {
PrintToServer("Could not get action for WitchAttack");
return Plugin_Stop;
}
BehaviorAction newAction = ActionsManager.Allocate(18556);
SDKCall(g_hWitchAttack, newAction, target);
action.StorePendingEventResult(CHANGE_TO, newAction);
// newAction.StorePendingEventResult(DONE);
if(maxCount > 0 && ++count >= maxCount) break;
}
ShowActivity(client, "%d witches target %s", count, target_name);
}else{
ReplyToTargetError(client, target_count);
}
}
return Plugin_Handled;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment