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:
I have all the code shown here, but how do I add the page for them to access it? Is it the fishingview or fishingcontroller? Or do I need to do something else?
 
I have all the code shown here, but how do I add the page for them to access it? Is it the fishingview or fishingcontroller? Or do I need to do something else?
Your link would be something like yoursite.com/fishing if you have both the fishingview and controller in your site's files. If you want to add it to your menu you can do that in the admin CP or add a link on your index page :)
 
I have berryview.php and berrycontroller.php
  Spoiler: berrycontroller.php 

  Spoiler: berryview.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 berryview 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("Garden");
// Change the required amount of minutes in between fishing (less than 60)
if (($minutes - $mysidia->user->lastminuteberry) >= 5 || ($minutes - $mysidia->user->lastminuteberry) <= -5 || $mysidia->user->lastberryday != $today) {
$mysidia->db->update("users", array("berrycollected" => (0)), "username = '{$mysidia->user->getUsername()}'");
$mysidia->db->update("users", array("lastminuteberry" => $minutes), "username = '{$mysidia->user->getUsername()}'");
$mysidia->db->update("users", array("lastberryday" => $today), "username = '{$mysidia->user->getUsername()}'");
}

if ($mysidia->user->berrycollected < 1 && $required->inInventory()) {
$mysidia->db->update("users", array("berrycollected" => ($mysidia->user->berrycollected + 1)), "username = '{$mysidia->user->getUsername()}'");


// Image and text for when you successfully fish
$document->add(new Image(" ", "Lake"));
$document->add(new Comment("<br>You found something! It's", 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("Berry", $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 Berry!"));
$document->add(new Image("http://systemsocial.x10.mx/picuploads/png/288a115efa2c7e353617466a6cbd52f9.png", "Berry"));
} elseif ($ran >= 500 && $ran < 501) {
$ownedItem = new OwnedItem("Concept Artist Medal", $mysidia->user->getID());
$trueItem = new OwnedItem($ownedItem->getItemID(), $mysidia->user->getID());
$trueItem->add(1, $mysidia->user->getID());
$document->add(new Comment(" a Medal! Where did this come from?!!"));
$document->add(new Image("http://systemsocial.x10.mx/picuploads/png/c5d7912504f598736069d16ef3939b48.png", "Concept Artist Medal"));
} else {
// If the number generated was anything else, you caught nothing
$document->add(new Comment("...Oh, never mind. It was just a leaf...", FALSE));
}
} elseif ($required->inInventory()) {
// Image and text for when you've already fished in the past duration
$document->add(new Image(" ", "Lake"));
$timewait = $minutes - $mysidia->user->lastfishminute;
$document->add(new Comment("<br>You can't find anything. Maybe try searching a bit longer?<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(" ", "Lake"));
$document->add(new Comment("<br>You need a Basket in order to gather 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/3", "General Store?"));
}
}
}
?>

Did I at least do THIS part right?
 
Well, now systemsocial.x10.mx/berry just leads me to a white screen...
Do you have anything in your view file other than just:

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;

That could definitely lead to a white screen as it doesn't have any information on what to display. If you do, could you share the full view file and I can give it a shot to see if I can see anything up with it? The controller looks fine
 
Do you have anything in your view file other than just:

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;

That could definitely lead to a white screen as it doesn't have any information on what to display. If you do, could you share the full view file and I can give it a shot to see if I can see anything up with it? The controller looks fine
I figured out what I did. I didn't set the default values........
 
Okay. Sorry for so many questions. Now, my "Time Waited: {$timewait}" just produces the server time minute. It resets every hour, but I have the wait time between picking berries to be 5 minutes. Like right now, it says Time Waited: 53 minute(s) for example and like I don't think I changed anything. I'm just struggling lol
 
I'm getting this error:

Fatal error: Uncaught TypeError: Unsupported operand types: string - string in /home/pixellat/public_html/view/main/fishingview.php:26 Stack trace: #0 /home/pixellat/public_html/resource/core/frontcontroller.php(120): View\Main\FishingView->index() #1 /home/pixellat/public_html/index.php(78): Resource\Core\FrontController->render() #2 /home/pixellat/public_html/index.php(84): IndexController->run() #3 /home/pixellat/public_html/index.php(88): IndexController::main() #4 {main} thrown in /home/pixellat/public_html/view/main/fishingview.php on line 26
 
[28-Jan-2024 12:52:48 America/Boise] PHP Fatal error: Uncaught Error: Class 'Controller\main\gardenController' not found in /home4/kaleidx3/public_html/resource/core/frontcontroller.php:191

But I do have that controller, so a bit confused, also I changed fishing to Garden

so want to make sure I changed things correctly

1706472062867.png
 

Attachments

  • gardencontroller.php
    328 bytes · Views: 0
  • gardenview.php
    4.2 KB · Views: 0
I don't know how much it matters, but I think all the words should be uppercase

the error is showing: Controller\main\gardenController

but it should look like this: Controller\Main\GardenController

I'm not sure why it's doing that. Files themselves should be lowercase, like gardencontroller.php

function names should use camel case with first word being lower case and other words beginning with uppercase, like: public function getAdoptID()

and class names should uppercase the first letter of every word in the class name, like: Class GardenController extends AppController
 
Last edited:
I'm going to have to play with it more and maybe change it back to the original name ... then slowly make changes because now it's not even loading the page when I go to the garden where before I got the error/white page. Hurm, thanks for looking through and trying to help

edit: got it working under fishing, but even trying to change it to garden for the URL makes the page not load at all and go back to my index.

I'll take the win that I was able to convert everything /else/ over to the garden, users might laugh a little that they're going to a "fishing" URL to visit the garden but I'll take the loss until I can figure out why that little thing is being finicky at least the errors are gone and it seems to be working.
 
Last edited:
I'm getting this error:

Fatal error: Uncaught TypeError: Unsupported operand types: string - string in /home/ozthebro/public_html/view/main/fishingview.php:26 Stack trace: #0 /home/ozthebro/public_html/resource/core/frontcontroller.php(120): View\Main\FishingView->index() #1 /home/ozthebro/public_html/index.php(78): Resource\Core\FrontController->render() #2 /home/ozthebro/public_html/index.php(84): IndexController->run() #3 /home/ozthebro/public_html/index.php(88): IndexController::main() #4 {main} thrown in /home/ozthebro/public_html/view/main/fishingview.php on line 26
 
Similar threads

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,267
Messages
33,048
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top