Mys 1.3.4 Simple NPC Battle

Forum
Last Post
Threads / Messages
Hi again....... :/
So, My code works fine until I try to fetch the favpet data........
PHP:
if ((int)$mysidia->userprofile->getFavpetID() == 0){
            $document->add(new Comment("You don't have an assigned companion. Set one <a href='https://ashenblade.click/account/profile'>HERE</a>."));
        } else {
            $favorite = new OwnedAdoptable($mysidia->userprofile->getFavpet());
            $document->add(new Comment("<center>{$favorite} is your current companion!</center>"));
        }
The getFavpet() and getFavpetID() are both in model/domainmodel/userprofile and I THOUGHT I understood how to call from that, but I guess not.........

I also have all of these to cover my bases...
PHP:
<?php

namespace View\Main;
use Controller\Main;
use Model\DomainModel\Item;
use Model\DomainModel\Member;
use Model\DomainModel\OwnedAdoptable;
use Model\DomainModel\UserProfile;
use Model\DomainModel\User;
use Resource\Core\Registry;
use Resource\Core\View;
use Resource\GUI\Document\Comment;
use Resource\GUI\Component\Image;
use Resource\GUI\Component\Link;
 
Hi again....... :/
So, My code works fine until I try to fetch the favpet data........
PHP:
if ((int)$mysidia->userprofile->getFavpetID() == 0){
            $document->add(new Comment("You don't have an assigned companion. Set one <a href='https://ashenblade.click/account/profile'>HERE</a>."));
        } else {
            $favorite = new OwnedAdoptable($mysidia->userprofile->getFavpet());
            $document->add(new Comment("<center>{$favorite} is your current companion!</center>"));
        }
The getFavpet() and getFavpetID() are both in model/domainmodel/userprofile and I THOUGHT I understood how to call from that, but I guess not.........

I also have all of these to cover my bases...
PHP:
<?php

namespace View\Main;
use Controller\Main;
use Model\DomainModel\Item;
use Model\DomainModel\Member;
use Model\DomainModel\OwnedAdoptable;
use Model\DomainModel\UserProfile;
use Model\DomainModel\User;
use Resource\Core\Registry;
use Resource\Core\View;
use Resource\GUI\Document\Comment;
use Resource\GUI\Component\Image;
use Resource\GUI\Component\Link;
Woo, okay, that took me a while to get lmao. I've never had to call the favpet before so had to look into it. I put it on my index as I'm not sure where you're wanting it. But this is how I did it:

PHP:
 $profile = $mysidia->user->getProfile();
        if ($profile->getFavpet() == 0) $favourite = "You have no favpet.";
        else{
                $favpet = new OwnedAdoptable($profile->getFavpetID());
                $favourite = "<img src='{$favpet->getImage()}' style='width:100px'></img>";
        }

Then to call it I used:

PHP:
$document->add(new Comment("Here's your favpet: {$favourite}"));

2023-11-16 16_10_10-Mysidia Adoptables v1.3.6 and 9 more pages - Personal - Microsoft​ Edge.png 2023-11-16 16_09_57-Mysidia Adoptables v1.3.6 and 9 more pages - Personal - Microsoft​ Edge.png
 
Woo, okay, that took me a while to get lmao. I've never had to call the favpet before so had to look into it. I put it on my index as I'm not sure where you're wanting it. But this is how I did it:

PHP:
 $profile = $mysidia->user->getProfile();
        if ($profile->getFavpet() == 0) $favourite = "You have no favpet.";
        else{
                $favpet = new OwnedAdoptable($profile->getFavpetID());
                $favourite = "<img src='{$favpet->getImage()}' style='width:100px'></img>";
        }

Then to call it I used:

PHP:
$document->add(new Comment("Here's your favpet: {$favourite}"));

View attachment 635View attachment 634
Defining $favpet causes the white page again....... Am I forgetting a domain model? Here's what I have:
PHP:
<?php

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

