Mys 1.3.4 Health and mood system + progress bars

Forum
Last Post
Threads / Messages
If your host allows cronjobs, you can just have a page with the tasks you want to perform and set it up through the cpanel ("I want this function from this file to run every day").

All the automatic tasks I've set up are basically like this:

PHP:
class CronController extends AppController{

	public function __construct(){

	}
	
	public function index(){

	}
	
	public function resetNotifs() {
		$mysidia = Registry::get("mysidia");
		$mysidia->db->delete("notifications", "Isread = '1'");
	}
	
	public function resetClicks() {
		$mysidia = Registry::get("mysidia");
		$now = new DateTime();
		$mysidia->db->delete("vote_voters", "date != '{$now->format('Y-m-d')}'");
	}
	
	public function resetBiomes() {
		$mysidia = Registry::get("mysidia");
		$mysidia->db->delete("generatedadoptables", "1");
	}
	
}

But this depends on if your host allows cronjobs.

To do it like HoF is saying, you can create a class file for each task you want. For example ResetClicksTask, LowerMoodTask, ... (which can extend a class Task, if you want inheritance)
Each task class has a function like executeTask() that does what you want. In this case it would be like

PHP:
class ResetClicksTask extends Model{ //or extends Task
	
       public function __construct(){
       }

	public function executeTask() {
		$mysidia = Registry::get("mysidia");
		$now = new DateTime();
		$mysidia->db->delete("vote_voters", "date != '{$now->format('Y-m-d')}'");
	}
	
}

Then from the index.php file, you can create a function that checks if any task from the database can run, like

PHP:
$mysidia = Registry::get("mysidia");
$tasks = $mysidia->db->select("tasks", array("id", "name", "executiontime", "waittime"), "...");

while($task = $tasks->fetchObject()) {
        if($currenttime >= $task->executiontime) {
              $taskName = $task->name . "Task"; //so it looks like ResetClicksTask
              $taskToRun = new $taskName();
              $taskToRun->executeTask();//run the execute function
              //update the next exe time
              $newexetime = $task->executiontime + $task->waittime;
              $mysidia->db->update("tasks", array("executiontime" => $newexetime), "id = '{$task->id}'");
        }
}


So when anyone visits the index, the function calls all the tasks that need to run.
 
Okay, so this is what I have in cron.php within the root folder:
PHP:
class CronController extends AppController{

    public function __construct(){

    }
    
    public function index(){

    }
    
    public function lowerMood() {
        $mysidia = Registry::get("mysidia");
        $mysidia->db->update("owned_adoptables", array("mood" => -10));
    }
    
    public function lowerHealth() {
        $mysidia = Registry::get("mysidia");
        $mysidia->db->update("owned_adoptables", array("health" => -10));
    }
    
}

And this is what my cronjob command is:
php -f /home/adopttes/public_html/cron.php
I'm not sure if my command or setup is correct though, since it doesn't work.
 
Last edited:
As a better alternative to my method above, would it be possible to have something like mySQL events? They're said to be able to be an alternative to cronjobs and I have seen options for this in phpMyAdmin, but I've never touched them. I'll try it and see how it works out.

EDIT: Nevermind, you would need super privileges in mySQL to make schedules (basically add permission), which I can't find a way to do.
 
Last edited:
Just a heads up, if you haven't already done it for another mod et cetera, you'll need to define $adopt in public function manage. Copying it from the function above it seems to be enough.
 
I can't seem to get the provided method for changing the health to work. It's all set in class_ownedadoptables, although I'm trying to do this outside the manage page.
EDIT: Never mind. I dug through my files and it turned out to be a typo in what I was using to track health.
 
Last edited:
Can items be used to increase health or mood?

OK, so I'm trying to get this to work, and I would REALLY APPRECIATE if anyone in here could share whatever magic trick it takes to use an item to restore health. All I get is a white screen, every time.
 
