The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX Ace => VXA Scripts Database => Topic started by: game_guy on February 29, 2012, 05:08:39 AM

Title: [VXA] One Game Instance
Post by: game_guy on February 29, 2012, 05:08:39 AM
One Game Instance
Authors: game_guy
Version: 1.0
Type: System Utility

Introduction

This script is to prevent multiple instances of your game. This is really only for online games so players can't cheat and PvP themselves.

Features


Screenshots

N/A

Demo

N/A

Script

Place at very top!
Spoiler for:
Code: [Select]
#===============================================================================
# One Game Instance
# Version 1.0
# Author game_guy
#-------------------------------------------------------------------------------
# Intro:
# Prevents players from opening multiple instances of your games.
#
# Features:
# Prevents Multiple Instances
# Custom File/Error
# XP/VX Compatible
#
# Instructions:
# Place as first script.
# Configure the 2 variables and thats all!
#
# Compatibility:
# Works with everything.
#
# Credits:
# game_guy ~ For creating it.
# ZenVirZan ~ For requesting it.
#===============================================================================

# Custom error message.
ERROR = "Instance already running."
# Custom file name, I'd recommend leaving the ENV[Appdata]
TOKEN_FILE = ENV['APPDATA'] + "game_name.token"

begin
  if FileTest.exists?(TOKEN_FILE)
    begin
      File.delete(TOKEN_FILE)
    rescue Errno::EACCES
      if !DEBUG && !$TEST
        msgbox ERROR
        exit
      end
    end
  end
  $token = File.open(TOKEN_FILE, "w")
end

Instructions

In script.

Compatibility

Works with everything.
XP/VX/VX Ace compatibility.

Credits and Thanks


Author's Notes

Prevent dem hackahs! >:U