class TrainView extends View {
    public function index() {
        $mysidia = Registry::get("mysidia");
        $document = $this->document;
        $required = new OwnedItem(17, $mysidia->user->getID());
        $profile = $mysidia->user->getProfile();
       
        $document->setTitle("<img src='https://i.postimg.cc/HnfxQxcw/H200.png'> Training Area <img src='https://i.postimg.cc/HnfxQxcw/H200.png'>");
       
        if($required->inInventory()){
            $document->add(new Comment("Work In Progress. I will post a news update when I get this working."));
           if ($profile->getFavpet() == 0){
                   $document->add(new Comment("You don't have an assigned companion. Assign one <a href='https://ashenblade.click/account/profile'>here</a>."));
            } else{
               //$favpet = new OwnedAdoptable($profile->getFavpetID());
            }
        } else{
            $document->add(new Comment("You need a training bag to train your critters. Get one in the <a href='https://ashenblade.click/shop/browse/2'>general store</a>."));
        }
    }
}

edit: I forgot OwnedAdoptable -.-
 
Why am I so bad at this???!?!?!?

All was working fine until I changed one thing and now I don't know what that thing was. I tried commenting out several lines of code to no avail. It's somewhere in the index section. I've commented out everything else, so I'mma just post that section.
Here's trainview.php
PHP:
<?php

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

