Mys 1.3.4 Simple NPC Battle

Forum
Last Post
Threads / Messages

Abronsyth

A Headache Embodied
Member
Joined
Aug 25, 2011
Messages
1,012
Points
36
Location
NY
Mysidian Dollar
73,285
Simple NPC Battle V.1.0

Hello!

This mod will cover several topics:
-assigning stats to adoptables (and making them inheritable through breeding)
-training adoptables to increase stats
-competing against randomly generated NPCs
-earning trophies from competing

This mod was specifically coded for and tested with Mysidia 1.3.4. While it may be adaptable to other versions of Mysidia it would take quite a bit of tweaking.

Note: the battleview.php code is based on Kyttias's explore code, I have permission from her to use and share it with you all :)

Demo:
FyN6mnF.gif


P.1: Stats
The code I will provide uses four stats: Sense, Speed, Strength, and Stamina. In this section I will show you how to add these four, but with some tweaking you can honestly use/add any sort of stats you'd like.

The first step is adding these stats to the database. In phpMyAdmin go to the table prefix_owned_adoptables, then go to the structure tab and scroll down to add four columns, naming them sense, speed, strength, and stamina. Type should be varchar and you shouldn't need more than 5. I set the default value as 10. (screenshot)

Once that is done, it's time to make it so that when a user adopts a new pet that pet has random stats. Go into the file adopt.php and find this line:
PHP:
$mysidia->db->insert("owned_adoptables"...
Right above that insert this chunk of code:
PHP:
$sense = rand(10,100); 	
$speed = rand(10,100); 
$strength = rand(10,100); 
$stamina = rand(10,100);

Now add this to the end of the insert string, make sure it is BEFORE the ending ));, and that there is a comma between the last thing in there and the new stuff. So right after "lastbred" => 0 add a comma, and then add this before the ));
PHP:
"sense" => $sense, "speed" => $speed, "strength" => $strength, "stamina" => $stamina

Now we need to do the same thing in the files class_promocode.php and class_stockadopt.php, just follow the above steps for these two files.

Now breeding is a little bit more tricky since we want bred adoptables to inherit their parent's stats. So go into class_breeding.php and find the insert statement ($mysidia->db->insert("owned_adoptables"...). Right above it add this lovely chunk of code:
PHP:
$mother_se =  $this->female->sense;
$father_se =  $this->male->sense;
$mother_sp =  $this->female->speed;
$father_sp =  $this->male->speed;
$mother_str =  $this->female->strength;
$father_str =  $this->male->strength;
$mother_st =  $this->female->stamina;
$father_st =  $this->male->stamina;

$parent_se = $mother_se + $father_se;
$parent_sp = $mother_sp + $father_sp;
$parent_str = $mother_str + $father_str;
$parent_st = $mother_st + $father_st;

$sense = $parent_se / 2; 	
$speed = $parent_sp / 2; 
$strength = $parent_str / 2; 
$stamina = $parent_st / 2;
What this does is retrieve all of the parent stats, add each stat together (mother's sense + father's sense, etc), and then finds the average between them. So if the mother has 32 sense and the father has 64, the babies will have 48.
After you add that, add this in just like we did for the other files:
PHP:
"sense" => $sense, "speed" => $speed, "strength" => $strength, "stamina" => $stamina

Cool, now that's it for stats! Our battle page will display the pet's stats anyways, but if you want to display it on the level up pages and such check these threads out:
Restyling the Manage Page
Public Pet Profiles

P.2: Training
This section will cover how to train pets in order to increase stats!

So, we are going to need two files. First create a file called train.php and paste this in it:
PHP:
<?php

class TrainController extends AppController{
    
    public function __construct(){
        parent::__construct("member");
    }

    public function index(){
        $mysidia = Registry::get("mysidia");        
    }

}
?>

That goes in your root folder and it is good to go. Close it and make a new file, this one called trainview.php. Now copy and paste this code into it:
PHP:
<?php
class TrainView extends View{
    
