-
Notifications
You must be signed in to change notification settings - Fork 1
/
prevent-door-spam.sp
67 lines (58 loc) · 1.97 KB
/
prevent-door-spam.sp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* Headers & preprocessor directives */
#include <sourcemod>
#include <sdktools>
#pragma newdecls required
#define MAX_EDICTS 2048
#define IGNORE_PLAYER_USE 32768 // Ignore player +USE, prop_door_rotating flag
/* Global variables */
bool g_bInAction[MAX_EDICTS];
/**
* Plugin public information.
*/
public Plugin myinfo =
{
name = "Prevent Door Spam",
author = "ici",
description = "Prevents players from opening/closing func_door_rotating entities repeatedly",
version = "1.0.0",
url = "http://steamcommunity.com/id/1ci/"
};
/**
* Called when the plugin is fully initialized and all known external references
* are resolved. This is only called once in the lifetime of the plugin, and is
* paired with OnPluginEnd().
*
* If any run-time error is thrown during this callback, the plugin will be marked
* as failed.
*/
public void OnPluginStart()
{
HookEntityOutput("prop_door_rotating", "OnOpen", StartAction);
HookEntityOutput("prop_door_rotating", "OnClose", StartAction);
HookEntityOutput("prop_door_rotating", "OnFullyOpen", EndAction);
HookEntityOutput("prop_door_rotating", "OnFullyClosed", EndAction);
}
public Action StartAction(const char[] output, int caller, int activator, float delay)
{
if (g_bInAction[caller])
{
// The door is still opening/closing.
// Don't allow the player to close the door if it's not fully opened yet and vice versa.
return Plugin_Handled;
}
PrintCenterTextAll("StartAction %d", caller);
g_bInAction[caller] = true;
int flags = GetEntProp(caller, Prop_Data, "m_spawnflags");
flags |= IGNORE_PLAYER_USE;
SetEntProp(caller, Prop_Data, "m_spawnflags", flags);
return Plugin_Continue;
}
public void EndAction(const char[] output, int caller, int activator, float delay)
{
// The door has finished opening/closing.
PrintCenterTextAll("EndAction %d", caller);
g_bInAction[caller] = false;
int flags = GetEntProp(caller, Prop_Data, "m_spawnflags");
flags &= ~IGNORE_PLAYER_USE;
SetEntProp(caller, Prop_Data, "m_spawnflags", flags);
}