-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtrigger_sequential.as
More file actions
144 lines (120 loc) · 4.73 KB
/
Copy pathtrigger_sequential.as
File metadata and controls
144 lines (120 loc) · 4.73 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* trigger_sequential
by Outerbeast
Installation:-
- Place in scripts/maps
- Add
map_script trigger_sequential
to your map cfg
OR
- Add
#include "trigger_sequential"
to your main map script header
OR
- Create a trigger_script with these keys set in your map:
"classname" "trigger_script"
"m_iszScriptFile" "trigger_sequential"
Usage:-
Literally multi_manager except each target is not triggered automatically, rather only when the entity is triggered manually.
Each target is now triggered in the order that is set in the entity, not based on delay value. Delay values only determine when the target gets triggered after the trigger_sequential is used.
When the last target is triggered, the entity will reset back to the initial target and can be used again.
"health" key sets a wait-reset period before the trigger_sequential is allowed to be triggered again.
"frags" key keeps track of which number target the entity is expected to trigger next, the first target being "0" and the second "1", ...
This key can also be preset to override which target to start from, so from a list of 10 targets should you which to start from the 5th target, set the value to "4" (since 10 targets equates to 0th-9th)
This entity also has the trigger type "#3" which will use whatever the caller entity use type was.
*/
bool blRegisterTriggerSequential = RegisterTriggerSequential();
bool RegisterTriggerSequential()
{
g_CustomEntityFuncs.RegisterCustomEntity( "trigger_sequential", "trigger_sequential" );
return g_CustomEntityFuncs.IsCustomEntity( "trigger_sequential" );
}
final class trigger_sequential : ScriptBaseEntity
{
private dictionary dictKeyValues;
private bool blShouldTrigger = true;
private uint iTargetNumber
{
get { return uint( self.pev.frags ); }
set { self.pev.frags = value; }
}
bool KeyValue(const string& in szKey, const string& in szValue)
{
dictKeyValues[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 );
BaseClass.Spawn();
}
USE_TYPE SetUseType(uint iTriggerType = 99)
{
switch( iTriggerType )
{
case 0: return USE_OFF;
case 1: return USE_ON;
case 2: return USE_KILL;
case 3: return USE_SET;
default: return USE_TOGGLE;
}
return USE_TOGGLE;
}
void KillTarget(string strTargetname, float flDelay)
{
if( strTargetname == "" )
return;
if( flDelay > 0.0f )
{
g_Scheduler.SetTimeout( this, "KillTarget", flDelay, strTargetname, 0.0f );
return;
}
do( g_EntityFuncs.Remove( g_EntityFuncs.FindEntityByTargetname( null, strTargetname ) ) );
while( g_EntityFuncs.FindEntityByTargetname( null, strTargetname ) !is null );
}
void Think()
{
if( !blShouldTrigger )
{
blShouldTrigger = true;
self.pev.nextthink = 0.0f;
}
}
void Use(CBaseEntity@ pActivator, CBaseEntity@ pCaller, USE_TYPE useType, float flValue)
{
if( !blShouldTrigger || dictKeyValues.isEmpty() )
return;
const array<string> STR_KEYS = dictKeyValues.getKeys();
if( iTargetNumber == STR_KEYS.length() )
iTargetNumber = 0;
string strCurrentTarget = STR_KEYS[iTargetNumber];
strCurrentTarget.Trim( '#' );
const string strValue = string( dictKeyValues[STR_KEYS[iTargetNumber]] );
const float flDelay = atof( strValue );
USE_TYPE utTriggerType = SetUseType();
for( uint i = 0; i < strValue.Length(); i++ )
{
if( strValue[i] != '#' )
continue;
utTriggerType = SetUseType( atoui( strValue[i+1] ) );
break;
}
if( utTriggerType != USE_KILL )
{
if( utTriggerType == USE_SET )
g_EntityFuncs.FireTargets( strCurrentTarget, pActivator, pCaller, useType, 0.0f, flDelay );
else
g_EntityFuncs.FireTargets( strCurrentTarget, pActivator, pCaller, utTriggerType, 0.0f, flDelay );
}
else
KillTarget( strCurrentTarget, flDelay );
if( self.pev.health > 0.0f )
{
blShouldTrigger = false;
self.pev.nextthink = g_Engine.time + self.pev.health;
}
iTargetNumber += 1;
}
}