class TrainView extends View {
    public function index() {
        $mysidia = Registry::get("mysidia");
        $document = $this->document;
        $required = new OwnedItem(17, $mysidia->user->getID());
        $profile = $mysidia->user->getProfile();
     
        $document->setTitle("<img src='https://i.postimg.cc/HnfxQxcw/H200.png'> Training Area <img src='https://i.postimg.cc/HnfxQxcw/H200.png'>");
        $document->add(new Comment("Work In Progress. I will post a news update when I get this working.<hr>"));
        $document->add(new Comment("<center>Welcome to the Training Grounds. Here, you can train your assigned companion's stats. It costs 30 Gold Pieces to train once.<br>Better stats means better performance in battle, so let's get to work!</center><hr>"));
     
        if($required->inInventory()){
           if ($profile->getFavpetID() == 0){
                   $document->add(new Comment("<center>You don't have an assigned companion. Assign one <a href='https://ashenblade.click/account/profile'>here</a>.</center>"));
            } else{
               $favpet = new OwnedAdoptable($profile->getFavpetID());
               $favorite = new OwnedAdoptable($profile->getFavpet());
           
               $document->add(new Comment("<center>
                Your assigned companion is your {$favorite}.<br>
                To change it, click <a href='../account/profile'>here</a>.
               </center>"));
           
               $document->add(new Comment("To train, select the stat that you would like to work on.<br><br>
                    <b>{$favpet}'s Stats</b><br>
                    <table>
                        <tr><th>Strength</th>
                        <th>Speed</th>
                        <th>Stamina</th></tr>
                        <tr><td>{$favpet->strength}</td>
                        <td>{$favpet->speed}</td>
                        <td>{$favpet->stamina}</td>
                    </table><br><br>
                    ", FALSE));
                $document->add(new Link("train/strength", "Train Strength"));
                $document->add(new Comment("<br>"));
                $document->add(new Link("train/speed", "Train Speed"));
                $document->add(new Comment("<br> "));
                $document->add(new Link("train/stamina","Train Stamina"));
            }
        } else{
            $document->add(new Comment("You need a training bag to train your critters. Get one in the <a href='https://ashenblade.click/shop/browse/2'>general store</a>."));
        }
    }
Even ChatGPT can't figure out what's wrong DX

After a LOT of troubleshooting, it turns out it doesn't like defining $favpet or $favorite............ It doesn't seem to mind $profile->getFavpetID but when I try to define $favpet or $favorite with that same function, it goofs up.

I just think I'm not going to use this mod. It messed up my being able to access my adoptables again and I don't know what happened...
 
Last edited:
Why am I so bad at this???!?!?!?

All was working fine until I changed one thing and now I don't know what that thing was. I tried commenting out several lines of code to no avail. It's somewhere in the index section. I've commented out everything else, so I'mma just post that section.
Here's trainview.php
PHP:
<?php

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

class TrainView extends View {
    public function index() {
        $mysidia = Registry::get("mysidia");
        $document = $this->document;
        $required = new OwnedItem(17, $mysidia->user->getID());
        $profile = $mysidia->user->getProfile();
   
        $document->setTitle("<img src='https://i.postimg.cc/HnfxQxcw/H200.png'> Training Area <img src='https://i.postimg.cc/HnfxQxcw/H200.png'>");
        $document->add(new Comment("Work In Progress. I will post a news update when I get this working.<hr>"));
        $document->add(new Comment("<center>Welcome to the Training Grounds. Here, you can train your assigned companion's stats. It costs 30 Gold Pieces to train once.<br>Better stats means better performance in battle, so let's get to work!</center><hr>"));
   
        if($required->inInventory()){
           if ($profile->getFavpetID() == 0){
                   $document->add(new Comment("<center>You don't have an assigned companion. Assign one <a href='https://ashenblade.click/account/profile'>here</a>.</center>"));
            } else{
               $favpet = new OwnedAdoptable($profile->getFavpetID());
               $favorite = new OwnedAdoptable($profile->getFavpet());
         
               $document->add(new Comment("<center>
                Your assigned companion is your {$favorite}.<br>
                To change it, click <a href='../account/profile'>here</a>.
               </center>"));
         
               $document->add(new Comment("To train, select the stat that you would like to work on.<br><br>
                    <b>{$favpet}'s Stats</b><br>
                    <table>
                        <tr><th>Strength</th>
                        <th>Speed</th>
                        <th>Stamina</th></tr>
                        <tr><td>{$favpet->strength}</td>
                        <td>{$favpet->speed}</td>
                        <td>{$favpet->stamina}</td>
                    </table><br><br>
                    ", FALSE));
                $document->add(new Link("train/strength", "Train Strength"));
                $document->add(new Comment("<br>"));
                $document->add(new Link("train/speed", "Train Speed"));
                $document->add(new Comment("<br> "));
                $document->add(new Link("train/stamina","Train Stamina"));
            }
        } else{
            $document->add(new Comment("You need a training bag to train your critters. Get one in the <a href='https://ashenblade.click/shop/browse/2'>general store</a>."));
        }
    }
Even ChatGPT can't figure out what's wrong DX

After a LOT of troubleshooting, it turns out it doesn't like defining $favpet or $favorite............ It doesn't seem to mind $profile->getFavpetID but when I try to define $favpet or $favorite with that same function, it goofs up.

Try this:

PHP:
<?php

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

class TrainView extends View{
  
    public function index() {
        $mysidia = Registry::get("mysidia");
        $document = $this->document;
        $required = new OwnedItem(17, $mysidia->user->getID());
        $profile = $mysidia->user->getProfile();
      
        $document->setTitle("<img src='https://i.postimg.cc/HnfxQxcw/H200.png'> Training Area <img src='https://i.postimg.cc/HnfxQxcw/H200.png'>");
        $document->add(new Comment("Work In Progress. I will post a news update when I get this working.<hr>"));
        $document->add(new Comment("<center>Welcome to the Training Grounds. Here, you can train your assigned companion's stats. It costs 30 Gold Pieces to train once.<br>Better stats means better performance in battle, so let's get to work!</center><hr>"));
      
        if($required->inInventory()){
           if ($profile->getFavpetID() == 0){
                   $document->add(new Comment("<center>You don't have an assigned companion. Assign one <a href='https://ashenblade.click/account/profile'>here</a>.</center>"));
            }
            else{
               $favpet = new OwnedAdoptable($profile->getFavpetID());
            
               $document->add(new Comment("<center>
                Your assigned companion is your {$favpet->getName()}.<br>
                To change it, click <a href='../account/profile'>here</a>.
               </center>"));
            
               $document->add(new Comment("To train, select the stat that you would like to work on.<br><br>
                    <b>{$favpet->getName()}'s Stats</b><br>
                    <table>
                        <tr><th>Strength</th>
                        <th>Speed</th>
                        <th>Stamina</th></tr>
                        <tr><td>{$favpet->getStrength()}</td>
                        <td>{$favpet->getSpeed()}</td>
                        <td>{$favpet->getStamina()}</td>
                    </table><br><br>
                    ", FALSE));
                $document->add(new Link("train/strength", "Train Strength"));
                $document->add(new Comment("<br>"));
                $document->add(new Link("train/speed", "Train Speed")); 
                $document->add(new Comment("<br> "));
                $document->add(new Link("train/stamina","Train Stamina"));
            }
        } else{
            $document->add(new Comment("You need a training bag to train your critters. Get one in the <a href='https://ashenblade.click/shop/browse/2'>general store</a>."));
        }
    }
}

You don't need to assign {$favourite} on this page, before I did it because that was how I displayed the image. Now you only need {$favpet} as you're just calling the information you need.

To call information you use the same functions that are defined in ownedadoptable.php.

So here's a list you could use.

{$favpet} by itself calls the type/species name.
{$favpet->getAdoptID()} gets the ID.
{$favpet->getName()} calls the adopt's name. You cannot just use $favpet->name because name is a protected function in ownedadoptable.php (you can see what's protected, public, or private, at the top of ownedadoptable.php)
{$favpet->getStrength()} calls the strength. We assigned in ownedadoptable.php last time.

I recommend setting speed and stamina the same way in the model, it gets you used to the process and means you can use getSpeed and getStamina whenever you need to.

Technically you can use {$favpet->strength}, etc, and it DOES work because we set strength, speed, etc, as public in ownedadoptable.php. However I still recommend getting used to getStrength() instead because most things tend to be set to protected and it helps you to get used to it lol.

So the process tends to be set something in the model, then you can use it whenever you call that model. In this case $favpet = new OwnedAdoptable($profile->getFavpetID()); is calling from the ownedadoptable.php file.

Hopefully that helps you!
 
Everything works but now I cant adopt anything from the adopt shops. I have no clue what files I've edited at this point.........

FIXED HOLY CRAP THAT WAS ANNOYING
 
Last edited:
Everything works but now I cant adopt anything from the adopt shops. I have no clue what files I've edited at this point.........
That's my bad actually, adopt shops use makeOwnedAdopt as well and we've changed it to allow stats when breeding. So adopt shops also need the values to be passed. I didn't consider that, sorry lol.

EDIT: Removed what I had put before as I figured an easier solution.

For the easier solution, add your stats to the adopts_adoptables table in the DB. So strength, stamina, speed, etc.

Then go back to breedingservice.php and replace public function breed with this:

PHP:
public function breed(){
        $mysidia = Registry::get("mysidia");
        foreach($this->offsprings as $adopt){
               $code = $adopt->generateCode();
            $gender = $adopt->getGender();
            $mysidia->db->insert("owned_adoptables", ["aid" => NULL, "adopt" => $adopt->getID(), "name" => $adopt->getType(), "owner" => $mysidia->user->getID(), "currentlevel" => 0, "totalclicks" => 0, "code" => $code, "imageurl" => "", "alternate" => 0, "tradestatus" => "fortrade", "isfrozen" => "no", "gender" => $gender, "offsprings" => 0,"strength" => $this->getBabyStrength(), "lastbred" => 0]);
        }
        $this->validator->setStatus("complete");   
    }

That essentially makes it so you only need to change the breed function when you want to change how something passes down. Doesn't affect anything else like the adoptshop, promos, or adopt page. If something is not defined in that insert it should use the DB default... this way you can control breeding a lot more. It's what I'll be doing for my site as I have genetics involved.

It's how it used to be back in 1.3.4 but it was changed when the code got an overhaul.

Good news is, now you can have different default stats for each adoptable LOL.

If you add new stats though you still need to define them in adoptable.php and public function makeOwnedAdopt.
 
Last edited:
KITTTTTTTTTT~
I haven't broken anything but I'm having trouble understanding the buttons for battle.

Here's what I have:
PHP:
$document->add(new Comment("
                    You enter the battle arena with {$favname->getName()} at your side. Waiting at the opposite end of the arena is your opponent!<br>
                    To engage in battle, select an attack from below. If you would not like to battle, simply leave this page.<br>
                "));
                $document->add(new Button("Bite", "use_bite"));
                $document->add(new Button("Tackle", "use_tackle"));
                if ("use_bite"){
                    $document->add(new Comment("testing"));
                }
                if ("use_tackle"){
                    $document->add(new Comment("also testing"));
                }
When I load the page (if you want to look at it it's ashenblade.click/battle) it shows the comments before I touch the button. How do i make it only trigger if I touch the corresponding button?

Thanks in advance!!!
 
KITTTTTTTTTT~
I haven't broken anything but I'm having trouble understanding the buttons for battle.

Here's what I have:
PHP:
$document->add(new Comment("
                    You enter the battle arena with {$favname->getName()} at your side. Waiting at the opposite end of the arena is your opponent!<br>
                    To engage in battle, select an attack from below. If you would not like to battle, simply leave this page.<br>
                "));
                $document->add(new Button("Bite", "use_bite"));
                $document->add(new Button("Tackle", "use_tackle"));
                if ("use_bite"){
                    $document->add(new Comment("testing"));
                }
                if ("use_tackle"){
                    $document->add(new Comment("also testing"));
                }
When I load the page (if you want to look at it it's ashenblade.click/battle) it shows the comments before I touch the button. How do i make it only trigger if I touch the corresponding button?

Thanks in advance!!!
Hey, I couldn't look at it on your site as none of my adopts are the right level yet lol. But I figured it out! To use buttons you need to add them to a form.

So add this to the top if you don't already have it:

PHP:
use Resource\GUI\Container\Form;

Then something like this would work:

PHP:
public function battle(){
        $mysidia = Registry::get("mysidia");
        $profile = $mysidia->user->getProfile();
        $favpet = new OwnedAdoptable($profile->getFavpetID());
        $BattleForm = new Form("battle", "battle", "post");
        $document = $this->document;
        $document->setTitle("<img src='https://i.postimg.cc/HnfxQxcw/H200.png'> Training Area <img src='https://i.postimg.cc/HnfxQxcw/H200.png'>");
        if($mysidia->input->post("use_bite")){
            $document->add(new Comment("testing"));
            return;
        }
        if($mysidia->input->post("use_tackle")){
            $document->add(new Comment("also testing"));
            return;
        }
        $document->add(new Comment("
                    You enter the battle arena with {$favpet->getName()} at your side. Waiting at the opposite end of the arena is your opponent!<br>
                    To engage in battle, select an attack from below. If you would not like to battle, simply leave this page.<br>
                "));
        $BattleForm->add(new Button("Bite", "use_bite", "submit"));
        $BattleForm->add(new Button("Tackle", "use_tackle", "submit"));
        $document->add($BattleForm);
    }

Essentially that makes the buttons part of a form and when you click it will submit. You need to use $mysidia->input->post in the if statement and the reason you add the form is because else it doesn't know to expect a post. Not a very good explanation but hopefully you get it haha :ROFLMAO:
 
Hey, I couldn't look at it on your site as none of my adopts are the right level yet lol. But I figured it out! To use buttons you need to add them to a form.

So add this to the top if you don't already have it:

PHP:
use Resource\GUI\Container\Form;

Then something like this would work:

PHP:
public function battle(){
        $mysidia = Registry::get("mysidia");
        $profile = $mysidia->user->getProfile();
        $favpet = new OwnedAdoptable($profile->getFavpetID());
        $BattleForm = new Form("battle", "battle", "post");
        $document = $this->document;
        $document->setTitle("<img src='https://i.postimg.cc/HnfxQxcw/H200.png'> Training Area <img src='https://i.postimg.cc/HnfxQxcw/H200.png'>");
        if($mysidia->input->post("use_bite")){
            $document->add(new Comment("testing"));
            return;
        }
        if($mysidia->input->post("use_tackle")){
            $document->add(new Comment("also testing"));
            return;
        }
        $document->add(new Comment("
                    You enter the battle arena with {$favpet->getName()} at your side. Waiting at the opposite end of the arena is your opponent!<br>
                    To engage in battle, select an attack from below. If you would not like to battle, simply leave this page.<br>
                "));
        $BattleForm->add(new Button("Bite", "use_bite", "submit"));
        $BattleForm->add(new Button("Tackle", "use_tackle", "submit"));
        $document->add($BattleForm);
    }

Essentially that makes the buttons part of a form and when you click it will submit. You need to use $mysidia->input->post in the if statement and the reason you add the form is because else it doesn't know to expect a post. Not a very good explanation but hopefully you get it haha :ROFLMAO:
Yeah that makes sense. I figured it was something simple I wasn't doing lol
 
lol

Breeding adoptables has changed a lot so a lot of the code has moved or straight up been changed... for example, there is a function in model/domainmodel/adoptable.php for giving an adopt to a user.

PHP:
public function makeOwnedAdopt($owner, $name = NULL){
        $mysidia = Registry::get("mysidia");
        if(!$name) $name = $this->type;
        $code = $this->generateCode();
        $gender = $this->getGender();
        $mysidia->db->insert("owned_adoptables", ["aid" => NULL, "adopt" => $this->id, "name" => $name, "owner" => $owner, "currentlevel" => 0,
                                                  "totalclicks" => 0, "code" => $code, "imageurl" => "", "alternate" => 0, "tradestatus" => "fortrade",
                                                  "isfrozen" => "no", "gender" => $gender, "offsprings" => 0, "lastbred" => 0]); 
        $aid = $mysidia->db->lastInsertId();
        if(!$aid) return NULL;
        return new OwnedAdoptable($aid);
    }

Then in breedingservice.php there's this:

PHP:
public function breed(){
        $mysidia = Registry::get("mysidia");
        foreach($this->offsprings as $adopt){
            $adopt->makeOwnedAdopt($mysidia->user->getID());
        }
        $this->validator->setStatus("complete");
    }

That essentially uses $adopt->makeOwnedAdopt($mysidia->user->getID()); to give the adopt to a user, and there's no direct insert like there used to be. So unfortunately adding stats while breeding will be a bit more complicated.

That being said, I have given it a shot and managed to get it working. :cool:

1) Open service/applicationservice/breedingservice.php. Add this:

PHP:
public function getBabyStrength(){
        $femaleStrength = $this->female->getStrength();
        $maleStrength = $this->male->getStrength();
        $parentStrength = $femaleStrength + $maleStrength;
        $strength = $parentStrength / 2;
        return $strength;
    }

2) Scroll to the bottom breed function and replace it with this:

PHP:
public function breed(){
        $mysidia = Registry::get("mysidia");
        foreach($this->offsprings as $adopt){
            $adopt->makeOwnedAdopt($mysidia->user->getID(), $this->getBabyStrength());
        }
        $this->validator->setStatus("complete"); 
    }

3) Open model/domainmodel/adoptable.php. Find the makeOwnedAdopt function and replace it with this:

PHP:
public function makeOwnedAdopt($owner, $strength, $name = NULL){
        $mysidia = Registry::get("mysidia");
        if(!$name) $name = $this->type;
        $code = $this->generateCode();
        $gender = $this->getGender();
        $mysidia->db->insert("owned_adoptables", ["aid" => NULL, "adopt" => $this->id, "name" => $name, "owner" => $owner, "currentlevel" => 0, "totalclicks" => 0, "code" => $code, "imageurl" => "", "alternate" => 0, "tradestatus" => "fortrade", "isfrozen" => "no", "gender" => $gender, "offsprings" => 0,"strength" => $strength, "lastbred" => 0]);  
        $aid = $mysidia->db->lastInsertId();
        if(!$aid) return NULL;
        return new OwnedAdoptable($aid);
    }

If you want the strength to be randomised between the two parents instead, use this in breedingservice:

PHP:
public function getBabyStrength(){
        $femaleStrength = $this->female->getStrength();
        $maleStrength = $this->male->getStrength();
        $strength = rand($femaleStrength, $maleStrength);
        return $strength;
    }

Top 2 are parents, others are children (from 2 breedings):

View attachment 632


If you want the strength to have a random chance to get a small boost you can use something like:

PHP:
public function getBabyStrength(){
        $femaleStrength = $this->female->getStrength();
        $maleStrength = $this->male->getStrength();
        $boostChance = rand(1,100);
        $boostAmount = rand(1,10);
        if($boostChance <= 10){
            $strength = rand($femaleStrength, $maleStrength) + $boostAmount;
        }
        else{
            $strength = rand($femaleStrength, $maleStrength);
        }
     
        return $strength;
    }

That essentially randomises the baby's strength between the two parents and then there is a 10% chance the baby gets a 1-10 boost. To change the values just change if($boostChance <= 10) to whatever chance you want. It basically means if the random value out of 100 lands on 1-10, they get the boost. And then $boostAmount is the two values the boost can be between.

With the above random + boost, this is what I got:

View attachment 633

Then if you want to add MORE stats you basically need to repeat the steps and in public function breed you need to make this line have all the other stats:

PHP:
$adopt->makeOwnedAdopt($mysidia->user->getID(), $this->getBabyStrength());

So something like:

PHP:
$adopt->makeOwnedAdopt($mysidia->user->getID(), $this->getBabyStrength(), $this->getBabySpeed(), $this->getBabyStamina());

And also make sure to change:

PHP:
public function makeOwnedAdopt($owner, $strength, $name = NULL)

To also have the new values, like:

PHP:
public function makeOwnedAdopt($owner, $strength, $speed, $stamina, $name = NULL)

And don't forget the insert needs to include the new stats too.

Hopefully that was clear enough haha!
Can you help me with this mod on 1.3.4? I need to fix the negative money error but don't understand how ^^'

i tried using this code:

public function checkMoney($mysidia, $document) {
$traincost = 10000;
$money = 0;

if($money = 0) {
$document->add(new Comment(" You don't have enough money to train your companion!"));
return;
}
 
Last edited:
For what its worth, going back in all this time later, this brilliant Mod just needs all the attributes (sense, etc) changed to public instead of private.

I am much more php savvy a few years in -- and found it easy to get it working just fine!

Highly recommend this awesome and fun Mod!


Thanks again for it!
Can you help me to fix the negative money error please? i don't understand how to fix it I've tried everything... I'm on 1.3.4.
 
Can you help me to fix the negative money error please? i don't understand how to fix it I've tried everything... I'm on 1.3.4.
You can try setting the money field to unsigned in the database. That should stop it from going below zero, but it will throw an error if the math tries to go below zero. Your function uses return without returning anything. It should also use the player's money value. You set the value to always equal zero and it's not using the player's actual money value, so it will never work. Instead of making a separate function, just toss the if statement into the function that is already doing the subtracting so that it will show the message if the player doesn't have enough money to cover the cost. Something like, if the player's money is less than the cost, add the comment about not having enough money, and exit.
 
Last edited:
You can try setting the money field to unsigned in the database. That should stop it from going below zero, but it will throw an error if the math tries to go below zero. Your function uses return without returning anything. It should also use the player's money value. You set the value to always equal zero and it's not using the player's actual money value, so it will never work. Instead of making a separate function, just toss the if statement into the function that is already doing the subtracting so that it will show the message if the player doesn't have enough money to cover the cost. Something like, if the player's money is less than the cost, add the comment about not having enough money, and exit.
How would I do that? I'm not good at coding, I used AI for that ^^'
 
Okay, what the heck; it was working on my previous site but I don't have those files anymore...

I'm in "model\domainmodel\adoptable.php" to set my stats and I changed the code to this:
PHP:
public function makeOwnedAdopt($owner, $strength, $speed, $stamina, $sense, $name = NULL){
        $mysidia = Registry::get("mysidia");
        if(!$name) $name = $this->type;
        $code = $this->generateCode();
        $gender = $this->getGender();
        
        $strength = rand(10,100);
        $speed = rand(10,100);
        $stamina = rand(10,100);
        $sense = rand(10,100);
    
        $mysidia->db->insert("owned_adoptables", ["aid" => NULL, "adopt" => $this->id, "name" => $name, "owner" => $owner, "currentlevel" => 0,
                                                  "totalclicks" => 0, "code" => $code, "imageurl" => "", "alternate" => 0, "tradestatus" => "fortrade",
                                                  "isfrozen" => "no", "gender" => $gender, "offsprings" => 0, "lastbred" => 0, "strength" => $strength, "speed" => $speed, "stamina" => $stamina, "sense" => $sense]);     
        $aid = $mysidia->db->lastInsertId();
        if(!$aid) return NULL;
        return new OwnedAdoptable($aid);
    }
but when I try to buy an adoptable, it takes my money, doesn't give me the adopt, and obviously doesn't set the stats cause there's no adoptable to set it on. I tried commenting out all the stats in $mysidia->db->insert[...] but it still does the same thing. So it seems to be something with how I'm settting the stats but it looks the same as $genderNumber = rand(0,99); so I'm not sure what's wrong...
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,295
Messages
33,186
Members
1,606
Latest member
kandriamage
BETA

Latest Threads

Latest Posts

Top