Mys 1.3.6 Gathering/Fishing Every X Minutes Game

Forum
Last Post
Threads / Messages

clay

Member
Member
Joined
May 2, 2023
Messages
8
Points
3
Age
27
Mysidian Dollar
158
Credit for the daily counter script idea goes to Dinocanid, because I would have been lost on how to emulate the daily checking mechanism without their health & mood bar system script! 😅

Edit 7/20/23: Now, items granted by this script will stack properly in user inventories instead of creating their own individual stacks every time an item is generated.

This script works for a gathering game every X minutes and can require an item (like a Fishing Rod or a Basket) to access the page, I use it on my site for both fishing and berry harvesting right now. We're going to use fishing as an example, but replace the terminology as necessary for whatever game you're going for! Just be sure your variables match up.
It does have some issues, namely you have to refresh the page once in order to get it to work (like the warning on the page says), and sometimes the "time waited" is calculated as a negative number because it rolls over past 60 minutes. (At least I think that's what's happening...)
But anyway, here's how to install it! It works on my site and I've tested it fairly thoroughly past those issues! This is my first time uploading a mod so I hope I didn't forget anything. :el:

  Spoiler: Fishing Screenshots 
XTXQMel.png
KQeAcci.png


Okay, first you'll need to edit the database and add these variables to the adopts_users table somewhere after "friends". (For berry harvesting, I named these variables lastberryday, lastberryminute, and berrycollected.)
VKPhu6b.png


Now, we create the controller page in controller/main. Title it fishingcontroller.php (or whatever's appropriate). Here's the code for you to copy+paste there:
PHP:
<?php

namespace Controller\Main;
use Resource\Core\AppController;
use Resource\Core\Registry;

class FishingController extends AppController {
    public function __construct() {
        parent::__construct("member");
    }
    public function index() {
        $mysidia = Registry::get("mysidia");
    }
}
?>

Now navigate to view/main and create fishingview.php. Here's your base code! Just change where the code comments are and you're good to go! Be sure the items actually exist in your database, and start handing out those gathering game prizes~ You're free to use the images that come with this code, by the way. :meow:
PHP:
<?php

namespace View\Main;
use Controller\Main;
use Model\DomainModel\Item;
use Model\DomainModel\Member;
use Model\DomainModel\OwnedItem;
use Resource\Core\Registry;
use Resource\Core\View;
use Resource\GUI\Document\Comment;
use Resource\GUI\Component\Image;
use Resource\GUI\Component\Link;

class FishingView extends View {
    public function index() {
        $mysidia = Registry::get("mysidia");
        $document = $this->document;
        // Put the item ID (found on adopts_items table) of your required Fishing Rod here
        $required = new OwnedItem(25, $mysidia->user->getID());
        $minutes = date("i");
        $today = date("d");
      
        // The page title of your fishing page
        $document->setTitle("Fishing");
        // Change the required amount of minutes in between fishing (less than 60)
        if (($minutes - $mysidia->user->lastfishminute) >= 5 || ($minutes - $mysidia->user->lastfishminute) <= -5 || $mysidia->user->lastfishday != $today) {
            $mysidia->db->update("users", array("hasfished" => (0)), "username = '{$mysidia->user->getUsername()}'");
            $mysidia->db->update("users", array("lastfishminute" => $minutes), "username = '{$mysidia->user->getUsername()}'");
            $mysidia->db->update("users", array("lastfishday" => $today), "username = '{$mysidia->user->getUsername()}'");
        }
       
        if ($mysidia->user->hasfished < 1 && $required->inInventory()) {
            $mysidia->db->update("users", array("hasfished" => ($mysidia->user->hasfished + 1)), "username = '{$mysidia->user->getUsername()}'");
           
           
            // Image and text for when you successfully fish
            $document->add(new Image("https://i.imgur.com/63w1qAx.png", "Lake"));
            $document->add(new Comment("<br>Something's on the line!! You reel it in, and up comes", FALSE));
            $ran = rand(1,1000);
            if ($ran < 500 && $ran > 0) {
                // Change the name of the item you're generating (make sure it exists in your database!)
                $ownedItem = new OwnedItem("Worm", $mysidia->user->getID());
                $trueItem = new OwnedItem($ownedItem->getItemID(), $mysidia->user->getID());
                // ...and change the quantity, if you wish
                $trueItem->add(1, $mysidia->user->getID());
                // Be sure to update the image and text
                $document->add(new Comment(" a Worm!"));
                $document->add(new Image("https://i.imgur.com/grhw2Xn.png", "Worm"));
            } elseif ($ran >= 500 && $ran < 501) {
                $ownedItem = new OwnedItem("Treasure Chest", $mysidia->user->getID());
                $trueItem = new OwnedItem($ownedItem->getItemID(), $mysidia->user->getID());
                $trueItem->add(1, $mysidia->user->getID());
                $document->add(new Comment(" a Treasure Chest! What a lucky catch!!"));
                $document->add(new Image("https://i.imgur.com/UxPXmFx.png", "Treasure Chest"));
            } else {
                // If the number generated was anything else, you caught nothing
                $document->add(new Comment("...oh, never mind, it got away...", FALSE));
            }
        } elseif ($required->inInventory()) {
            // Image and text for when you've already fished in the past duration
            $document->add(new Image("https://i.imgur.com/dFoL1Nc.png", "Lake"));
            $timewait = $minutes - $mysidia->user->lastfishminute;
            $document->add(new Comment("<br>Nothing's biting, maybe you should wait a bit longer before pulling your line in?<br>(Tip: You might have to refresh once you've waited long enough, sorry!)<br><b>Time waited:</b> {$timewait} minute(s)", FALSE));
        } else {
            // Image and text for when you don't own a fishing rod
            $document->add(new Image("https://i.imgur.com/dFoL1Nc.png", "Lake"));
            $document->add(new Comment("<br>You need a Fishing Rod in order to fish here! Why don't you purchase one from the ", FALSE));
            // Link to a store where you can buy a fishing rod
            $document->add(new Link("shop/browse/1", "General Store?"));
        }
    }
}
?>
 
Last edited:
Similar threads

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,229
Messages
32,687
Members
1,593
Latest member
Dracadia
BETA

Latest Threads

Top