forked from VANCOLD/fm_drive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FM_ENTMOD_KEY.sma
124 lines (98 loc) · 2.94 KB
/
FM_ENTMOD_KEY.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
#include "feckinmad/fm_global"
#include "feckinmad/entmod/fm_entmod_misc" // fm_SetKeyValue()
#include "feckinmad/entmod/fm_entmod_base" // fm_SetCachedEntKey() & fm_CachedEntKeyCount() & fm_GetCachedEntKeyIndex()
#include "feckinmad/entmod/fm_entmod_command" // fm_CommandGetEntity()
#include "feckinmad/entmod/fm_entmod_access" // fm_CheckUserEntAccess()
#include <fakemeta>
public plugin_init()
{
fm_RegisterPlugin()
register_clcmd("fm_ent_info", "Player_EntInfo")
register_clcmd("fm_ent_key", "Player_EntSetKey")
register_clcmd("fm_ent_spawn", "Player_EntSpawn")
}
public Player_EntInfo(id)
{
if (!fm_CheckUserEntAccess(id))
{
return PLUGIN_HANDLED
}
new sArg[8]; read_argv(1, sArg, charsmax(sArg))
new iEnt = fm_CommandGetEntity(id, sArg)
if (!iEnt || !fm_CommandCheckEntity(id, iEnt, ENTCMD_READ))
{
return PLUGIN_HANDLED
}
new iMax = fm_CachedEntKeyCount(iEnt)
new sClassName[32]; pev(iEnt, pev_classname, sClassName, charsmax(sClassName))
console_print(id, "\nEntity: %d - pev_classname: %s", iEnt, sClassName)
console_print(id, "{")
new sKey[32], sValue[32]
for (new i = 0; i < iMax; i++)
{
fm_GetCachedEntKeyIndex(iEnt, i, sKey, charsmax(sKey), sValue, charsmax(sValue))
if (!equal(sKey, "fm_", 3))
{
console_print(id, "\t\t\t\"%s\" \"%s\"", sKey, sValue)
}
}
console_print(id, "}")
return PLUGIN_HANDLED
}
public Player_EntSpawn(id)
{
if (!fm_CheckUserEntAccess(id))
{
return PLUGIN_HANDLED
}
new sArg[8]; read_argv(1, sArg, charsmax(sArg))
new iEnt = fm_CommandGetEntity(id, sArg)
if (!iEnt || !fm_CommandCheckEntity(id, iEnt, ENTCMD_MODIFY))
{
return PLUGIN_HANDLED
}
dllfunc(DLLFunc_Spawn, iEnt)
new sClassName[32]; pev(iEnt, pev_classname, sClassName, charsmax(sClassName))
console_print(id, "Entity #%d \"%s\": Spawned", iEnt, sClassName)
return PLUGIN_HANDLED
}
public Player_EntSetKey(id)
{
if (!fm_CheckUserEntAccess(id))
{
return PLUGIN_HANDLED
}
new sBuffer[255]; read_args(sBuffer, charsmax(sBuffer))
new sArg1[8]; argbreak(sBuffer, sArg1, charsmax(sArg1), sBuffer, charsmax(sBuffer))
new iEnt = fm_CommandGetEntity(id, sArg1)
if (!iEnt || !fm_CommandCheckEntity(id, iEnt, ENTCMD_MODIFY))
{
return PLUGIN_HANDLED
}
new sArg2[32], sArg3[128]
argbreak(sBuffer, sArg2, charsmax(sArg2), sArg3, charsmax(sArg3))
if (!sArg2[0])
{
console_print(id, "You must specify a key")
return PLUGIN_HANDLED
}
if (equal(sArg2, "fm_", 3))
{
console_print(id, "Reserved key")
return PLUGIN_HANDLED
}
trim(sArg3)
if (equal(sArg2, "model") && sArg3[0] == '*')
{
if (!fm_IsValidBrushModel(str_to_num(sArg3[1])))
{
console_print(id, "Invalid brush model specified")
return PLUGIN_HANDLED
}
}
new sClassName[32]; pev(iEnt, pev_classname, sClassName, charsmax(sClassName))
fm_SetCachedEntKey(iEnt, sArg2, sArg3)
fm_SetKeyValue(iEnt, sClassName, sArg2, sArg3)
console_print(id, "Entity #%d \"%s\": Set key %s to \"%s\"", iEnt, sClassName, sArg2, sArg3)
return PLUGIN_HANDLED
}