-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrigger_playerfreeze.as
203 lines (161 loc) · 7.05 KB
/
trigger_playerfreeze.as
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/* trigger_playerfreeze- Freezing entity from Opposing Force
by Outerbeast
Made this for backwards compatibility reasons- freezing players can already
be achieved using trigger_camera "Freeze players" flag, or changevalue + entity_iterator but this is much more convenient.
Installation:-
- Place in scripts/maps
- Add
map_script trigger_playerfreeze
to your map cfg
OR
- Add
#include "trigger_playerfreeze"
to your main map script header
OR
- Create a trigger_script with these keys set in your map:
"classname" "trigger_script"
"m_iszScriptFile" "trigger_playerfreeze"
Usage:-
Simply trigger the entity to start freezing players. The entity will continue to freeze players while its active.
To unfreeze, trigger it again, or killtarget the entity.
You can use "target" key followed by the targetname of your player to specifically freeze them and nobody else.
After the entity triggers it will target entities matching its "message" value.
Flags:
1: "Start On" - the entity will be active when the level starts. This is automatically the case if the entity has no targetname
2: "Invisible" - while the players are frozen, they will also be invisible.
4: "Invert target" - instead of freezing the target, everyone else but the target will be frozen.
8: "Freeze in place" - players will be frozen in place and cannot be moved through other means, such as being pushed by entities or falling. Players cannot use weapons
*/
enum freezespawnflags
{
SF_STARTON = 1 << 0,
SF_RENDERINVIS = 1 << 1,
SF_INVERT_TARGET = 1 << 2,
SF_FREEZE_IN_PLACE = 1 << 3
};
bool blTriggerPlayerFreezeRegistered = RegisterTriggerPlayerFreezeEntity();
bool RegisterTriggerPlayerFreezeEntity()
{
g_CustomEntityFuncs.RegisterCustomEntity( "trigger_playerfreeze", "trigger_playerfreeze" );
g_CustomEntityFuncs.RegisterCustomEntity( "trigger_playerfreeze", "player_freeze" );// alias for SoHL
return g_CustomEntityFuncs.IsCustomEntity( "trigger_playerfreeze" );
}
final class trigger_playerfreeze : ScriptBaseEntity
{
private EHandle hActivator;
private bool blShouldFreeze;
private float flWaitTime;
private CScheduledFunction@ fnWaitToggle;
bool KeyValue(const string& in szKey, const string& in szValue)
{
if( szKey == "wait" )
flWaitTime = atof( szValue );
else
return BaseClass.KeyValue( szKey, szValue );
return true;
}
void Spawn()
{
self.pev.movetype = MOVETYPE_NONE;
self.pev.solid = SOLID_NOT;
self.pev.effects |= EF_NODRAW;
g_EntityFuncs.SetOrigin( self, self.pev.origin );
if( self.pev.SpawnFlagBitSet( SF_STARTON ) || self.GetTargetname() == "" )
self.Use( self, self, USE_ON );
BaseClass.Spawn();
}
bool FCanFreezeTarget(EHandle hFreezeTarget)
{
if( !hFreezeTarget )
return false;
if( self.pev.target == "" )
return true;
if( self.pev.target == "!activator" && hActivator )
{
return( self.pev.SpawnFlagBitSet( SF_INVERT_TARGET ) ?
hFreezeTarget.GetEntity() !is hFreezeTarget.GetEntity() :
hFreezeTarget.GetEntity() is hFreezeTarget.GetEntity() );
}
return( self.pev.SpawnFlagBitSet( SF_INVERT_TARGET ) ?
self.pev.target != hFreezeTarget.GetEntity().GetTargetname() :
self.pev.target == hFreezeTarget.GetEntity().GetTargetname() );
}
void TurnOff()
{
self.Use( self, self, USE_OFF );
}
void Use(CBaseEntity@ pActivator, CBaseEntity@ pCaller, USE_TYPE useType, float flValue)
{
switch( useType )
{
case USE_ON:
{
blShouldFreeze = g_Hooks.RegisterHook( Hooks::Player::PlayerPostThink, PlayerPostThinkHook( this.Freezer ) );
g_Hooks.RegisterHook( Hooks::Player::ClientPutInServer, ClientPutInServerHook( this.Freezer ) );
g_Hooks.RemoveHook( Hooks::Player::PlayerPostThink, PlayerPostThinkHook( this.Defroster ) );
hActivator = pActivator;
break;
}
case USE_OFF:
{
blShouldFreeze = false;
g_Hooks.RemoveHook( Hooks::Player::PlayerPostThink, PlayerPostThinkHook( this.Freezer ) );
g_Hooks.RemoveHook( Hooks::Player::ClientPutInServer, ClientPutInServerHook( this.Freezer ) );
g_Hooks.RegisterHook( Hooks::Player::PlayerPostThink, PlayerPostThinkHook( this.Defroster ) );
hActivator = EHandle();
break;
}
case USE_TOGGLE:
self.Use( null, null, blShouldFreeze ? USE_OFF : USE_ON );
break;
}
if( flWaitTime > 0 && blShouldFreeze )
@fnWaitToggle = g_Scheduler.SetTimeout( this, "TurnOff", flWaitTime );
if( self.pev.message != "" && self.pev.message != self.GetTargetname() && blShouldFreeze )
g_EntityFuncs.FireTargets( self.pev.message, hActivator.GetEntity(), self, USE_TOGGLE );
}
HookReturnCode Freezer(CBasePlayer@ pPlayer)
{
if( pPlayer is null || !pPlayer.IsConnected() || !blShouldFreeze || !FCanFreezeTarget( pPlayer ) )
return HOOK_CONTINUE;
if( self.pev.SpawnFlagBitSet( SF_FREEZE_IN_PLACE ) )
pPlayer.EnableControl( false );
else
{
pPlayer.SetMaxSpeedOverride( 0 );
pPlayer.pev.fuser4 = 1.0f;
}
if( self.pev.SpawnFlagBitSet( SF_RENDERINVIS ) && pPlayer.pev.effects & EF_NODRAW == 0 )
pPlayer.pev.effects |= EF_NODRAW;
return HOOK_CONTINUE;
}
HookReturnCode Defroster(CBasePlayer@ pPlayer)
{
if( pPlayer is null || !pPlayer.IsConnected() || blShouldFreeze )
return HOOK_CONTINUE;
if( pPlayer.pev.fuser4 <= 0.0f || pPlayer.pev.SpawnFlagBitSet( FL_FROZEN ) )
return HOOK_CONTINUE;
if( self.pev.SpawnFlagBitSet( SF_FREEZE_IN_PLACE ) )
pPlayer.EnableControl( true );
else
{
pPlayer.SetMaxSpeedOverride( -1 );
pPlayer.pev.fuser4 = 0.0f;
}
if( self.pev.SpawnFlagBitSet( SF_RENDERINVIS ) && pPlayer.pev.effects & EF_NODRAW != 0 )
pPlayer.pev.effects &= ~EF_NODRAW;
return HOOK_CONTINUE;
}
void UpdateOnRemove()
{
blShouldFreeze = false;
g_Hooks.RemoveHook( Hooks::Player::PlayerPostThink, PlayerPostThinkHook( this.Freezer ) );
g_Hooks.RemoveHook( Hooks::Player::ClientPutInServer, ClientPutInServerHook( this.Freezer ) );
for( int iPlayer = 1; iPlayer <= g_Engine.maxClients; iPlayer++ )
Defroster( g_PlayerFuncs.FindPlayerByIndex( iPlayer ) );
g_Hooks.RemoveHook( Hooks::Player::PlayerPostThink, PlayerPostThinkHook( this.Defroster ) );
if( fnWaitToggle !is null )
g_Scheduler.RemoveTimer( fnWaitToggle );
BaseClass.UpdateOnRemove();
}
};