Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: G_G on August 04, 2011, 08:52:05 am

Title: [XP][VX] One Game Instance
Post by: G_G on August 04, 2011, 08:52:05 am
One Game Instance
Authors: game_guy
Version: 1.0
Type: Cheating Prevention
Key Term: Misc System



Introduction

Was reading this thread. http://www.hbgames.org/forums/viewtopic.php?f=12&t=74963&start=0 The guy who resolved it made it way overcomplicated. I decided to make a smaller more compact version.

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


Features




Screenshots

N/A


Demo

N/A


Script

Place at very top!
Spoiler: ShowHide

#===============================================================================
# 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
       print ERROR
       exit
     end
   end
 end
 $token = File.open(TOKEN_FILE, "w")
end



Instructions

In script.


Compatibility

Works with everything.
XP/VX compatibility.


Credits and Thanks




Author's Notes

Prevent dem hackahs! >:U
Title: Re: [XP][VX] One Game Instance
Post by: Blizzard on August 04, 2011, 10:52:36 am
And the beauty of the script is that you can put it anywhere! :O
Title: Re: [XP][VX] One Game Instance
Post by: GamerGeeks on August 21, 2011, 09:44:25 am
i think i gonna need this for my RMX-OS server. Thanks!
Title: Re: [XP][VX] One Game Instance
Post by: Apidcloud on August 21, 2011, 10:09:16 am
Quote from: Blizzard on August 04, 2011, 10:52:36 am
And the beauty of the script is that you can put it anywhere! :O


Roflmao  :O.o:  :facepalm:  :uhm:

Great snippet g_g ^^
Title: Re: [XP][VX] One Game Instance
Post by: Blizzard on August 21, 2011, 11:15:43 am
No, seriously. This is a rare script that can be put anywhere in the script editor, the order doesn't matter.
Title: Re: [XP][VX] One Game Instance
Post by: Apidcloud on August 21, 2011, 11:38:51 am
lol, if it doesn't need any class that is on the editor, it can be used in everywhere(as you said previously) xD

A great script really =)
Title: Re: [XP][VX] One Game Instance
Post by: G_G on August 21, 2011, 12:35:56 pm
Thanks guys. :3 I don't think it can be placed under main though. It'll start the loop before it'll reach the script. Then when the loop ends it'll make a derp moment.
Title: Re: [XP][VX] One Game Instance
Post by: Apidcloud on August 21, 2011, 12:55:56 pm
I think you're entirely correct.
I ever heard that scripts under main won't work, although, as your script only uses 'begin' I think it won't be a problem even if it is placed under main.
Title: Re: [XP][VX] One Game Instance
Post by: G_G on August 21, 2011, 01:00:23 pm
It would be a problem. Main is a loop. When the game is ran, it loads scripts from top to bottom so its going to hit main before mine. When it hits main, it loops and updates $scene until it becomes nil. After that it would then hit  my script, then close. Thats what happens to any script put below main.
Title: Re: [XP][VX] One Game Instance
Post by: Apidcloud on August 21, 2011, 01:20:43 pm
XD thanks for explaining ^^
Title: Re: [XP][VX] One Game Instance
Post by: Blizzard on August 21, 2011, 01:39:27 pm
Scripts under main are run when you do a clean game exit (that means no "exit", no ALT+F4 and no pressing the X to close the window). Obviously you can put it wherever you want above main. :roll: