once again thanks for your reply. this is a little hard to add any additional text items to search for (monster_human_grunt). While keeping track of the current monster count or making any other changes. but it works.
Dim f, fc, afile
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set f = objfso.GetFolder(".")
Set fc = f.Files
For Each aFile In fc
'If UCase(Right(aFile.Name, 3)) = "ENT" then
If Left(afile.Type, 3) = "ENT" Then
Set objFile = objFSO.OpenTextFile(afile, ForReading)
strText = objFile.ReadAll
objFile.Close
Dim colmatches
'alien_slave counter
With New RegExp
.IgnoreCase = True
.Global = True
.Pattern = "monster_alien_slave"
Set colMatches = .Execute(strText)
ialien_slavescount = colmatches.count
End With
'barnacle counter
With New RegExp
.IgnoreCase = True
.Global = True
.Pattern = "monster_barnacle"
Set colMatches = .Execute(strText)
ibarnaclecount = colmatches.count
End With
'headcrab counter
With New RegExp
.IgnoreCase = True
.Global = True
.Pattern = "monster_headcrab"
Set colMatches = .Execute(strText)
iheadcrabcount = colmatches.count
End With
'houndeye counter
With New RegExp
.IgnoreCase = True
.Global = True
.Pattern = "monster_houndeye"
Set colMatches = .Execute(strText)
ihoundeyecount = colmatches.count
End With
'zombie counter
'Dim colmatches
With New RegExp
.IgnoreCase = True
.Global = True
.Pattern = "monster_zombie"
Set colMatches = .Execute(strText)
izombiecount = colmatches.count
End With
'sum the counters
icount = ialien_slavecount + ibarnaclecount + iheadcrabcount + ihoundeyecount + izombiecount
'insert headcrab stuff
strstuff = Chr(34) & "monster_headcrab" &Chr(34)
strNewText = Replace(strText, _
strstuff, _
strstuff _
&vbNewLine &Chr(34) &"TriggerTarget" &Chr(34) & " " &chr(34) &"MonsterCounter" &Chr(34) _
&vbNewLine &Chr(34) & "TriggerCondition" &Chr(34) & " " &chr(34) & "4" &Chr(34))
If iheadcrabcount > 0 Then
strText = strNewText
End If
'insert houndeye stuff
strstuff = Chr(34) & "monster_houndeye" &Chr(34)
strNewText = Replace(strText, _
strstuff, _
strstuff _
&vbNewLine &Chr(34) &"TriggerTarget" &Chr(34) & " " &chr(34) &"MonsterCounter" &Chr(34) _
&vbNewLine &Chr(34) & "TriggerCondition" &Chr(34) & " " &chr(34) & "4" &Chr(34))
If ihoundeyecount > 0 Then
strText = strNewText
End If
'insert zombie stuff
strstuff = Chr(34) & "monster_zombie" &Chr(34)
strNewText = Replace(strText, _
strstuff, _
strstuff _
&vbNewLine &Chr(34) &"TriggerTarget" &Chr(34) & " " &chr(34) &"MonsterCounter" &Chr(34) _
&vbNewLine &Chr(34) & "TriggerCondition" &Chr(34) & " " &chr(34) & "4" &Chr(34))
If izombiecount > 0 Then
strText = strNewText
End If
Set objFile = objFSO.OpenTextFile(afile, ForWriting)
objFile.WriteLine strNewText
'append other stuff
objFile.WriteLine "{"
objFile.WriteLine chr(34) &"target" &Chr(34) &" " &chr(34) &"EndMap" &Chr(34)
objFile.WriteLine Chr(34) &"count"&Chr(34) &" " &Chr(34) &iCount-2 &Chr(34)
objFile.WriteLine Chr(34) &"style"&Chr(34) &" " &Chr(34) &"32" &Chr(34)
objFile.WriteLine Chr(34) &"message" &Chr(34) &" " &Chr(34) &"one dead monster" &Chr(34)
objFile.WriteLine Chr(34) &"targetname" &Chr(34) &" " &Chr(34) &"MonsterCounter" &Chr(34)
objFile.WriteLine Chr(34) &"classname" &Chr(34) &" " &Chr(34) &"trigger_counter" &Chr(34)
objFile.WriteLine "}"
objFile.WriteLine "{"
objFile.WriteLine Chr(34) &"targetname" &Chr(34) &" " &Chr(34) &"EndMap" &Chr(34)
objFile.WriteLine Chr(34) &"spawnflags" &Chr(34) &" " &Chr(34) &"2" &Chr(34)
objFile.WriteLine Chr(34) &"classname" &Chr(34) &" " &Chr(34) &"trigger_changelevel" &Chr(34)
objFile.WriteLine Chr(34) &"map" &Chr(34) & " " &Chr(34) &"WHATEVER" &Chr(34)
objFile.WriteLine "}"
objFile.Close
End If
Next