-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtrigger_command.as
More file actions
120 lines (101 loc) · 3.79 KB
/
trigger_command.as
File metadata and controls
120 lines (101 loc) · 3.79 KB
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
/* trigger_command - custom entity for executing player commands
Based loosly on the SoHL entity.
Installation:-
- Place in scripts/maps
- Add
map_script trigger_command
to your map cfg
OR
- Add
#include "trigger_command"
to your main map script header
OR
- Create a trigger_script with these keys set in your map:
"classname" "trigger_script"
"m_iszScriptFile" "trigger_command"
Usage:-
Use the "command" key folows by the command you wish to execute. The command is executed when the entity is triggered.
If the entity has no targetname applied, the entity will trigger automatically.
"netname" key sets a filter to target players with targetnames matching the netname value.
- Outerbeast
*/
const uint SF_SERVERCOMMAND = 1 << 0;
bool blTriggerCommandRegistered = RegisterTriggerCommand();
bool RegisterTriggerCommand()
{
g_CustomEntityFuncs.RegisterCustomEntity( "trigger_command", "trigger_command" );
return g_CustomEntityFuncs.IsCustomEntity( "trigger_command" );
}
// Execute client command
void StuffClient(const string& in command, edict_t@ eTarget = null)
{
if( command == "" )
return;
NetworkMessage stufftext( eTarget !is null ? MSG_ONE : MSG_BROADCAST, NetworkMessages::SVC_STUFFTEXT, eTarget );
stufftext.WriteString( command );
stufftext.End();
}
final class trigger_command : ScriptBaseEntity
{
private string strCommand;
bool KeyValue(const string& in szKey, const string& in szValue)
{
if( szKey == "command" )
strCommand = szValue;
else
return BaseClass.KeyValue( szKey, szValue );
return true;
}
void Spawn()
{
self.Precache();
self.pev.movetype = MOVETYPE_NONE;
self.pev.solid = SOLID_NOT;
self.pev.effects |= EF_NODRAW;
g_EntityFuncs.SetOrigin( self, self.pev.origin );
BaseClass.Spawn();
}
void PostSpawn()
{ // No targetname, just run automatically.
if( self.GetTargetname() == "" )
self.Use( self, self, USE_TOGGLE );
}
void Use(CBaseEntity@ pActivator, CBaseEntity@ pCaller, USE_TYPE useType, float flValue)
{
if( strCommand == "" )
return;
if( !self.pev.SpawnFlagBitSet( SF_SERVERCOMMAND ) )
{
if( self.pev.netname != "" )
{
CBasePlayer@ pTarget;
if( self.pev.netname == "!activator" )
@pTarget = cast<CBasePlayer@>( pActivator );
else if( self.pev.netname == "!caller" )
@pTarget = cast<CBasePlayer@>( pCaller );
else
{
for( int iPlayer = 1; iPlayer <= g_Engine.maxClients; iPlayer++ )
{
@pTarget = g_PlayerFuncs.FindPlayerByIndex( iPlayer );
if( pTarget is null || !pTarget.IsConnected() || pTarget.GetTargetname() != self.pev.netname )
continue;
StuffClient( strCommand, pTarget.edict() );
}
return;
}
if( pTarget !is null && pTarget.IsConnected() )
StuffClient( strCommand, pTarget.edict() );
}
else
StuffClient( strCommand );
}// !-BLOCKED-!: these methods are only exposed to plugin scripts
/* else
{
g_EngineFuncs.ServerCommand( strCommand );
g_EngineFuncs.ServerExecute();
}*/
if( self.pev.message != "" )
g_EntityFuncs.FireTargets( self.pev.message, pActivator, pCaller, useType );
}
};