I've reworked your script for my (SSHIP) purposes.
Script will log AI switching (for debug AI puproses, also loggin is good ), but needs to be run with cscript instead of wscript from .bat or comment logging
Logs will look like:
BAI switched to AiSet5 at 13:42:09
BAI switched to AiSet3 at 13:43:11
Script is easy configurable - minutes between switches - delayMinutes variable.
Works with Steam, should work with no steam also (kingdom.exe process).
Here :
Code:
' Please run with cscript G5BAISwitcher.vbs or comment Wscript.Echo logging
' Creadits for idea & initial script for to TATW team
' Tomasz M. - tmodelsk, free of use
delayMinutes = 10 ' Delay between BAI switching in minutes
delayInterval = 3000 '3 sec. internal loop delay
processName1 = "kingdoms.exe"
processName2 = "medieval2.exe"
delayIterationReset = (delayMinutes * 60 * 1000) / delayInterval
delayInteration = delayIterationReset / 2
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWSH = CreateObject("WScript.Shell")
sCurDir = oFSO.GetParentFolderName(WScript.ScriptFullName)
Function IsProcessRunning( strServer, processName1 )
Dim Process, strObject
IsProcessRunning = False
strObject = "winmgmts://" & strServer
For Each Process in GetObject( strObject ).InstancesOf( "win32_process" )
If UCase( Process.name ) = UCase( processName1 ) Then
IsProcessRunning = True
Exit Function
End If
Next
End Function
Function IsNotMedievalRunning()
Dim strServer
IsNotMedievalRunning = Not ( IsProcessRunning( strServer, processName1 ) Or IsProcessRunning( strServer, processName2 ) )
End Function
Do While True
delayInteration = delayInteration + 1
if ( delayInteration >= delayIterationReset ) Then
delayInteration = 0
intHighNumber = 5
intLowNumber = 1
Randomize
intNumber = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
If intNumber = 1 then oFSO.CopyFile sCurDir & "\data\AiSet1\*.*", sCurDir & "\data\", True
If intNumber = 2 then oFSO.CopyFile sCurDir & "\data\AiSet2\*.*", sCurDir & "\data\", True
If intNumber = 3 then oFSO.CopyFile sCurDir & "\data\AiSet3\*.*", sCurDir & "\data\", True
If intNumber = 4 then oFSO.CopyFile sCurDir & "\data\AiSet4\*.*", sCurDir & "\data\", True
If intNumber = 5 then oFSO.CopyFile sCurDir & "\data\AiSet5\*.*", sCurDir & "\data\", True
Wscript.Echo "BAI switched to AiSet" & intNumber & " at " & FormatDateTime(Now, vbLongTime)
End if
WScript.Sleep delayInterval
if ( IsNotMedievalRunning() ) Then WScript.Quit
Loop