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...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Who's Online   0 Members, 0 Anonymous, 9 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