Online save backup using events
Hello ^^ I've been working on this online save backup system for quite some time now. It turned out pretty good and it's highly customizable since it is fully evented.Want a demonstration?
Spoiler: Making backups
Yes, I know proceed is spelled wrong here btw. The Account.txt file is auto generated for verification purposes. Without this file, if anyone enters a name and password that isn't contained in your dev's dropbox, they'll get the 'account exists' message (in the 'Yes, I have an account' choice) but files won't get uploaded or downloaded. That's why it was important for me to create this file. The event checks if this account.txt file exists or not in the dropbox folder and then goes on to say if account truly exists or not.
Spoiler: Loading backups
https://forums.rpgmakerweb.com/attachments/load-gif.149202/
Before I get to the explanations, there's some things you should know:
What is this?
-->This is an evented system through which the players can backup their saves in the developer’s dropbox and retrieve them again when needed.
Why Dropbox?
-->Because I could actually wrap my head around their api. Google drive also has an api but I couldn't understand anything no matter how much I browsed the web for answers. And me being a non-programmer definitely doesn't help. But can you use google drive? Obviously. But honestly, I really hope someone would make a plugin for something like this. Eventing this was toughhh.
Who is this for?
-->People like me… who don’t understand codes and stuff and simply can’t use this plugin right here: https://forums.rpgmakerweb.com/inde...ger-simple-cloud-based-savegame-system.57750/ (If you can, please consider using this plugin. Because making this system work is tedious. Don't proceed if you don't want to go through a lot of trial and error.You have been warned.)
Why would you need to use this?
-->Well… because you can? XD Honestly, I don’t think it’s such a big requirement since it’s not cross platform (it’s only for desktop). But I spent quite some time on this (a lot actually… because I’m lifeless and I sort of enjoyed the process
data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7) so I’m making a tutorial regardless ✧*。٩(ˊᗜˋ*)و✧*。
But seriously- If a player forgets to backup their saves and they lose the files for whatever reason, they can get them back. This also works if the game is on different computers.
And it doesn’t have to be saves. You can get any other information from the player like a survey. Or maybe a report to see how far they got in the game. As it reads text contents, you can make the game save Player’s info like level, play time, achievements, whatever you want to know about in to a txt file so it gets uploaded to you. I don’t know about other people but I will certainly find it amusing to know how my players are doing ^^
It might work for browser deployment too but I’m not that smart to figure it out. Maybe someone else can utilize this and make a plugin that offers that function.
-----------------------***------------------------
Well, now that you know if you should use this, let's get to the actual tutorial.
Requirements:
A Dropbox account
-Setting up your Dropbox account-
If your existing dropbox account has decent amount of space, you don’t need a new account since we’re just going to store written content (.txt, .rpgsave, .json etc.) and they're fairly small in size. Consider making a separate dropbox account if you think your remaining space isn’t enough.
Go to https://www.dropbox.com/ and make an account if you want a new one. Or skip to the next step if you already have one.
Go to https://www.dropbox.com/developers/apps and click create an app.
Select the following options:
Spoiler
Hit create app
Next, you’ll be taken to a new page with a bunch of settings.
Under the permissions tab,
Tick files.content.read and files.content.write. These are the only ones we’ll need.
Remember to click submit!
Spoiler
Under the settings tab,
Click generate access token. You’ll be given a looong random string. You’ll need that so copy it somewhere or it will disappear and you’ll need to generate a new one.
Set Access Token expiration to No expiration.
Spoiler
We’re done with the dropbox part.
-Eventing-
Uploading files:
Make a section where you ask the player for their name and password. You can use the Name Input scene for this or any of these plugins here:
SpoilerText Input Window
I'm working on a script for making Input Scenes, it's mostly done here Terms of use: Free for Commercial and free use as long as I get some credit for the script. How to use: Screenshot Changelog: Download Bugs: ToDo: You can...
forums.rpgmakerweb.com
https://img1.daumcdn.net/thumb/R800x0/?scode=mtistory2&fname=https%3A%2F%2Ft1.daumcdn.net%2Fcfile%2Ftistory%2F2458683E57A8E97402
Keyboard Input Dialog - RPG Maker MV
Introduction This plugin is a Text Input System that allows you to enter various languages such as Korean, Chinese, Arabic, Japanese, and Russian. Screen shots ë보기 Its result is returned with specific variable when you are pressed Enter key. So you can add its sentences using the text code...
biud436.tistory.com
https://raw.githubusercontent.com/krmbn0576/mosimosido/master/js/plugins/111_InputForm.js
Here, I’m using name_password as the folder name. You might not even need a password but a name along with a password makes the combination stronger. This way players can’t access another player’s folder. If my name is HyouryuuNa and my password is iloveprocrastinating~, then my folder name is HyouryuuNa_ iloveprocrastinating~. Unique enough? Yes. What you do here is up to you. You can ask whether the player has a profile. If they do, you ask if they want to load saves. If they don’t have a profile, you can ask whether they’d like to make one. Basically, you can event this part in any way you like.
I’m making the game upload the save file every time the player saves. For this you’ll need Caethyril’s Save Load Switch plugin
(Thank you so much for taking my request Caethyril!)
Get the plugin here: https://forums.rpgmakerweb.com/index.php?threads/caethyrils-plugins.106255/
Set the plugin parameters. I’ve set the save switch to 1 and the save Id variable to 4.
Now let’s create the save common event. Every time the player saves, the game will upload the save file to the dropbox account. We use the save switch defined in the plugin parameter (it's 1 in my case) and set the trigger to parallel.
I’ve used this script (Unfortunately I couldn’t find the original source(s) of this snippet. But anyways, thank you strangers. Because seriously, putting this together was really tough for someone with no coding experience like me. I had to browse through numerous threads because one answer didn’t have the whole thing. Oh and you guys will probably need to squish it so it fits the 12 line script space -_-):
Spoiler: Single Save Script JavaScript:
var xhr = new XMLHttpRequest();xhr.open("GET", "save/file" + $gameVariables.value(4) + ".rpgsave", false); //Reads the save file's contents. Variable 4= Save ID. //You should change the path to www/save/... for after deployment.xhr.send(null);var fileContent = xhr.responseText;var path = "/" + $gameVariables.value(1) + "_" + $gameVariables.value(2) + "/file" + $gameVariables.value(4) + ".rpgsave";//Variable 1= name and variable 2= password. Here, the folder name is name_password. You can make it name+password, name*password, name&password or simply namepassword lmaovar accessToken = "<Your Access Token here, without the angle brackets>";var uploadUrl = "https://content.dropboxapi.com/2/files/upload"; //Do not change thisvar result;var xhr = new XMLHttpRequest();xhr.onreadystatechange = function() { if (xhr.readyState === 4) { result = xhr.responseText; //console.log(result); }};xhr.open("POST", uploadUrl, true);xhr.setRequestHeader("Authorization", "Bearer " + accessToken);xhr.setRequestHeader("Content-type", "application/octet-stream");xhr.setRequestHeader('Dropbox-API-Arg', JSON.stringify({ path: path, mode: 'overwrite', autorename: true, mute: false}));xhr.send(fileContent);
Spoiler: In editor
Remember to turn the switch off or it will keep on running and you don’t want that.
Writing multiple files:
And I’ve made a ‘Save multiple’ common event too. This is useful when the player decides to upload all saves that has been made beforehand… when they didn’t have a profile. This doesn’t need a switch. Simply call it when the player chooses ‘backup saves’ or something like that.
Spoiler: Multiple Save Script JavaScript:
for (checker = 1; checker <= 5; checker++) { //Replace 5 with your maximum save file number var xhr = new XMLHttpRequest(); const fs = require("fs"); if (fs.existsSync("save/file" + checker + ".rpgsave")) { xhr.open("GET", "save/file" + checker + ".rpgsave", false); //You should change the path to www/save/... for after deployment. xhr.send(null); var fileContent = xhr.responseText; var path = "/" + $gameVariables.value(1) + "_" + $gameVariables.value(2) + "/file" + checker + ".rpgsave"; //Var 1=name, var 2=password var accessToken = "<Your Access Token here, without the angle brackets>"; var uploadUrl = "https://content.dropboxapi.com/2/files/upload"; //Do not change this var result; var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState === 4) { result = xhr.responseText; //console.log(result); } }; xhr.open("POST", uploadUrl, true); xhr.setRequestHeader("Authorization", "Bearer " + accessToken); xhr.setRequestHeader("Content-type", "application/octet-stream"); xhr.setRequestHeader('Dropbox-API-Arg', JSON.stringify({ path: path, mode: 'overwrite', autorename: true, mute: false })); xhr.send(fileContent); } else {}}
Reading files:
I swear, this part had me banging my head against the pillow. I don’t want to get hurt ( ≧Д≦).I managed to make it work… but with the help of two variables. I wanted to do this without any game variables at all but for loop was not working and I had to step outside the little script call space.
Spoiler: Load Script JavaScript:
var path2 = "save/" + $gameVariables.value(11); //var 11= the ID of the save file. Saves in the 'save' folder. Change it to www/save/ for after deploymentvar path = "/" + $gameVariables.value(1) + "_" + $gameVariables.value(2) + "/" + $gameVariables.value(11); //var 1= name, var 2 = passwordvar token = "<Your Access Token here, without the angle brackets>";var url = "https://content.dropboxapi.com/2/files/download"; //as usual, don't change the url pleasevar result;var xhr = new XMLHttpRequest();xhr.onreadystatechange = function() { if (xhr.readyState === 4 && xhr.status != 409) { result = xhr.responseText; var fs = require('fs'); fs.writeFile(path2, result, function(err) { if (err) throw err; console.log(result); }); } else if (xhr.status == 409) { $gameVariables.setValue(12, $gameVariables.value(12) + 1) //when save files are missing, simply ignore them and continue forward }};xhr.open("GET", url, true);xhr.setRequestHeader("Authorization", "Bearer " + token);xhr.setRequestHeader('Dropbox-API-Arg', JSON.stringify({ path: path}))console.log(JSON.stringify({ path: path}));//console.log(path2 + " " + result);xhr.send();
Spoiler: In editor
I guess we’re done with all the basic stuff. The rest is up to your creativity. You can use the save and load script in combination to create any type of 'menu' you want.
Don't hesitate to ask me if you have any questions ^^ Though I don't have much coding knowledge, I'll try to help. Have fun eventing ^^
本贴来自国际rpgmaker官方论坛作者:Sodium89处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/online-save-backup-using-events.123361/
页:
[1]