MV Request: If the internet is on, it earns gold.

Warrior_Corporation

Razek Games
Veteran
Joined
Apr 17, 2018
Messages
44
Reaction score
6
First Language
Português
Primarily Uses
RMMV

Hello everyone!


I think this request will not be difficult to do.

What I need is a plugin / line of code, which if the player is connected to the internet, he will earn X Gold per Minute, then for example: every minute I will earn 20 of Gold because my internet is connected:

If the internet is on, every 1 minute earns an x amount of gold.
If the internet is turned off, the player will not win anything.


[It will be an incentive to play with internet connected and player and earn gold and show the developer ad]

If it is some line of code that tells me where to put it, I have no scripting experience.

Sorry for English, I'm using google translate so there may be errors in the request.
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
You can add this as a plugin anywhere in your Plugin Manager. I didn't test it, but it should work fine.

Code:
(function() {
var GOLD_GAIN_AMOUNT = 20; //how much gold
var GOLD_GAIN_INTERVAL = 60000; // how many mili seconds for each interval
Utils.rewardPartyGold = function() {
   if ($gameParty && navigator.onLine) {
      $gameParty.gainGold(GOLD_GAIN_AMOUNT);
   }
};

Utils.setGoldInterval = function() {
   window.setInterval(Utils.rewardPartyGold, GOLD_GAIN_INTERVAL);
};

var old_commandNewGame = Scene_Title.prototype.commandNewGame;
Scene_Title.prototype.commandNewGame = function() {
    old_commandNewGame.call(this);
    Utils.setGoldInterval();
};

var old_onLoadSuccess = Scene_Load.prototype.onLoadSuccess;
Scene_Load.prototype.onLoadSuccess = function() {
    old_onLoadSuccess.call(this);
    Utils.setGoldInterval();
};
})();
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,212
First Language
Binary
Primarily Uses
RMMZ
navigator.onLine only works if the computer doesnt have a virtual machine installed. just a small caveat, but one to note. :)
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,370
Reaction score
7,678
First Language
German
Primarily Uses
RMMV
do you have a server on the net?
as said above any pure local check for the internet can be circumvented with virtual machines or a few other ways.

the only way to check for a guaranteed connection is to check for something you placed on the internet, and that means you'll need a server or at minimum a hosted website - which usually has monthly costs.
 

LTN Games

Indie Studio
Veteran
Joined
Jun 25, 2015
Messages
704
Reaction score
631
First Language
English
Primarily Uses
RMMV
If you know coding you can use my basic method for checking for web access. It simply checks if it recieves a response from a web URL you put in, if it does then your connected otherwise it's not. How often is google not online? Not often so you can check if the player can connect to google.

If I had time I would show you how to use it and I would make this function so you can place it in a plugin but I'm currently really busy. P.S only works with 1.6.1unless you change it from an asynchronous function to a normal one. Sorry I can't be more of a help.

https://fenixenginemv.gitlab.io/fenix-tools/File_hasWebAccess.js.html
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
Yes, that seems like a better idea. If you're on v1.5 you can use the Fetch API and Promises to ping a reliable url like Google/Facebook/etc., just can't use the "async" and "await" keywords unless on v1.6+.

Code:
(function() {
var GOLD_GAIN_AMOUNT = 20; //how much gold
var GOLD_GAIN_INTERVAL = 60000; // how many mili seconds for each interval
Utils.checkInternetAccess = function() {
   return fetch('https://www.google.com');
};
Utils.rewardPartyGold = function() {
    Utils.checkInternetAccess()
    .then(function(res) {if (res.ok && $gameParty) {           
        $gameParty.gainGold(GOLD_GAIN_AMOUNT)
    }})
    .catch(console.error('Not connected to the internet.'))
};

Utils.setGoldInterval = function() {
   window.setInterval(Utils.rewardPartyGold, GOLD_GAIN_INTERVAL);
};

var old_commandNewGame = Scene_Title.prototype.commandNewGame;
Scene_Title.prototype.commandNewGame = function() {
    old_commandNewGame.call(this);
    Utils.setGoldInterval();
};

var old_onLoadSuccess = Scene_Load.prototype.onLoadSuccess;
Scene_Load.prototype.onLoadSuccess = function() {
    old_onLoadSuccess.call(this);
    Utils.setGoldInterval();
};
})();
 
