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

● ARCHIVED · READ-ONLY
Started by Warrior_Corporation 16 posts View original ↗

  1. 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.
  2. 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();
    };
    })();
  3. navigator.onLine only works if the computer doesnt have a virtual machine installed. just a small caveat, but one to note. :)
  4. 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.
  5. 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
  6. 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();
    };
    })();
  7. You have to contact a server that has CORS enabled. else the reply is an error. :)
  8. 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.
  9. 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.
    Spoiler

    L90n6uc
  10. 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
  11. 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.
  12. LTN Games said:
    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.
  13. 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.
  14. 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
  15. 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!
  16. 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