03-24-2019, 03:33 AM (This post was last modified: 09-02-2024, 10:34 PM by DerVVulfman.)
Prevent Deactivation by KK20 Version: 1.1
* and Minor F12 fix added by DerVVulfman
Introduction
When the game window is no longer the active window, it normally freezes the game from updating. This script will allow games to still run in the background.
This feature makes it so your game stays active and continues to run, even if you bring up another window or program.
Features
Keeps the game running, even if you're running another program
Has options to turn on/off the prevention feature
Versions for Ruby 1.8 and newer Ruby 2.0+
Script
The version for Ruby 1.8+
Code:
=begin
================================================================================
Prevent Deactivation
Author: KK20
Version: 1.1
--------------------------------------------------------------------------------
[ Description ]
When the game window is no longer the active window, it normally freezes the
game from updating. This script will allow games to still run in the background.
[ Instructions ]
You can enable / disable this feature in-game using the script call:
$game_system.keep_game_active = true / false
This is useful for custom menu options so that the player can choose their
preference of whether the game runs in the background or not.
Script should be placed as low as possible in your script list, but still
above Main.
It is highly advised to not modify this script unless you know what you are
doing.
================================================================================
=end
module Input
class << self
if @intercept_f12_stack.nil?
alias update_if_game_in_focus update
@intercept_f12_stack = true
end
end
# Only accept player input if the game window is in focus
def self.update
update_if_game_in_focus if MessageIntercept::Flag_Deactivate[0] == 1
end
end
class Game_System
attr_reader :keep_game_active
alias init_for_no_deactivate initialize
def initialize
@keep_game_active = true
init_for_no_deactivate
end
# When loading a save, need to make DLL call to enable/disable keeping the
# game active
alias original_update_no_deactivate update
def self.modify_update(revert = false)
if revert
alias update original_update_no_deactivate
else
alias update no_deactivate_update
end
end
def no_deactivate_update
MessageIntercept::Toggle.call(@keep_game_active ? 1 : 0)
original_update_no_deactivate
Game_System.modify_update(true)
end
def keep_game_active=(bool)
@keep_game_active = bool
MessageIntercept::Toggle.call(@keep_game_active ? 1 : 0)
end
end
class Game_Temp
alias change_gamesystem_update_init initialize
def initialize
change_gamesystem_update_init
Game_System.modify_update
end
end
if MessageIntercept::Start.call('.\\Game.ini', MessageIntercept::Flag_Deactivate) == -1
raise 'ERROR: Prevent Deactivation failed to set new window procedure!'
end
Instructions
Mainly, place the .DLL attached in your project's root directory and paste the script just above main after all other custom scripts. Other instructions are in the script.
FAQ
This was searched for by DerVVulfman, the request at RPGMakerWeb.Com posted and found right (>HERE<)
Compatibility
Designed for the RPGMaker engines, with two versions based on which version of Ruby/RGSS your engine is using.
Credits and Thanks
This script was designed by KK20, and with thanks to Jaiden for the toggle on/off feature request.
Terms and Conditions
Due credit for both KK20 and Jaiden is required. Free for use in commercial projects.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)
It's weird to find no reason to double post the code here. Didn't you make any mistake, wulfo? O_o? Or has the original scripter lied to people hoping nobody would notice it?
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9
Maranatha!
The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.
03-24-2019, 06:32 PM (This post was last modified: 03-24-2019, 06:46 PM by DerVVulfman.)
I have done searches within the forum for key words of "KK20", "MessageIntercept", and "Deactivation". At no point do we have any thread or post that comes up. And as towards a search for the keyword of "Jaiden" who supplied a suggestion AND whom I've known for ten years since the old RMXP.Org days, no script posts were provided.
I have also performed a google searches for "MessageIntercept RPG" and "Deactivation RPG", so the returned list of viable links would only involve within RPGMaker forums for either the name 'Deactivation' or the MessageIntercept DLL file. No results were found.
If you are stating that this script already exists within this forum, please provide the link.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)
03-24-2019, 08:21 PM (This post was last modified: 03-24-2019, 08:24 PM by DerVVulfman.)
*ACK! I keep forgetting you go by that name in here!!!
And nope, that is not a double-post. There is a subtle difference between the two. Ruby 1.8 does not include the getbyte statement for the String class, so the 1.8 version contains the line:
Code:
update_if_game_in_focus if MessageIntercept::Flag_Deactivate[0] == 1
However, since the later versions of Ruby does have the getbyte statement, the newer version of the script instead contains the line:
Code:
update_if_game_in_focus if MessageIntercept::Flag_Deactivate.getbyte(0) == 1
This minor change was pointed out by KK20 as below:
KK20 at RPGMakerWeb Wrote:Oh right, forgot about that. You just use String#[] to get the byte. So it should be
Code:
update_if_game_in_focus if MessageIntercept::Flag_Deactivate[0] == 1
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)
The question would be if there's an actual need for two versions of the same script. I mean, isn't it enough to use either #[] or get_byte in both versions of Ruby. Who can confirm it? O_O
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9
Maranatha!
The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.
12-25-2020, 12:42 PM (This post was last modified: 12-25-2020, 01:11 PM by Rangnarok.)
(03-25-2019, 07:26 PM)Thank you for this Wrote: Thanks for this script. I am noob to RPG Maker, let alone Ruby. But this script is exactly what I needed.
I had to change a bit so the game still accepts input while the window is inactive. Luckily, the instructions in the file was clear enough for me to understand and commented that part out.
I tried with SpecialK to do what I need, but it didn't hook at all. Thank you again for this.
EDIT 2: It works :) I had to start a new game. I guess the old save file still uses the old script system somehow.
For those who is curious, I edited this part out so the game would still accept player input while the window is inactive (for controller)
Code:
# Only accept player input if the game window is in focus
# def self.update
# update_if_game_in_focus if MessageIntercept::Flag_Deactivate.getbyte(0) == 1
# end