PLK_TroopsOnline
A downloadable rpgmaker mz
The trick requires a global time plugin to specify and enable/disable that activity.
The above time plugin, if the internet is lost, the game time will return to the default time, including preventing time modification.
If a player is disconnected from the game, the online status will remain for a certain amount of time, for example 60 seconds from the dungeon timer setting + 60 seconds of the trigger that works every 1 minute. The status will then be removed at that time, so there is no more waiting period. The video shows that if the online status is completely resolved, and the player who did nothing will immediately terminate the game.
✅ How to Use in Google Sheets
If the player is disconnected, the online status will remain for a set time, such as 60 seconds + 60 seconds of the trigger that works every 1 minute, and then it will be removed at that time.
- Create a new Google Sheet and set up the columns as above.
- Copy and paste the table data into the sheet.
- Ensure the
effects
column contains JSON strings (useJSON.parse()
). - Integrate the Google Sheets API with RPG Maker MZ using a plugin.
- Test the item functionality in the game. 🎮
- Set up important triggers
Copy Google Sheet to your own database
Open Extension Select app script Press Depoly button
New Deployment
Select type Select web app
Who has access Select Anyone
Press Depoly button Authorize access Select You Select Advanced Go to StorageSyncGoogle (unsafe) Allow
Web app
URL
https://script.google.com/macros/s/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Go to game plugin list
Select
PLK_TroopsOnline
Put URL here https://script.google.com/macros/s/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Once done, you can edit and change items from the sheet.
Caution It will load items by ID, if no ID is entered it will be blank. You can go to your own item settings to see it from the Games\Project\data\Troops This link will help you sort item values.
Column | Description |
id | A unique identifier for each troop. This is used to reference and look up specific troop data. |
members | A JSON string that represents the troop's members (e.g., enemy data and positions). |
name | The name of the troop (e.g., "Goblin", "Crow*2"). |
pages | A JSON string that represents the troop's battle pages (conditions, commands, etc.). |
note | A text field for additional notes or metadata related to the troop. |
online | This column is managed by the system to track the online status of the troop. It is updated automatically when a troop is marked as online or removed. |
Backend (Google Apps Script)
- Google Sheet Setup and Script Code:
- Prepare a Google Sheet with a header in the first row. The columns should be arranged in the following order:
id, members, name, pages, note, escape, online
- The id column is used for the troop number.
- The members and pages columns store data in JSON string format.
- The note column is for any notes.
- The escape column (if used) indicates whether the player is allowed to escape the battle.
- The online column is managed automatically by the system.
- Prepare a Google Sheet with a header in the first row. The columns should be arranged in the following order:
- Main Functions in the Script:
- validateTroopData(troopObj, requiredKeys):
Checks whether the troop object has all required keys. - sanitizeTroop(troopObj):
Processes a troop object by:- Verifying it contains the required keys.
- Converting the JSON strings in the members and pages fields into arrays.
- Storing a raw ID (rawId) for checking online status.
- doGet(e):
When a GET request is made, this function retrieves all troop data from the Google Sheet, converts it into a JSON array, and returns it. - doPost(e):
When a POST request is made, this function processes the payload. The payload must include an action and troopId.- For action
"setOnline"
:
It also accepts aduration
parameter (in seconds). The script calculates an expiry timestamp using the current time plus the duration (converted to milliseconds). It then writes a value in the online column in the format"online:<expiryTimestamp>"
. - For action
"removeOnline"
:
The function clears the online cell for the specified troop.
- For action
- clearExpiredOnlineStatus():
This function, which can be set up as a time-driven trigger (for example, every minute), loops through each row in the online column and checks if the stored expiry timestamp has passed. If it has, the online status is cleared for that row.
- validateTroopData(troopObj, requiredKeys):
Frontend (RPG Maker MZ Plugin)
- Plugin Manager Setup:
- Place the file PLK_TroopsOnline.js in the
js/plugins
folder of your game. - Open the Plugin Manager and set the DatabaseURL parameter to the URL of your deployed Web App from Google Apps Script.
- Place the file PLK_TroopsOnline.js in the
- Plugin Commands:
- ReloadTroopsDatabase:
This command sends a GET request to the Web App to retrieve the latest troop data from the Google Sheet and load that data into the game. - CheckOnlineStatus:
This command sends a POST request to the Web App to set the online flag for a troop.- You can optionally provide an argument
"id"
(if not provided, the current troop in the game is used). - You can also specify
"duration"
(in seconds) to indicate how long the online status should remain active (the default is 60 seconds). - When this command is executed, the request (including the duration) is sent to the Web App.
- If the response indicates that "There are already people online," a message is displayed and the battle will not start.
- If the online status is set successfully, the troopId and duration are saved in a global variable (
_battleCountdownData
), and the scene changes to Scene_Battle.
- You can optionally provide an argument
- ReloadTroopsDatabase:
- In Scene_Battle:
- When Scene_Battle is created (via the
createAllWindows
method), it checks the global variable_battleCountdownData
. - If this data exists, the scene creates a countdown window (using the custom
Window_BattleCountdown
class) that is displayed at the top-right corner of the battle screen (with a fixed height of 36 pixels and a width of 200 pixels). - The countdown window updates in real time (using the system clock via
Date.now()
or a similar mechanism) to show the remaining time (displayed as "Time left: X sec"). - When the countdown reaches zero, the window’s callback is triggered:
- A POST request is sent to remove the online status for the troop.
- A message "You're out of time to fight." is displayed.
- The scene then returns to Scene_Map, and the current map's BGM is restored.
- When Scene_Battle is created (via the
- Disconnect Handling:
- When the game window is closed or refreshed (using the
beforeunload
event), a beacon request is sent to the Web App to remove the online status of the currently active troop.
- When the game window is closed or refreshed (using the
How to Use the Plugin (Summary)
- Backend Setup:
- Deploy the provided Google Apps Script code as a Web App (set access to "Anyone, even anonymous").
- Ensure your Google Sheet’s header is set as:
id, members, name, pages, note, escape, online
- Set up a time-driven trigger (for example, every minute) to call
clearExpiredOnlineStatus()
. This will check each row and remove online statuses that have expired based on the stored expiry timestamps.
- Frontend Setup:
- Place PLK_TroopsOnline.js in the
js/plugins
folder of your RPG Maker MZ game. - In the Plugin Manager, set the DatabaseURL parameter to the URL of your deployed Web App.
- Use the ReloadTroopsDatabase command to load the troop data.
- Use the CheckOnlineStatus command to set the online flag before battle. Optionally, specify:
"id"
: The troop ID (optional; if not provided, the current troop is used)."duration"
: The countdown duration in seconds (default is 60 seconds).
- When the online status is set, the game will change to Scene_Battle. In Scene_Battle, a countdown window will appear at the top-right that updates every frame.
- When the countdown expires (reaches 0 seconds), the online status is automatically removed, a message "You're out of time to fight." is displayed, and the game returns to Scene_Map with the map’s BGM restored.
- If the player disconnects (closes or refreshes the game), a beacon is sent to remove the online status automatically.
- Place PLK_TroopsOnline.js in the
Using this plugin, your game will manage the online status of troops automatically both on the server side (via Apps Script) and on the client side (via the RPG Maker MZ plugin), ensuring that if a player disconnects or if the specified duration expires, the online status is cleared.
This explanation covers the setup and usage of the plugin in both the backend (Google Apps Script) and the frontend (RPG Maker MZ plugin).
Published | 1 day ago |
Status | Released |
Author | Palatkorn |
Tags | RPG Maker MZ |
Purchase
In order to download this rpgmaker mz you must purchase it at or above the minimum price of $10 USD. You will get access to the following files:
Leave a comment
Log in with itch.io to leave a comment.