Results 1 to 3 of 3

Thread: G5BAISwitcher.vbs will not work background on Steam version (my steam)

  1. #1
    tmodelsk's Avatar Tiro
    Join Date
    Jan 2016
    Location
    Warsaw, Poland
    Posts
    242

    Default G5BAISwitcher.vbs will not work background on Steam version (my steam)

    Hi folks.

    I don't want to do any harm, I'm not playing TATW regularly, just want to share my observation.

    While looking into the Germanicus AI and switching AIs I've looked into your "G5BAISwitcher.vbs" for reference and ideas.
    I've got MOS installed, so maybe it's from MOS (don't know).

    The point is the script will work in a background ONLY if there's process named "kingdoms.exe" running in memory.

    But my Steam version (latest) so probably ALL Steam version has process named "medieval2.exe"
    Even when the exe is renamed to "kingdoms.exe".
    So script will do initial AI switch and terminate.

    Just sharing my observation & thoughts.
    SSHIP mini-mods :

  2. #2
    tmodelsk's Avatar Tiro
    Join Date
    Jan 2016
    Location
    Warsaw, Poland
    Posts
    242

    Default Re: G5BAISwitcher.vbs will not work background on Steam version (my steam)

    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
    SSHIP mini-mods :

  3. #3
    Withwnar's Avatar Script To The Waist
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    5,665

    Default Re: G5BAISwitcher.vbs will not work background on Steam version (my steam)

    Good find. And cleaner script.

    Additionally, strServer is never set to anything so may as well not be there at all.

    Code:
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •