-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentfinder.as
More file actions
239 lines (189 loc) · 7.92 KB
/
entfinder.as
File metadata and controls
239 lines (189 loc) · 7.92 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
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/* entfinder
Script to find stuff w/ commands
Commands:-
"find_edict": prints info for an entity at a given entindex
"find_entity_center": prints entity center point value
"find_radius": prints info for entities found within a given radius
"find_pvs": prints info for entities found within the given entity's pvs
"find_missing_brushmodels": prints all orphaned brush models unused by entities in the bsp, using 1 as an argument spawns them
This script is WIP and more features will be added if the need for them arises
- Outerbeast
*/
namespace ENTFINDER
{
const string strDebugMsgPrefix = " !------ENTFINDER------! ";
const array<CClientCommand@> CMD_FIND =
{
CClientCommand( "find_missing_brushmodels", "Finds missing brush models", FindMissingBrushModels ),
CClientCommand( "find_entity_center", "Gives entity center point", FindEntityCenter ),
CClientCommand( "find_edict", "Finds an entity at edict number", FindEdict ),
CClientCommand( "find_radius", "Finds entities in PVS", FindRadius ),
CClientCommand( "find_pvs", "Finds entities in PVS", FindPVS )
};
array<string> STR_BRUSHMODELS;
CScheduledFunction@ fnGetCurrentBrushEnts = g_Scheduler.SetTimeout( "GetCurrentBrushEnts", 0.0f );
void PrintEntInfo(CBaseEntity@ pEntity)
{
if( pEntity is null )
return;
string strInfo = pEntity.GetClassname();
strInfo += pEntity.GetTargetname() != "" ? "\nTargetname: " + pEntity.GetTargetname() : "";
strInfo += "\nPosition: " + pEntity.pev.origin.ToString().Replace( ",", "" );
strInfo += "\nAngles: " + pEntity.pev.angles.ToString().Replace( ",", "" );
strInfo += pEntity.pev.model != "" ? "\nModel: " + pEntity.pev.model : "";
g_EngineFuncs.ServerPrint( strDebugMsgPrefix + strInfo + "\n" );
}
void GetCurrentBrushEnts()
{
STR_BRUSHMODELS.resize( 0 );
const Vector
vecWorldMins = Vector( -WORLD_BOUNDARY, -WORLD_BOUNDARY, -WORLD_BOUNDARY ),
vecWorldMaxs = Vector( WORLD_BOUNDARY, WORLD_BOUNDARY, WORLD_BOUNDARY );
array<CBaseEntity@> P_ENTITIES( g_EngineFuncs.NumberOfEntities() );
if( g_EntityFuncs.BrushEntsInBox( @P_ENTITIES, vecWorldMins, vecWorldMaxs ) < 1 )
return;
for( uint i = 0; i < P_ENTITIES.length(); i++ )
{
if( P_ENTITIES[i] is null || !P_ENTITIES[i].IsBSPModel() )
continue;
if( STR_BRUSHMODELS.find( string( P_ENTITIES[i].pev.model ) ) >= 0 )
continue;
uint iCurrentBrushMdl = atoi( string( P_ENTITIES[i].pev.model ).Replace( "*", "" ) );
STR_BRUSHMODELS.resize( iCurrentBrushMdl + 1 );
STR_BRUSHMODELS[iCurrentBrushMdl] = "" + P_ENTITIES[i].pev.model;
//g_EngineFuncs.ServerPrint( strDebugMsgPrefix + "Found existing brush model: " + P_ENTITIES[i].pev.model + "\n" );
}
}
bool BrushExists(const string strModel)
{
CBaseEntity@ pExistingBrush;
while( ( @pExistingBrush = g_EntityFuncs.FindEntityByString( pExistingBrush, "model", strModel ) ) !is null )
{
if( @pExistingBrush is null || !pExistingBrush.IsBSPModel() || pExistingBrush.GetTargetname().StartsWith( "missing_brush_#" ) )
continue;
return pExistingBrush !is null;
}
return false;
}
void FindMissingBrushModels(const CCommand@ cmdArgs)
{
if( cmdArgs.ArgC() < 1 || cmdArgs[0][0] != "find_missing_brushmodels" )
return;
string strInfo;
for( uint i = 1; i < STR_BRUSHMODELS.length(); i++ )
{
if( STR_BRUSHMODELS[i] == "" )
{
CBaseEntity@ pMissingBrush = g_EntityFuncs.CreateEntity( "func_wall_toggle", {{ "model", "*" + i }, { "targetname", "missing_brush_#" + i }}, false );
if( !BrushExists( string( pMissingBrush.pev.model ) ) )
{
strInfo = strDebugMsgPrefix + "Found missing brush model: " + pMissingBrush.pev.model;
if( atoi( cmdArgs[1] ) > 0 )
{
g_EntityFuncs.DispatchSpawn( pMissingBrush.edict() );
strInfo += " spawned at position: " + pMissingBrush.Center().ToString().Replace( ",", "" );
}
g_EngineFuncs.ServerPrint( strInfo + "\n" );
}
else
g_EntityFuncs.Remove( pMissingBrush );
}
}
if( strInfo == "" )
g_EngineFuncs.ServerPrint( strDebugMsgPrefix + "No missing brush entities found." );
}
void FindEntityCenter(const CCommand@ cmdArgs)
{
if( cmdArgs.ArgC() < 1 || cmdArgs[0][0] != "find_entity_center" )
return;
CBaseEntity@ pEntity;
if( cmdArgs[1] != "" )
{
while( ( @pEntity = g_EntityFuncs.FindEntityByTargetname( pEntity, cmdArgs[1] ) ) !is null )
{
if( pEntity is null )
{
g_EngineFuncs.ServerPrint( strDebugMsgPrefix + "No entity with that name found.\n" );
continue;
}
g_EngineFuncs.ServerPrint( strDebugMsgPrefix + pEntity.GetClassname() + " center point: " + pEntity.Center().ToString().Replace( ",", "" ) + "\n" );
}
}
else
{
@pEntity = g_Utility.FindEntityForward( g_ConCommandSystem.GetCurrentPlayer() );
if( pEntity is null || !pEntity.IsBSPModel() )
{
g_EngineFuncs.ServerPrint( strDebugMsgPrefix + "No entity ahead.\n" );
return;
}
else
g_EngineFuncs.ServerPrint( strDebugMsgPrefix + pEntity.GetClassname() + " center point: " + pEntity.Center().ToString().Replace( ",", "" ) + "\n" );
}
}
void FindEdict(const CCommand@ cmdArgs)
{
if( cmdArgs.ArgC() < 1 || cmdArgs[0][0] != "find_edict" )
return;
if( cmdArgs[1] == "" || atoi( cmdArgs[1] ) < 0 )
{
g_EngineFuncs.ServerPrint( strDebugMsgPrefix + "Please enter a valid entity index number to search.\n" );
return;
}
CBaseEntity@ pEntity = g_EntityFuncs.Instance( atoi( cmdArgs[1] ) );
if( pEntity is null )
{
g_EngineFuncs.ServerPrint( strDebugMsgPrefix + " Entity at edict " + cmdArgs[1] + " not found.\n" );
return;
}
PrintEntInfo( pEntity );
}
void FindRadius(const CCommand@ cmdArgs)
{
if( cmdArgs.ArgC() < 1 || cmdArgs[0][0] != "find_radius" )
return;
const Vector vecOrigin = g_ConCommandSystem.GetCurrentPlayer().pev.origin;
const float flRadius = atof( cmdArgs[1] );
if( flRadius <= 0 )
{
g_EngineFuncs.ServerPrint( strDebugMsgPrefix + "Please enter a valid radius to search.\n" );
return;
}
CBaseEntity@ pEntity;
while( ( @pEntity = g_EntityFuncs.FindEntityInSphere( pEntity, vecOrigin, flRadius, "*", "classname" ) ) !is null )
{
if( pEntity is null || pEntity is g_ConCommandSystem.GetCurrentPlayer() )
continue;
PrintEntInfo( pEntity );
}
}
void FindPVS(const CCommand@ cmdArgs)
{
if( cmdArgs.ArgC() < 1 || cmdArgs[0][0] != "find_pvs" )
return;
edict_t@ eStartEntity, ePVSEntity;
if( cmdArgs[1] != "" && g_EntityFuncs.FindEntityByTargetname( null, cmdArgs[1] ) !is null )
@eStartEntity = g_EntityFuncs.FindEntityByTargetname( null, cmdArgs[1] ).edict();
else
@eStartEntity = g_ConCommandSystem.GetCurrentPlayer().edict();
if( eStartEntity is null )
return;
@ePVSEntity = g_EngineFuncs.EntitiesInPVS( eStartEntity );
if( ePVSEntity is null )
{
g_EngineFuncs.ServerPrint( strDebugMsgPrefix + " No entities in PVS found.\n" );
return;
}
do
{
if( ePVSEntity is eStartEntity || ePVSEntity.vars.size == g_vecZero ) // Physical entities only
{
@ePVSEntity = ePVSEntity.vars.chain;
continue;
}
PrintEntInfo( g_EntityFuncs.Instance( ePVSEntity ) );
@ePVSEntity = ePVSEntity.vars.chain;
}
while( ePVSEntity !is null );
}
}