Jump to content

Make a service stop if no players connect for x amount of days


mspsmuge

Recommended Posts

Try this:

import clr
import System
from System import String, DateTime

if QueryResults.Running == False :
 Script.Exit()

NumPlayers = QueryResults.NumPlayers

if ThisService.Variables.HasValue("LastDateWithPlayers") and NumPlayers == 0 :
 LastDateWithPlayers = ThisService.Variables["LastDateWithPlayers"]
 if LastDateWithPlayers.AddDays(1) <= DateTime.Now :
   Script.WriteToConsole(String.Format("{0} - Empty for 1 day. Stopping...", ThisService.ConnectionInfo))
   ThisService.Stop()

if NumPlayers > 0:
 ThisService.Variables["LastDateWithPlayers"] = DateTime.Now
 ThisService.Save()

Link to comment
Share on other sites

  • 3 years later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Who's Online   0 Members, 0 Anonymous, 46 Guests (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use