Last edited:

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,212
First Language
Binary
Primarily Uses
RMMZ
You have to contact a server that has CORS enabled. else the reply is an error. :)
 

LTN Games

Indie Studio
Veteran
Joined
Jun 25, 2015
Messages
704
Reaction score
631
First Language
English
Primarily Uses
RMMV
Yea forgot to mention that you need CORS enabled, I actually forgot myself, it's been so long since I've had to do net stuff. Well not a huge deal if you your own server, other than that I'm not sure what you can do.
 

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
For whatever reason, CORS is not an issue on nw.js deployments (see screenshot of testplay).

Not sure about mobile deployments.
However, OP didn't specify the deployment type so can't be sure.
 

LTN Games

Indie Studio
Veteran
Joined
Jun 25, 2015
Messages
704
Reaction score
631
First Language
English
Primarily Uses
RMMV
Excellent! Either way there are many free options out there to setup a server for something as simple as this anyways. Good luck @Warrior_Corporation
 

Warrior_Corporation

Razek Games
Veteran
Joined
Apr 17, 2018
Messages
44
Reaction score
6
First Language
Português
Primarily Uses
RMMV
I tested it on my computer and it worked, but the goal of these plugins is Android, I will test and see if it works on Android. I used that first code.
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,212
First Language
Binary
Primarily Uses
RMMZ
Excellent! Either way there are many free options out there to setup a server for something as simple as this anyways. Good luck @Warrior_Corporation
Please do advise me to the free service that can host a server that is always able to reply in a suitable amount of time ? I'd quite like to investigate that further. :)

The CORS thing isnt an issue for nwjs? why? thats really strange!! cors is a part of the modern standards, nwjs shouldnt be able to just bypass it.
 

LTN Games

Indie Studio
Veteran
Joined
Jun 25, 2015
Messages
704
Reaction score
631
First Language
English
Primarily Uses
RMMV
Firebase and Heroku are free. They're not quite servers in the way of having full control, but they provide an API to communicate with and with that API I'm sure with a clever enough dev, they can find a way to ping it and check for internet connection.

I would also recommend DigitalOcean while its not free 5$ a month for full control over your own server is awesome and well worth what they give you.
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,212
First Language
Binary
Primarily Uses
RMMZ
Ill certainly look into digital ocean and firebase..

ATM I use heroku, its certainly not free anymore. Their free plan turns your server off after 30 minutes of inactivty, and it has like, a 20 second restart time.. This causes major delays in api requests, most well programmed ones would likely timeout.It also has to sleep 8 hours a day im sure.

Heroku costs $7 per month, per dyno, if you want your app to run continuously, and have ssl encryption. It then costs an absolute fortune if you want to have any kind of database integration. I've been looking for a good alternative :D
 

LTN Games

Indie Studio
Veteran
Joined
Jun 25, 2015
Messages
704
Reaction score
631
First Language
English
Primarily Uses
RMMV
Yikes! I never knew about Heroku changing so much, it used to be half decent. I used DigitalOcean and I really enjoyed it, they give you a server with whatever OS you want, I chose Ubuntu due to familiarity and it was rather easy to get setup, they have a ton of tutorials and guides too.
Firebase I only played around with, I have no idea what the usage limits are but it too is easy to get get started and they have database, cloud services, and authentication straight out the box, makes things easy for app developers. Happy hunting!
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,212
First Language
Binary
Primarily Uses
RMMZ
Yea, heroku used to be decent, as did openshift, but the market seems to have changed alot in the past few years and they can get away with offering total crap free plans :D

I may actually test out DigitalOcean. I do remember looking into them and going with heroku because of their transfer limit. From the way it seems, they basically give you a private vm that you can access via the cloud? Its quite interesting either way. Definitely need to check if out some more :D
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

"You can thank my later", "But you haven't done anything", "Well, that's why ..."
Are we allowed to post about non-RPG Maker games?
I should realize that error was produced by a outdated version of MZ so that's why it pop up like that
Ami
i can't wait to drink some ice after struggling with my illness in 9 days. 9 days is really bad for me,i can't focus with my shop and even can't do something with my project
How many hours have you got in mz so far?

Forum statistics

Threads
105,884
Messages
1,017,240
Members
137,609
Latest member
shododdydoddy
Top