Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Mys v1.3.x Mods (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=42)
-   -   Mys v1.3.4 Health and mood system + progress bars (http://www.mysidiaadoptables.com/forum/showthread.php?t=5263)

ffsharriet 01-15-2017 06:05 PM

Can items be used to increase health or mood?

Dinocanid 01-15-2017 06:20 PM

It's definitely possible, but I've never attempted it so I don't know the code.

Dinocanid 01-21-2017 02:17 PM

Still need help with scheduled tasks to make the bars go down, since I'm still lost on what to do.

IntoRain 01-21-2017 05:03 PM

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 Code:

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 Code:

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 Code:

$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.

Dinocanid 01-21-2017 05:10 PM

Thank you! I'll have to try it out right now. I'm using mysidiahost, so it allows cronjobs.

Dinocanid 01-21-2017 05:57 PM

Okay, so this is what I have in cron.php within the root folder:
PHP Code:

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:
Quote:

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.

Dinocanid 04-02-2017 03:50 PM

I added a section for having the needs to go down every day.

Dinocanid 04-15-2017 09:43 AM

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.

KatFennec 04-28-2017 04:16 AM

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.

KatFennec 05-02-2017 11:54 PM

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.


All times are GMT -5. The time now is 10:18 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.