forked from VANCOLD/fm_drive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FM_ENTMOD_COMMAND.sma
144 lines (119 loc) · 2.73 KB
/
FM_ENTMOD_COMMAND.sma
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "feckinmad/fm_global"
#include "feckinmad/fm_point" // fm_GetAimEntity()
#include "feckinmad/entmod/fm_entmod_move" // fm_GetPlayerMoveEnt()
#include "feckinmad/entmod/fm_entmod_command" // fm_CommandGetEntity()
#include <fakemeta>
new g_iForward, g_iMaxPlayers
new g_iMovePlugin
public plugin_natives()
{
register_native("fm_CommandGetEntity", "Native_CommandGetEntity")
register_native("fm_CommandCheckEntity", "Native_CommandCheckEntity")
register_library("fm_entmod_command")
set_module_filter("Module_Filter")
set_native_filter("Native_Filter")
}
public plugin_init()
{
fm_RegisterPlugin()
g_iMaxPlayers = get_maxplayers()
g_iForward = CreateMultiForward("fm_RunEntCommand", ET_STOP, FP_CELL, FP_CELL, FP_CELL)
g_iMovePlugin = LibraryExists("fm_entmod_move", LibType_Library)
}
public plugin_end()
{
if (g_iForward > 0)
{
DestroyForward(g_iForward)
}
}
public Native_CommandGetEntity()
{
new id = get_param(1)
if (id < 1 || id > g_iMaxPlayers)
{
log_error(AMX_ERR_NATIVE, "Player out of range (%d)", id)
return 0
}
if (!is_user_connected(id))
{
log_error(AMX_ERR_NATIVE, "Invalid player (%d)", id)
return 0
}
static sArg[8]; get_string(2, sArg, charsmax(sArg))
new iLen = strlen(sArg)
if (!iLen)
{
console_print(id, "You must specify an enitity")
return 0
}
// If you press the up arrow to repeat a command in the hl console it adds a space to the end of the line. Remove it.
new iEndChar = iLen - 1
if (sArg[iEndChar] == ' ')
{
sArg[iEndChar] = 0
}
// If the player specifies -1, I use the entity they are moving or the entity they are looking at
new iEnt = str_to_num(sArg)
if (iEnt == -1)
{
if (g_iMovePlugin)
{
iEnt = fm_GetPlayerMoveEnt(id)
}
if (!iEnt)
{
iEnt = fm_GetAimEntity(id)
}
}
return iEnt
}
public Native_CommandCheckEntity()
{
new id = get_param(1)
if (id < 1 || id > g_iMaxPlayers)
{
log_error(AMX_ERR_NATIVE, "Player out of range (%d)", id)
return 0
}
if (!is_user_connected(id))
{
log_error(AMX_ERR_NATIVE, "Invalid player (%d)", id)
return 0
}
new iEnt = get_param(2)
if (!pev_valid(iEnt))
{
console_print(id, "Entity %d is not valid", iEnt)
return 0
}
if (iEnt > 0 && iEnt <= g_iMaxPlayers)
{
console_print(id, "You cannot run ent commands on players")
return 0
}
new iReturn, iMode = get_param(3)
ExecuteForward(g_iForward, iReturn, id, iEnt, iMode)
if (iReturn == PLUGIN_HANDLED)
{
return 0
}
return 1
}
public Module_Filter(sModule[])
{
// Load the plugin even if the entmod move plugin is not running
if (equal(sModule, "fm_entmod_move"))
{
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
public Native_Filter(sName[], iIndex, iTrap)
{
if (!iTrap)
{
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}