    public function index(){
        $mysidia = Registry::get("mysidia");
        $document = $this->document; 
		$document->setTitle("Stat Training");
		            $document->add(new Comment("Welcome to the Gym. People from all across the land come here to train their pets and prep them for battle.<br>
					<center><b>Each training session costs 30 CURRENCY.</b></center><br><br>
					To train your pet it must be an adult, and it must be set as your assigned companion.", FALSE)); 
		$profile = $mysidia->user->getprofile();
		$mysidia->user->getprofile(); 
		if ((int)$profile->getFavpetID() == 0) { 
			$document->addLangVar('<br><br>It seems you do not yet have not assigned a companion! Assign one and then come back.'); 
		return; 
		} 
		$favpet = new OwnedAdoptable($profile->getFavpetID());	
		
		if ($favpet->currentlevel < 3){ 
            $document->add(new Comment("<br><br>Woah, sorry there! Your pet isn't old enough to train, yet! Come back with an adult if you want to train!", FALSE)); 
      return; 
		} 
		if($favpet->currentlevel = 3){
			$document->add(new Comment("To train, select the stat that you would like to work on.<br><br>
					<center><b>{$favpet->name}'s Stats</b><br>
					<u>Se | Sp | Str | Stm</u><br>
					{$favpet->sense} | {$favpet->speed} | {$favpet->strength} | {$favpet->stamina}<br>", FALSE));
			$this->exploreButton("Train_Sense", FALSE, "Train Sense");
			$this->exploreButton("Train_Speed", FALSE, "Train Speed");
			$this->exploreButton("Train_Strength", FALSE, "Train Strength");
			$this->exploreButton("Train_Stamina", FALSE, "Train Stamina");
        } # END no area selected

        /* If an area is selected: */
        if($mysidia->input->post("area")){
            
            $area = $mysidia->input->post("area"); // This has apostrophes as *s instead, just like the exploreButtons above!
            $str = str_replace("_", " ", $area);
            $areaname = str_replace("*", "'", $str); // This one has apostrophes instead of asterisks.

            $document->setTitle("{$areaname}");
				$increase = rand(1,5);
				$sense = $favpet->sense;
				$newsense = $sense + $increase;
				$speed = $favpet->speed;
				$newspeed = $speed + $increase;
				$strength = $favpet->strength;
				$newstrength = $strength + $increase;
				$stamina = $favpet->stamina;
				$newstamina = $stamina + $increase;
		
            switch ($area){
                # First one is the default response that will happen unless something specific is specified:
                case $areaname: $document->add(new Comment("<br><br>Oops, something has gone wrong.", FALSE));
                break;

				
				case "Train_Sense": 
					$currentcash = $mysidia->user->money;
					$newmoney = $currentcash - 30;
						$document->add(new Comment("<br><b>The Session:</b><br> Write something here about the Sense training.<br><br>
						{$favpet->name} gained {$increase} Sense from this session!", FALSE));
						$mysidia->db->update("users", array("money" => $newmoney), "username='{$mysidia->user->username}'");
						$mysidia->db->update("owned_adoptables", array("sense" => $newsense), "aid='{$profile->getFavpetID()}'");
				break;
				case "Train_Speed": 
					$currentcash = $mysidia->user->money;
					$newmoney = $currentcash - 30;
						$document->add(new Comment("<br><b>The Session:</b><br> Write something here about the Speed training.<br><br>
						{$favpet->name} gained {$increase} Speed from this session!", FALSE));
						$mysidia->db->update("users", array("money" => $newmoney), "username='{$mysidia->user->username}'");
						$mysidia->db->update("owned_adoptables", array("speed" => $newspeed), "aid='{$profile->getFavpetID()}'");
				break;
				case "Train_Strength": 
					$currentcash = $mysidia->user->money;
					$newmoney = $currentcash - 30;
						$document->add(new Comment("<br><b>The Session:</b><br> Write something here about the Strength training.<br><br>
						{$favpet->name} gained {$increase} Strength from this session!", FALSE));
						$mysidia->db->update("users", array("money" => $newmoney), "username='{$mysidia->user->username}'");
						$mysidia->db->update("owned_adoptables", array("strength" => $newstrength), "aid='{$profile->getFavpetID()}'");
				break;
				case "Train_Stamina": 
					$currentcash = $mysidia->user->money;
					$newmoney = $currentcash - 30;
						$document->add(new Comment("<br><b>The Session:</b><br> Write something here about the training.<br><br>
						{$favpet->name} gained {$increase} Stamina from this session!", FALSE));
						$mysidia->db->update("users", array("money" => $newmoney), "username='{$mysidia->user->username}'");
						$mysidia->db->update("owned_adoptables", array("stamina" => $newstamina), "aid='{$profile->getFavpetID()}'");
				break;

			}

            return;
        }
	}

    public function exploreButton($areaname, $image_link = "", $customtext = "", $customimg = ""){
        $document = $this->document;
        
        if ($image_link){ /* Image Links */
            
             if (!$customimg){ /* Area Logo Image */
                 $imgname = str_replace("*", "'", $areaname);
                $document->add(new Comment("
                    <form id='exploreform' action='train' name='exploreform' method='post' role='form'>
                    <input id='area' name='area' type='hidden' value='{$areaname}'>
                    <button id='{$areaname}' class='btn-text btn-sm' value='train' name='{$areaname}' type='submit'>
                    <img src=\"./images/{$imgname}_logo.png\"/>
                    </button>
                    </form>
                ", FALSE)); 
             }
             
             else { /* Custom Link Image */
                 $imgname = str_replace("*", "'", $customimg);
                $document->add(new Comment("
                    <form id='exploreform' action='train' name='exploreform' method='post' role='form'>
                    <input id='area' name='area' type='hidden' value='{$areaname}'>
                    <button id='{$areaname}' class='btn-text btn-sm' value='train' name='{$areaname}' type='submit'>
                    <img src=\"./images/{$imgname}\"/>
                    </button>
                    </form>
                ", FALSE)); 
             }
        } 
        
        else { /* Text-Only Links */
            
            if (!$customtext){ /* Area Name Button */
                $str = str_replace("_", " ", $areaname); $btn_name = str_replace("*", "'", $str);
                $document->add(new Comment("
                    <form id='exploreform' action='train' name='exploreform' method='post' role='form'>
                    <input id='area' name='area' type='hidden' value='{$areaname}'>
                    <button id='{$areaname}' class='btn-violet btn-sm' value='train' name='{$areaname}' type='submit'>
                    {$btn_name}
                    </button>
                    </form>
                ", FALSE));
            } 
            
            else { /* Custom Link Text */
                $customtext = str_replace("*", "'", $customtext);
                $document->add(new Comment("
                    <form id='exploreform' action='train' name='exploreform' method='post' role='form'>
                    <input id='area' name='area' type='hidden' value='{$areaname}'>
                    <button id='{$areaname}' class='btn-violet btn-sm' style='display: inline;' value='train' name='{$areaname}' type='submit'>
                    {$customtext}
                    </button>
                    </form>
                ", FALSE));
            }
        }
        return;
    }
}	
?>

First, customize the currency name around line 9 where it just says CURRENCY. Also change the price so that it reflects whatever you want to charge for each training session.

Then, to change the charge, scroll to where you see the line
PHP:
$newmoney = $currentcash - 30;
and just change 30 to whatever the cost should be.

Each type of training has a section for you to write about the training session or add images, etc. Just fill it in to your pleasing!

P.3: Battle
This is the major focus of this mod! Creating a page that allows the user's fave pet to battle!

This requires two new files:
battle.php
This goes in the root folder where the files like adopt.php and account.php are.
PHP:
<?php

class BattleController extends AppController{
    
    public function __construct(){
        parent::__construct("member");
    }

    public function index(){
        $mysidia = Registry::get("mysidia");        
    }

}
?>

battleview.php
This goes in the view folder.
PHP:
<?php
/* This is the Battle Mod view page. This page is created based on the explore script created by Kyttias, so credit for the base of that goes to her. The ability to select and use the favepet was from RestlessThoughts, as posted on this thread; http://mysidiaadoptables.com/forum/showthread.php?t=4827&page=3
*This mod is entirely a collection of what Abronsyth has learned from messing around with mods created by wonderful users such as the two mentioned above.
 */
class BattleView extends View{
    
    public function index(){
        $mysidia = Registry::get("mysidia");
        $document = $this->document; 
		$document->setTitle("Battle");
		            $document->add(new Comment("<br>", FALSE)); 
		$profile = $mysidia->user->getprofile();
		$mysidia->user->getprofile(); 
		if ((int)$profile->getFavpetID() == 0) { 
			$document->addLangVar('<br><br>It seems you do not yet have not assigned a companion! Assign one and then come back.'); 
		return; 
		} 
		$favpet = new OwnedAdoptable($profile->getFavpetID());	
		
		if ($favpet->currentlevel < 3){ 
            $document->add(new Comment("<br><br>Woah, sorry there! Your companion isn't old enough to battle, yet! Come back with an adult companion if you want to compete!", FALSE)); 
      return; 
		} 
		if($favpet->currentlevel = 3){
 /*Random Opponent Stats*/
		$opsense = rand(1,100);
		$opstamina = rand(1,100);
		$opstrength = rand(1,100);
		$opspeed = rand(1,100);
	/*Below determines how many trophies the pet earns by winning a batttle.*/
		$trophies = $favpet->trophies;
		$newtrophy = $trophies + 1;
			$document->add(new Comment("You enter the battle arena with {$favpet->name} 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, you may simply leave this page.<br>", FALSE));
			$this->exploreButton("Use_Bite", FALSE, "Bite");
			$this->exploreButton("Use_Tackle", FALSE, "Tackle");
			$this->exploreButton("Use_Trick", FALSE, "Trick");
        } 
        if($mysidia->input->post("area")){
            
            $area = $mysidia->input->post("area");

            $document->setTitle("Battle");
		
            switch ($area){
				case "Use_Bite": 
					$opbite = $opspeed + $opstrength;
					$bite = $favpet->speed + $favpet->strength;
					$prize = rand(25,50);
					$currentcash = $mysidia->user->money;
					$newmoney = $prize + $currentcash;
					if($bite > $opbite){
						$document->add(new Comment("<br><br><table align='center' border='0px'>
				<tr>
					<td width='40%' style='text-align:left;vertical-align:bottom;'>
					<i>{$favpet->name}</i><br>
					<b>Sense:</b> {$favpet->sense}<br>
					<b>Speed:</b> {$favpet->speed}<br>
					<b>Strength:</b> {$favpet->strength}<br>
					<b>Stamina:</b> {$favpet->stamina}<br>
					</td>
					<td width='20%'>
					<center><b>VS</b></center>
					</td>
					<td width='40%' style='text-align:right;vertical-align:bottom'>
					<i>Opponent</i><br>
					<b>Sense:</b> {$opsense}<br>
					<b>Speed:</b> {$opspeed}<br>
					<b>Strength:</b> {$opstrength}<br>
					<b>Stamina:</b> {$opstamina}<br>
					</td>
				</tr>
			</table><br><center>Your pet dives in and attacks your opponent with a bite dealing {$bite} damage.
						<br>The opponent counters the attack with {$opbite} damage, but it isn't enough!<br>
						Your pet has won, and brought you {$prize} currency! Furthermore, {$favpet->name} has won a trophy!</center><br><br>", FALSE));
						$mysidia->db->update("users", array("money" => $newmoney), "username='{$mysidia->user->username}'");
						$mysidia->db->update("owned_adoptables", array("trophies" => $newtrophy), "aid='{$profile->getFavpetID()}'");
					}
					else{
						$document->add(new Comment("<br><br><table align='center' border='0px'>
				<tr>
					<td width='40%' style='text-align:left;vertical-align:bottom;'>
					<i>{$favpet->name}</i><br>
					<b>Sense:</b> {$favpet->sense}<br>
					<b>Speed:</b> {$favpet->speed}<br>
					<b>Strength:</b> {$favpet->strength}<br>
					<b>Stamina:</b> {$favpet->stamina}<br>
					</td>
					<td width='20%'>
					<center><b>VS</b></center>
					</td>
					<td width='40%' style='text-align:right;vertical-align:bottom'>
					<i>Opponent</i><br>
					<b>Sense:</b> {$opsense}<br>
					<b>Speed:</b> {$opspeed}<br>
					<b>Strength:</b> {$opstrength}<br>
					<b>Stamina:</b> {$opstamina}<br>
					</td>
				</tr>
			</table><br><center>Your pet dives in and attacks your opponent with a bite dealing {$bite} damage.
						<br>The opponent counters the attack with {$opbite} damage, and manages to over power {$favpet->name}!<br>
						Unfortunately your pet lost...better luck next time!</center><br><br>", FALSE));
					}
				break;
				case "Use_Tackle": 
					$optackle = $opstrength + $opstamina;
					$tackle = $favpet->strength + $favpet->stamina;
					$prize = rand(25,50);
					$currentcash = $mysidia->user->money;
					$newmoney = $prize + $currentcash;
					if($tackle > $optackle){
						$document->add(new Comment("<br><br>
						<table align='center' border='0px'>
					<tr>
					<td width='40%' style='text-align:left;vertical-align:bottom;'>
					<i>{$favpet->name}</i><br>
					<b>Sense:</b> {$favpet->sense}<br>
					<b>Speed:</b> {$favpet->speed}<br>
					<b>Strength:</b> {$favpet->strength}<br>
					<b>Stamina:</b> {$favpet->stamina}<br>
					</td>
					<td width='20%'>
					<center><b>VS</b></center>
					</td>
					<td width='40%' style='text-align:right;vertical-align:bottom'>
					<i>Opponent</i><br>
					<b>Sense:</b> {$opsense}<br>
					<b>Speed:</b> {$opspeed}<br>
					<b>Strength:</b> {$opstrength}<br>
					<b>Stamina:</b> {$opstamina}<br>
					</td>
				</tr>
			</table><br><center>Your pet launches forward and slams into the opponent, dealing {$tackle} damage!
						<br>The opponent counters the attack with {$optackle} damage, but it isn't enough!<br>
						Your pet has won, and brought you {$prize} currency! Furthermore, {$favpet->name} has won a trophy!</center><br><br>", FALSE));
						$mysidia->db->update("users", array("money" => $newmoney), "username='{$mysidia->user->username}'");
						$mysidia->db->update("owned_adoptables", array("trophies" => $newtrophy), "aid='{$profile->getFavpetID()}'");
					}
					else{
						$document->add(new Comment("<br><br>
						<table align='center' border='0px'>
					<tr>
					<td width='40%' style='text-align:left;vertical-align:bottom;'>
					<i>{$favpet->name}</i><br>
					<b>Sense:</b> {$favpet->sense}<br>
					<b>Speed:</b> {$favpet->speed}<br>
					<b>Strength:</b> {$favpet->strength}<br>
					<b>Stamina:</b> {$favpet->stamina}<br>
					</td>
					<td width='20%'>
					<center><b>VS</b></center>
					</td>
					<td width='40%' style='text-align:right;vertical-align:bottom'>
					<i>Opponent</i><br>
					<b>Sense:</b> {$opsense}<br>
					<b>Speed:</b> {$opspeed}<br>
					<b>Strength:</b> {$opstrength}<br>
					<b>Stamina:</b> {$opstamina}<br>
					</td>
				</tr>
			</table><br><center>Your pet launches forward and slams into the opponent, dealing {$tackle} damage!
						<br>The opponent counters the attack with {$opbite} damage, and manages to over power {$favpet->name}!<br>
						Unfortunately your pet lost...better luck next time!</center><br><br>", FALSE));
					}
				break;
				case "Use_Trick": 
					$optrick = $opsense + $opspeed;
					$trick = $favpet->sense + $favpet->speed;
					$prize = rand(25,50);
					$currentcash = $mysidia->user->money;
					$newmoney = $prize + $currentcash;
					if($trick > $optrick){
						$document->add(new Comment("<br><br>
						<table align='center' border='0px'>
					<tr>
					<td width='40%' style='text-align:left;vertical-align:bottom;'>
					<i>{$favpet->name}</i><br>
					<b>Sense:</b> {$favpet->sense}<br>
					<b>Speed:</b> {$favpet->speed}<br>
					<b>Strength:</b> {$favpet->strength}<br>
					<b>Stamina:</b> {$favpet->stamina}<br>
					</td>
					<td width='20%'>
					<center><b>VS</b></center>
					</td>
					<td width='40%' style='text-align:right;vertical-align:bottom'>
					<i>Opponent</i><br>
					<b>Sense:</b> {$opsense}<br>
					<b>Speed:</b> {$opspeed}<br>
					<b>Strength:</b> {$opstrength}<br>
					<b>Stamina:</b> {$opstamina}<br>
					</td>
				</tr>
			</table><br><center>Your pet taunts the opponent and dashes out of the way at the last minute, tricking the opponent into running at the wall, dealing {$trick} damage!
						<br>The opponent counters the attack with {$optrick} damage, but it isn't enough!<br>
						Your pet has won, and brought you {$prize} currency! Furthermore, {$favpet->name} has won a trophy!</center><br><br>", FALSE));
						$mysidia->db->update("users", array("money" => $newmoney), "username='{$mysidia->user->username}'");
						$mysidia->db->update("owned_adoptables", array("trophies" => $newtrophy), "aid='{$profile->getFavpetID()}'");
					}
					else{
						$document->add(new Comment("<br><br>
						<table align='center' border='0px'>
					<tr>
					<td width='40%' style='text-align:left;vertical-align:bottom;'>
					<i>{$favpet->name}</i><br>
					<b>Sense:</b> {$favpet->sense}<br>
					<b>Speed:</b> {$favpet->speed}<br>
					<b>Strength:</b> {$favpet->strength}<br>
					<b>Stamina:</b> {$favpet->stamina}<br>
					</td>
					<td width='20%'>
					<center><b>VS</b></center>
					</td>
					<td width='40%' style='text-align:right;vertical-align:bottom'>
					<i>Opponent</i><br>
					<b>Sense:</b> {$opsense}<br>
					<b>Speed:</b> {$opspeed}<br>
					<b>Strength:</b> {$opstrength}<br>
					<b>Stamina:</b> {$opstamina}<br>
					</td>
				</tr>
			</table><br><center>Your pet taunts the opponent and dashes out of the way at the last minute, tricking the opponent into running at the wall, dealing {$trick} damage!
						<br>The opponent counters the attack with {$optrick} damage, and manages to over power {$favpet->name}!<br>
						Unfortunately your pet lost...better luck next time!</center><br><br>", FALSE));
					}
				break;
			}

            return;
        }
	}

    public function exploreButton($areaname, $image_link = "", $customtext = "", $customimg = ""){
        $document = $this->document;
        
        if ($image_link){ /* Image Links */
            
             if (!$customimg){ /* Area Logo Image */
                 $imgname = str_replace("*", "'", $areaname);
                $document->add(new Comment("
                    <form id='exploreform' action='battle' name='exploreform' method='post' role='form'>
                    <input id='area' name='area' type='hidden' value='{$areaname}'>
                    <button id='{$areaname}' class='btn-text btn-sm' value='battle' name='{$areaname}' type='submit'>
                    <img src=\"./images/{$imgname}_logo.png\"/>
                    </button>
                    </form>
                ", FALSE)); 
             }
             
             else { /* Custom Link Image */
                 $imgname = str_replace("*", "'", $customimg);
                $document->add(new Comment("
                    <form id='exploreform' action='battle' name='exploreform' method='post' role='form'>
                    <input id='area' name='area' type='hidden' value='{$areaname}'>
                    <button id='{$areaname}' class='btn-text btn-sm' value='battle' name='{$areaname}' type='submit'>
                    <img src=\"./images/{$imgname}\"/>
                    </button>
                    </form>
                ", FALSE)); 
             }
        } 
        
        else { /* Text-Only Links */
            
            if (!$customtext){ /* Area Name Button */
                $str = str_replace("_", " ", $areaname); $btn_name = str_replace("*", "'", $str);
                $document->add(new Comment("
                    <form id='exploreform' action='battle' name='exploreform' method='post' role='form'>
                    <input id='area' name='area' type='hidden' value='{$areaname}'>
                    <button id='{$areaname}' class='btn-violet btn-sm' value='battle' name='{$areaname}' type='submit'>
                    {$btn_name}
                    </button>
                    </form>
                ", FALSE));
            } 
            
            else { /* Custom Link Text */
                $customtext = str_replace("*", "'", $customtext);
                $document->add(new Comment("
                    <form id='exploreform' action='battle' name='exploreform' method='post' role='form'>
                    <input id='area' name='area' type='hidden' value='{$areaname}'>
                    <button id='{$areaname}' class='btn-violet btn-sm' style='display: inline;' value='battle' name='{$areaname}' type='submit'>
                    {$customtext}
                    </button>
                    </form>
                ", FALSE));
            }
        }
        return;
    }
}	
?>

Note lines 20 and 24:
PHP:
if ($favpet->currentlevel < 3)
PHP:
if($favpet->currentlevel = 3)
These make it so that if the user's assigned fave pet must be level 3 in order to battle. Change this number to whichever suits your needs (and remember the levels start at 0 for the egg).

Also note lines 49, 108, and 169:
PHP:
	$prize = rand(25,50);
This determines how much the user will be awarded each time their pet wins. The first number (25) is the minimum amount, and the second number (50) is the maximum amount.

There are many places in the code where you can alter and customize the text to your liking. For example, each attack uses two different stats, combines them to get a total, and uses that total against a similar total for the opponent.

Ask about it if you have questions!

Continue reading below for a guide on adding a simply trophy system!
 
Last edited:
P.4: Trophies
Alright, finally ready for this!
Trophies are just another little extra thing that gives users more reason to engage in the battle system. I add extra incentive by rearranging my stats page to display based on number of trophies instead of clicks.

The battle code up above is already set up to add trophies, so no need to worry about that. We do have to set up the database, though.

Database
Go into phpMyAdmin, prefix_ownedadoptables, and add one new row with the following data:
Name Type Collation Null Default
trophies varchar(10) latin1_swedish_ci No 0

Displaying
Good job! Now in a file where you want to display the number of trophies (such as on the myadopts page, etc), you just need to include this to call it:
PHP:
$trophies = $mysidia->db->select("owned_adoptables", array("trophies"), "aid = '{$adopt->getAdoptID()}'")->fetchColumn();

and this to display it:
PHP:
{$trophies}

Stats Page
If you want to use the stats page to show adopts based on trophies instead of clicks there is just a minor adjustment to make.

Go to stats.php and change the FIRST line starting with "$stmt = " and replace that line with this:
PHP:
$stmt = $mysidia->db->select("owned_adoptables", array("aid"), "1 ORDER BY trophies DESC LIMIT 10");

Now go into view/statsview.php...we have some things here to change so it actually displays the trophies.

Where you see the line $table->buildHeaders...replace it with this:
PHP:
$table->buildHeaders("Image", "Name", "Owner", "Total Clicks", "Trophies");

Now, scroll down to find this line:
PHP:
$cells->add(new String($adopt->getTotalClicks()));

And add this right under it:
PHP:
$cells->add(new TCell($adopt->getTrophies()));

That's it! You might also want to change the lang_stats.php file so that it reflects the changes.

P.5: Extras
You can add extra depth to this by creating other stats, such as health, battle skill, etc! Check out Dinocanid's health and mood mod, which could pair with this very nicely!
http://mysidiaadoptables.com/forum/showthread.php?t=5263
 
Last edited:
Surprised no one commented to this!

Thank you for making this, I'm going to try it on one or more of my sites!! This looks pretty fantastic!!
 
Before I had a favpet selected, it came up ok and asked me to go choose a Companion -- I manually input the number of one of my pets in the appropriate section in the database (for the life of me I cannot remember how to just go choose one!) -- and got a white page!

This seems to be my time to get white pages haha. Got one on this and for every try at a public pet profile page so far ...



edit: Did find where to choose him in my account page, but still white page now for battle
 
Last edited:
Is anyone else using this or getting a white page from it ?

I'm two days from launching and I am considering not trying to use this, though it looks so fun ...
 
Missy Master, try doing it through the user CP instead? Go to /account/profile, and then select your pet from the drop down there. Then get back to me and let me know if it persists!
 
Still not working :(

If I remove the fav pet from the database, the page loads .. but once that id is in there, nope!



'It seems you do not yet have not assigned a companion! Assign one and then come back. ' With no fav pet assigned. With one, white page!
 
Thought I would add in something here, maybe shed a little more light on the issue.

I'm seeing the same problem Missy did.

My error log is showing:
PHP:
[01-Sep-2016 22:15:11 America/Chicago] PHP Fatal error:  Uncaught exception 'Exception' with message 'Fatal Error: Class Owned_Adoptable either does not exist, or has its include path misconfigured!' in /home/mystfell/public_html/classes/class_loader.php:83
Stack trace:
#0 [internal function]: Loader->load('Owned_Adoptable')
#1 /home/mystfell/public_html/view/battleview.php(18): spl_autoload_call('Owned_Adoptable')
#2 /home/mystfell/public_html/classes/class_frontcontroller.php(100): battleView->index()
#3 /home/mystfell/public_html/index.php(74): FrontController->render()
#4 /home/mystfell/public_html/index.php(78): IndexController::main()
#5 {main}
  thrown in /home/mystfell/public_html/classes/class_loader.php on line 83
[01-Sep-2016 22:16:22 America/Chicago] PHP Notice:  Undefined variable: controller in /home/mystfell/public_html/classes/class_language.php on line 111
[01-Sep-2016 22:16:22 America/Chicago] PHP Fatal error:  Cannot access protected property OwnedAdoptable::$currentlevel in /home/mystfell/public_html/view/battleview.php on line 20
 
Good news is, I partly found the answer to my question. For whatever reason, it can't pull from "currentlevel". Changing it to "AdoptLevel", "Level", and "CurrentLevel" allows the page to load, but doesn't allow me to battle, nor does it show my "favpet", insisting that my pet isn't level 1 or higher.

Looking at the error log after each save, seems like it keeps bumping on how to call the level of the pet. x.x So, now what?
 
Last edited:
I can't get this to work either. I can get to the page just fine, but it keeps insisting that my favpet isn't level 3.
 
Good news is, I partly found the answer to my question. For whatever reason, it can't pull from "currentlevel". Changing it to "AdoptLevel", "Level", and "CurrentLevel" allows the page to load, but doesn't allow me to battle, nor does it show my "favpet", insisting that my pet isn't level 1 or higher.

Looking at the error log after each save, seems like it keeps bumping on how to call the level of the pet. x.x So, now what?


I responded via PM but I'll paste this here for other's sakes:
Try going into class_ownedadoptable.php and changing the line here:
PHP:
	protected $currentlevel;
to this:
PHP:
	public $currentlevel;

Save, upload, and let me know if that fixes your issue :)

Everyone having the issue please make sure this has been done and then, once done, get back to me on it.
 
THANK YOU! <3 Okay, so it didn't like that both the "currentlevel" and "name" were protected, instead of public. Changing that made it work for me!
 
Now that I have this working, I'd like to add some graphics and such to make it more fun to look at and give their opponent a "face". So, my question here is, how would I go about perhaps using random images above the "random opponent side? I know how to post the image of the pet, but a random image code would be awesome. 8D Would be neat to also use this to make it seem like the "battleground" as changed. Just a thought!
 
Oh yeah, that is totally doable! I actually originally had it set up that way but was having issues with aligning it in a way that looked really good...but the random opponent image isn't too difficult. You just need the images...so, where you add opponent stats add in this:
PHP:
$images = rand(1,3);
Change the 3 to suit whatever number of images you want possible. Then, below the stats add this:
PHP:
if($images = 1) {
$opimage = "<img src='IMAGE URL'/>";
}
elseif($images = 2) {
$opimage = "<img src='IMAGE URL'/>";
}
elseif($images = 3) {
$opimage = "<img src='IMAGE URL'/>";
}

Where it says IMAGE URL just change it to the image's url for the different opponent images. Then where you display the opponent's stats just add in {$opimage}. So, for example:
PHP:
<td width='40%' style='text-align:right;vertical-align:bottom'> 
{$opimage}<br>                    
<i>Opponent</i><br> 
                    <b>Sense:</b> {$opsense}<br> 
                    <b>Speed:</b> {$opspeed}<br> 
                    <b>Strength:</b> {$opstrength}<br> 
                    <b>Stamina:</b> {$opstamina}<br> 
                    </td>


Now I will note that I just wrote this without testing it at all, so I don't guarantee it'll work as is, but it should give you the general idea!
 
Hey all! I updated the main post so that it now includes the training section! My method of training is very lazy at the moment, just spend some money, click a button, raise the stats.

I hope you all enjoy it <3
 
Finally updated!

Now includes a Trophies section, and a little extras section :)
 
couple questions- I tried adding in the OP image coding but it keeps giving me errors... WHERE exactly do I put those? CAn you explain a little better please?

Also the trophies- where exactly and on which file do I put the calling code?

As well as How would I get my fave pets image for battling as well? {$Favepet} does not seem to work lol (And how would I flip the images so they're actually facing each other?)

EDIT: one more question- how would I make it so that they actually recieve items for winning? whether random or not so random lol...

(Apologies as I am a super noob at this)
 
Last edited:
1. In the battleview.php file find this:
PHP:
 /*Random Opponent Stats*/ 
        $opsense = rand(1,100); 
        $opstamina = rand(1,100); 
        $opstrength = rand(1,100); 
        $opspeed = rand(1,100);

Insert the image code right below that, so it looks like this:
PHP:
 /*Random Opponent Stats*/ 
$opsense = rand(1,100); 
$opstamina = rand(1,100); 
$opstrength = rand(1,100); 
$opspeed = rand(1,100); 
$images = rand(1,3);  
if($images = 1) {
$opimage = "<img src='IMAGE URL'/>";
}
elseif($images = 2) {
$opimage = "<img src='IMAGE URL'/>";
}
elseif($images = 3) {
$opimage = "<img src='IMAGE URL'/>";
}

The image url needs to start with http:// and end in .jpg, .jpeg, .png, or .gif

2. You put the calling code wherever you want to display the trophies. So if you want to display it for the owner of a pet when they go to manage it, you can go to myadoptsview.php and add it within the manage function. This works best if you already have "profiles" set up. But for a quick example, here is the manage function with it added in:
PHP:
	public function manage(){
		$mysidia = Registry::get("mysidia");
		$aid = $this->getField("aid")->getValue();
		$name = $this->getField("name")->getValue();
		$image = $this->getField("image");

		$trophies = $mysidia->db->select("owned_adoptables", array("trophies"), "aid = '{$adopt->getAdoptID()}'")->fetchColumn();

		$document = $this->document;		
		$document->setTitle("Managing {$name}");
		$document->add($image);
		$document->add(new Comment("<br><br>This page allows you to manage {$name}.  Click on an option below to change settings.<br>
<center>{$name} has {$trophies} trophies!</center><br>"));
		
		$document->add(new Image("templates/icons/add.gif"));
		$document->add(new Link("levelup/click/{$aid}", " Level Up {$name}", TRUE));
		$document->add(new Image("templates/icons/stats.gif"));
		$document->add(new Link("myadopts/stats/{$aid}", " Get Stats for {$name}", TRUE));
		$document->add(new Image("templates/icons/bbcodes.gif"));
		$document->add(new Link("myadopts/bbcode/{$aid}", " Get BBCodes / HTML Codes for {$name}", TRUE));
	   	$document->add(new Image("templates/icons/title.gif"));
		$document->add(new Link("myadopts/rename/{$aid}", " Rename {$name}", TRUE)); 
		$document->add(new Image("templates/icons/trade.gif"));
		$document->add(new Link("myadopts/trade/{$aid}", " Change Trade status for {$name}", TRUE)); 
		$document->add(new Image("templates/icons/freeze.gif"));
		$document->add(new Link("myadopts/freeze/{$aid}", " Freeze or Unfreeze {$name}", TRUE)); 
		$document->add(new Image("templates/icons/delete.gif"));
		$document->add(new Link("pound/pound/{$aid}", " Pound {$name}", TRUE)); 
	}

3. The base code for displaying it is this:
PHP:
<img src='{$favpet->getImage()}'/>

But you also need to include this information to make it callable:
PHP:
$profile = $mysidia->user->getprofile();
$favpet = new OwnedAdoptable($profile->getFavpetID());

As for flipping, not sure, I googled it and apparently this works (I have not tested it):
PHP:
$opimage = "<img src='IMAGE URL' style='-moz-transform: scale(-1, 1);-webkit-transform: scale(-1, 1);-o-transform: scale(-1, 1);transform: scale(-1, 1);filter: FlipH;' />";

4. To directly insert an item into a user's inventory you use this string:
PHP:
$item = "ItemName";
PHP:
$newitem = new StockItem($item);  
$newitem->append(1, $mysidia->user->username);
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

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

Latest Threads

Latest Posts

Top