Ok, I made my own health system so I cannot garauntee that this will work, but here is my item function for health increasing items:
PHP:
 function items_health($item, $adopt){
  $mysidia = Registry::get("mysidia");
  $health = $mysidia->db->select("owned_adoptables", array("health"), "aid ='{$adopt->aid}'")->fetchObject();
  $addHealth = $adopt->health + $item->value;
      //Check if the adoptable's health is already at maximum.    
  if($adopt->health >= 100){
    $note = "Your pet is already fully healed! The {$item->itemname} was not used.";
  }
  //Not at maximum, but don't go overboard!
  elseif($addHealth > 100){
    $mysidia->db->update("owned_adoptables", array("health" => 100), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
    $note = "The {$item->itemname} fully healed your pet!";
    $delitem = $item->remove();
  }
  //Not at maximum, won't go overboard. Proceed.
  else{
    $mysidia->db->update("owned_adoptables", array("health" => $addHealth), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
    $note = "The {$item->itemname} raised your pet's health by {$item->value}! Their health is now at {$addHealth}.";
    $delitem = $item->remove();
  }
  return $note;
}

(also need to edit classes/class_privateitem, and add the function in the database)
 
just want to point out that the progress bar dont work in all the browsers, specially old ones, to "fix" this you need to create a div like progress bar :
https://css-tricks.com/html5-progress-element/ <-- there you will find the "fix" for that =)
in short you just need to add the css codes to your style.css and call them with the div:
PHP:
<progress max='100' value='{$health}'>
    <div class="progress-bar">
        <span style='width: 80%;'>Progress: 80%</span>
    </div>
</progress>
just replace the 80% with the {$health} or the status you created and you need to add max-width: 100px(or the max value of the status); to the .progress-bar > span {

you might need to remove 1 or 2px from the max-width... sometimes the filled bar gets out of the container by that.
 
Epic Mod.

Thanks to all who worked so hard on this. I have it installed, so far so good, will make goodies to bring mood and health up tonight or tomorrow!
 
Has anyone ported this to 1.3.6? I'm trying but I don't understand how to call variables from the database evidently... This is what I was trying to do, but it's showing a full progress bar, regardless of what the health value is in the database.
1699929493835.png
 
Has anyone ported this to 1.3.6? I'm trying but I don't understand how to call variables from the database evidently... This is what I was trying to do, but it's showing a full progress bar, regardless of what the health value is in the database.

I just had a crack at it and managed to get it working for you :) First, you don't need to use $mysidia->owned_adoptables->health to grab the value. $ownedAdopt is already called just above it so you can actually just use $ownedAdopt->getHealth() if you assigned getHealth in the model.

But instructions lol (I only added health as mood is just a copy)

1) Add health to the DB as in the original post.

2) Open model/domainmodel/ownedadoptables.php. Put this with the other protected functions:

PHP:
public $health;

3) Then put these with the other functions further down, where you call the name and stuff:

Code:
public function getHealth(){
        return $this->health;
    }

    public function setHealth($health, $assignMode = ""){
        if($assignMode == Model::UPDATE) $this->save("health", $health);
        $this->health = $health;
    }

4) Then open myadoptsview.php. Scroll down to the manage function and add this:

PHP:
$health = $ownedAdopt->getHealth();
        $addHealth = $ownedAdopt->getHealth() + 10;
        $subtractHealth = $ownedAdopt->getHealth() - 10;

Make sure it goes underneath this line:

PHP:
$ownedAdopt = $this->getField("ownedAdopt");

5) Then to display the progress bar, you'd use:

PHP:
$document->add(new Comment ("Health: <progress max='100' value='{$health}'></progress><br>"));

6) Make sure to make the CSS file and add a link to it in your theme header.tpl files. I know you have multiple themes so make sure to add a link for all of them. I recommend maybe making a general CSS file that they all link to if they need common css instead of making one JUST for the progress files, to prevent you having to add new files to every single one all the time lol.

Should look something like this when done (health is at 50):

2023-11-14 02_48_44-Mysidia Adoptables v1.3.6 and 10 more pages - Personal - Microsoft​ Edge.png
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,119
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Top