Mys 1.3.4 Simple NPC Battle

Forum
Last Post
Threads / Messages

dlithehil

Member
Member
Joined
Jun 10, 2022
Messages
59
Points
8
Mysidian Dollar
472
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;
 

KittHaven

Member
Member
Joined
May 21, 2013
Messages
466
Points
28
Age
25
Location
Devon, UK
Mysidian Dollar
8,183
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
 

dlithehil

Member
Member
Joined
Jun 10, 2022
Messages
59
Points
8
Mysidian Dollar
472
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 -.-
 

dlithehil

Member
Member
Joined
Jun 10, 2022
Messages
59
Points
8
Mysidian Dollar
472
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:

KittHaven

Member
Member
Joined
May 21, 2013
Messages
466
Points
28
Age
25
Location
Devon, UK
Mysidian Dollar
8,183
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!
 

dlithehil

Member
Member
Joined
Jun 10, 2022
Messages
59
Points
8
Mysidian Dollar
472
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:

KittHaven

Member
Member
Joined
May 21, 2013
Messages
466
Points
28
Age
25
Location
Devon, UK
Mysidian Dollar
8,183
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:

dlithehil

Member
Member
Joined
Jun 10, 2022
Messages
59
Points
8
Mysidian Dollar
472
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!!!
 

KittHaven

Member
Member
Joined
May 21, 2013
Messages
466
Points
28
Age
25
Location
Devon, UK
Mysidian Dollar
8,183
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:
 

dlithehil

Member
Member
Joined
Jun 10, 2022
Messages
59
Points
8
Mysidian Dollar
472
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
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,249
Messages
32,876
Members
1,597
Latest member
emotidogzz
BETA

Latest Threads

Top