witch_attack.sp
· 2.3 KiB · SourcePawn
Raw
#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;
}
| 1 | #pragma semicolon 1 |
| 2 | #pragma newdecls required |
| 3 | |
| 4 | #include <sourcemod> |
| 5 | #include <sdktools> |
| 6 | |
| 7 | // #include <l4d2_behavior> |
| 8 | #include <actions> |
| 9 | |
| 10 | Handle g_hWitchAttack; |
| 11 | |
| 12 | public void OnPluginStart() |
| 13 | { |
| 14 | GameData data = new GameData("l4d2_behavior"); |
| 15 | |
| 16 | StartPrepSDKCall(SDKCall_Raw); |
| 17 | PrepSDKCall_SetFromConf(data, SDKConf_Signature, "WitchAttack::WitchAttack"); |
| 18 | PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer, VDECODE_FLAG_ALLOWNULL | VDECODE_FLAG_ALLOWWORLD); |
| 19 | g_hWitchAttack = EndPrepSDKCall(); |
| 20 | |
| 21 | LoadTranslations("common.phrases"); |
| 22 | |
| 23 | delete data; |
| 24 | |
| 25 | RegAdminCmd("sm_witch_attack", Command_WitchAttack, ADMFLAG_CHEATS); |
| 26 | } |
| 27 | |
| 28 | public Action Command_WitchAttack(int client, int args) { |
| 29 | if(args < 1) { |
| 30 | ReplyToCommand(client, "Usage: sm_witch_attack <user> [# of witches or 0 for all]"); |
| 31 | }else{ |
| 32 | char arg1[32]; |
| 33 | GetCmdArg(1, arg1, sizeof(arg1)); |
| 34 | char target_name[MAX_TARGET_LENGTH]; |
| 35 | int target_list[1], target_count; |
| 36 | bool tn_is_ml; |
| 37 | if ((target_count = ProcessTargetString( |
| 38 | arg1, |
| 39 | client, |
| 40 | target_list, |
| 41 | 1, |
| 42 | COMMAND_FILTER_ALIVE, /* Only allow alive players */ |
| 43 | target_name, |
| 44 | sizeof(target_name), |
| 45 | tn_is_ml)) <= 0) |
| 46 | { |
| 47 | /* This function replies to the admin with a failure message */ |
| 48 | ReplyToTargetError(client, target_count); |
| 49 | return Plugin_Handled; |
| 50 | } |
| 51 | |
| 52 | GetCmdArg(2, arg1, sizeof(arg1)); |
| 53 | int maxCount = StringToInt(arg1); |
| 54 | if(maxCount < 0) maxCount = 0; |
| 55 | int count; |
| 56 | int target = target_list[0]; |
| 57 | |
| 58 | if(GetClientTeam(target) == 2) { |
| 59 | int witch = INVALID_ENT_REFERENCE; |
| 60 | while ((witch = FindEntityByClassname(witch, "witch")) != INVALID_ENT_REFERENCE) { |
| 61 | // WitchBehavior works best, but ideally any action? |
| 62 | BehaviorAction action = ActionsManager.GetAction(witch, "WitchBehavior"); |
| 63 | if(action == INVALID_ACTION) { |
| 64 | PrintToServer("Could not get action for WitchAttack"); |
| 65 | return Plugin_Stop; |
| 66 | } |
| 67 | BehaviorAction newAction = ActionsManager.Allocate(18556); |
| 68 | |
| 69 | SDKCall(g_hWitchAttack, newAction, target); |
| 70 | |
| 71 | action.StorePendingEventResult(CHANGE_TO, newAction); |
| 72 | // newAction.StorePendingEventResult(DONE); |
| 73 | if(maxCount > 0 && ++count >= maxCount) break; |
| 74 | } |
| 75 | ShowActivity(client, "%d witches target %s", count, target_name); |
| 76 | }else{ |
| 77 | ReplyToTargetError(client, target_count); |
| 78 | } |
| 79 | } |
| 80 | return Plugin_Handled; |
| 81 | } |
| 82 | |
| 83 | |
| 84 |