Item to change an adopts species

Forum
Last Post
Threads / Messages

Ittermat

The awesomesauce
Member
Joined
Feb 2, 2016
Messages
310
Points
18
Location
in front of my laptop
Mysidian Dollar
21,337
I thought that was what the Alts1 did...but thats apparently not it... is there a way to make it so certain items will change a species from one to another?

For example on my site- I have memorial pets- made to look like pets that people have lost... SO! if you take any pet-
We'll use a catari..

c130f7955dbfe6ac72e874b9045b182f.png
if I take an item pertaining to that lost pet--- like Chikus pocky stick?
u3slf.jpg


I want that pet to change to the Chiku-Banzai species..

rsug3k.jpg


For an example for what Im trying to do XD

Please and thanks <3
 
See all the "speciesAname" written in the code? Replace that with the species you want to change an adopt into.
 
but what if I want to do mulitple species with mulitple items...?

like..One item changes to this species..

a different item changes to a different species than the first one....

Etc.
 
EDIT: WAIT I THINK I GET IT! AUGH...***** I AM...
EDIT EDIT: nope still have the error...

Also when I try to go to my adopts page I get this error...

"
Fatal error: Uncaught exception 'AdoptNotfoundException' with message 'Adoptable speciesAname does not exist...' in /home/atrocity/public_html/classes/class_adoptable.php:26 Stack trace: #0 /home/atrocity/public_html/classes/class_ownedadoptable.php(28): Adoptable->__construct('speciesAname') #1 /home/atrocity/public_html/view/myadoptsview.php(26): OwnedAdoptable->__construct('66') #2 /home/atrocity/public_html/classes/class_frontcontroller.php(100): MyadoptsView->index() #3 /home/atrocity/public_html/index.php(74): FrontController->render() #4 /home/atrocity/public_html/index.php(78): IndexController::main() #5 {main} thrown in /home/atrocity/public_html/classes/class_adoptable.php on line 26"

and heres whats on my line 21-30 in class adoptable

Code:
    public function __construct($adoptinfo){	  
	    $mysidia = Registry::get("mysidia");
	    if($adoptinfo instanceof String) $adoptinfo = $adoptinfo->getValue();		
	    $whereClause = (is_numeric($adoptinfo))?"id ='{$adoptinfo}'":"type ='{$adoptinfo}'";
	    $row = $mysidia->db->select("adoptables", array(), $whereClause)->fetchObject();
        if(!is_object($row)) throw new AdoptNotfoundException("Adoptable {$adoptinfo} does not exist...");
        foreach($row as $key => $val){
            $this->$key = $val;     		 
        }	  
    }

And here is my functions_Items code...
  Spoiler: code 

Code:
<?php

// File ID: functions_items.php
// Purpose: Provides specific functions defined for items

function items_valuable($item, $adopt){
  $note = "The item {$item->itemname} is a valuable item, which cannot be used on any adoptable but may sell a good deal of money.";
  return $note;
}

function items_level1($item, $adopt){
  $mysidia = Registry::get("mysidia");
  $newlevel = $adopt->currentlevel + $item->value;
  $lev = $mysidia->db->select("levels", array(), "adoptiename='{$adopt->type}' and thisislevel ='{$newlevel}'")->fetchObject();
  
    //Check if the adoptable's level is already at maximum.    
  if(!is_object($lev)){
    // object not created, the level is already at maximum.
    $note = "Unfortunately, your selected adoptable's level cannot be raised by using item {$item->itemname}.";
  }
  else{
    //Update item quantity...
    $delitem = $item->remove();
    //Execute the script to update adoptable's level and clicks.
    $mysidia->db->update("owned_adoptables", array("currentlevel" => $newlevel, "totalclicks" => $lev->requiredclicks), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
    $note = "Congratulations, the item {$item->itemname} raised your adoptable's level by {$item->value}";
  }
  return $note;
}

function items_level2($item, $adopt){
  $mysidia = Registry::get("mysidia");
  $newlevel = $item->value;
  $lev = $mysidia->db->select("levels", array(), "adoptiename='{$adopt->type}' and thisislevel ='{$newlevel}'")->fetchObject();

    //Check if the adoptable's level is already at maximum.    
  if(!is_object($lev)){
    // object not created, the level is already at maximum.
    $note = "Unfortunately, your selected adoptable's level cannot be raised by using item {$item->itemname}.";
  }
  else{
    //Update item quantity...
    $delitem = $item->remove(); 
    //Execute the script to update adoptable's level and clicks.
	$mysidia->db->update("owned_adoptables", array("currentlevel" => $newlevel, "totalclicks" => $lev->requiredclicks), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
    $note = "Congratulations, the item {$item->itemname} increases your adoptable's level to {$item->value}";
  }
  return $note;
}

function items_level3($item, $adopt){
  $mysidia = Registry::get("mysidia");
  //Update item quantity...
  $delitem = $item->remove();
    //Execute the script to update adoptable's level and clicks.
  $mysidia->db->update("owned_adoptables", array("currentlevel" => 0, "totalclicks" => 0), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
  $note = "Congratulations, the item {$item->itemname} has reset the level and clicks of your adoptable.";
  return $note;
}

function items_click1($item, $adopt){
  $mysidia = Registry::get("mysidia");
  $newclicks = $adopt->totalclicks + $item->value;
  $mysidia->db->update("owned_adoptables", array("totalclicks" => $newclicks), "aid='{$adopt->aid}'and owner='{$item->owner}'");
  $note = "By using {$item->itemname}, the adoptable's total number of clicks has raised by {$item->value}<br>";
  //Now lets check if the adoptable has reached a new level.
  
  $ownedAdopt = new OwnedAdoptable($adopt->aid);
  if($ownedAdopt->hasNextLevel()){
      //new level exists, time to check if the total clicks have reached required minimum clicks for next level.
	 $nextLevel = $ownedAdopt->getNextLevel();
	 $requiredClicks = $nextLevel->getRequiredClicks();
     if($newclicks >= $requiredClicks and $requiredClicks != 0 and $requiredClicks != ""){
	    // We need to level this adoptable up...
        $mysidia->db->update("owned_adoptables", array("currentlevel" => $nextLevel->getLevel()), "aid ='{$adopt->aid}' and owner='{$item->owner}'");		     
        $note .= "And moreover, it has gained a new level!";
     }
  }
  //Update item quantity...
  $delitem = $item->remove(); 
  return $note;
}

function items_click2($item, $adopt){
  $mysidia = Registry::get("mysidia");
  $newclicks = $item->value;
  $mysidia->db->update("owned_adoptables", array("totalclicks" => $newclicks), "aid='{$adopt->aid}'and owner='{$item->owner}'");
  $note = "By using {$item->itemname}, the adoptable's total number of clicks has raised by {$item->value}<br>";
  //Now lets check if the adoptable has reached a new level.
  
  $ownedAdopt = new OwnedAdoptable($adopt->aid);
  if($ownedAdopt->hasNextLevel()){
      //new level exists, time to check if the total clicks have reached required minimum clicks for next level.
	 $nextLevel = $ownedAdopt->getNextLevel();
	 $requiredClicks = $nextLevel->getRequiredClicks();
     if($newclicks >= $requiredClicks and $requiredClicks != 0 and $requiredClicks != ""){
	    // We need to level this adoptable up...
        $mysidia->db->update("owned_adoptables", array("currentlevel" => $nextlevel), "aid ='{$adopt->aid}' and owner='{$item->owner}'");	  
        $note .= "And moreover, it has gained a new level!";
     }
  }

  //Update item quantity...
  $delitem = $item->remove(); 
  return $note;
}

function items_click3($item, $adopt){ 
  $mysidia = Registry::get("mysidia");
  $date = date('Y-m-d'); 
  $mysidia->db->delete("vote_voters", "adoptableid = '{$adopt->aid}' and date='{$date}'");
  //Update item quantity...
  $delitem = $item->remove(); 
  $note = "By using item {$item->name}, you have make your adoptables eligible for clicking by everyone again!";
  return $note;
}

function items_breed1($item, $adopt){
  $mysidia = Registry::get("mysidia");
  // Update the lastbred info.
  $mysidia->db->update("owned_adoptables", array("lastbred" => 0), "aid ='{$adopt->aid}' and owner='{$item->owner}'");	
  $note = "The item has been successfully used on your adoptable, it can breed again!<br>";
  //Update item quantity...
  $delitem = $item->remove(1, $item->owner);  
  return $note;
}

function items_breed2($item, $adopt){
  $mysidia = Registry::get("mysidia");
  // Note this function exists but is not useful until Mys v1.3.2, when adoptables can carry/attach items.
  $mysidia->db->update("owned_adoptables", array("lastbred" => 0), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
  $note = "The item has been successfully used on your adoptable, it can breed again!<br>";
  //Update item quantity...
  $delitem = $item->remove(); 
  return $note;
}
function items_alts1($item, $adopt){
  $mysidia = Registry::get("mysidia");
  // First lets check if alternative image exists for an adoptable at this level.
  $lev = $mysidia->db->select("levels", array(), "adoptiename='{$adopt->type}' and thisislevel ='{$adopt->currentlevel}'")->fetchObject();
  if($lev->alternateimage == ""){
      // The alternate image does not exist, cannot convert adoptable into its alternate form
    $note = "It appears that your adoptable does not have an alternate image at its given level...<br>";
  }
  
  else{
      // The alternate image exists, conversion between primary and alternate image is possible.
    switch($adopt->usealternates){
      case "yes": 
        $mysidia->db->update("owned_adoptables", array("usealternates" => 'no'), "aid ='{$adopt->aid}' and owner='{$item->owner}'");		
        $note = "Your adoptable has assume the species primary form.";
        break;
      default:
        $mysidia->db->update("owned_adoptables", array("usealternates" => 'yes'), "aid ='{$adopt->aid}' and owner='{$item->owner}'");	   
        $note = "Your adoptable {$adopt->name} has assume the species alternate form.";
    }
    //Update item quantity...
    $delitem = $item->remove();    
    return $note;    
}

function items_alts2($item, $adopt){
  $note = "This feature will be available soon after we redesign the adoptable class, enjoy!";
  return $note;
}
function items_Chiku1($item, $adopt){
  $mysidia = Registry::get("mysidia");
  $mysidia->db->update("owned_adoptables", array("type" => 'Chiku-Banzai'), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
  $note = "The item has been successfully used on your adoptable, it is now a {$adopt->type}!<br>";
  //Update item quantity...
  $delitem = $item->remove(); 
  return $note;
} 
function items_Luv1($item, $adopt){
  $mysidia = Registry::get("mysidia");
  $mysidia->db->update("owned_adoptables", array("type" => 'Luv-Bug'), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
  $note = "The item has been successfully used on your adoptable, it is now a {$adopt->type}!<br>";
  //Update item quantity...
  $delitem = $item->remove(); 
  return $note;
} 
function items_Zoey1($item, $adopt){
  $mysidia = Registry::get("mysidia");
  $mysidia->db->update("owned_adoptables", array("type" => 'Zoey'), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
  $note = "The item has been successfully used on your adoptable, it is now a {$adopt->type}!<br>";
  //Update item quantity...
  $delitem = $item->remove(); 
  return $note;
} 
function items_Smoke1($item, $adopt){
  $mysidia = Registry::get("mysidia");
  $mysidia->db->update("owned_adoptables", array("type" => 'Smoke'), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
  $note = "The item has been successfully used on your adoptable, it is now a {$adopt->type}!<br>";
  //Update item quantity...
  $delitem = $item->remove(); 
  return $note;
} 
}   
function items_recipe($item, $adopt){
  $note = "The item {$item->itemname} is a recipe item, which cannot be used on any adoptable and can only be useful if you are performing alchemy.";
  return $note;
}

function items_name1($item, $adopt){
  $note = "umm just realized that people can change adoptables names freely, will have to think about it later.";
  return $note;
}

function items_name2($item, $adopt){
  $note = "For now the items can only be used on adoptables, so user-based item usage will be implemented later.";
  return $note;
}
?>


And my Privateitem.php

  Spoiler: code 
Code:
<?php

use Resource\Native\String;

class PrivateItem extends Item{
  // The PrivateItem class, which defines functionalities for items that belong to specific users

  public $iid;
  public $owner;
  public $quantity;
  public $status;
  
  public function __construct($iteminfo, $itemowner = ""){     
	  // the item is an owned item in user inventory, so retrieve database info to assign properties
	  $mysidia = Registry::get("mysidia");
	  
	  $fetchmode = (is_numeric($iteminfo))?"iid":"itemname";
      $whereclause = ($fetchmode == "iid")?"{$fetchmode} = '{$iteminfo}'":"{$fetchmode} ='{$iteminfo}' and owner = '{$itemowner}'";		  
      $row = $mysidia->db->select("inventory", array(), $whereclause)->fetchObject();
	  if(is_object($row)){
	     // loop through the anonymous object created to assign properties
	     foreach($row as $key => $val){
            $this->$key = $val;
         }
	     parent::__construct($this->itemname);
      }
      else $this->iid = 0;	  
  }
 
  public function getitem(){
      // This method checks if the item exists in inventory or not, not to be confused with parent class' getitem() class.
	  $mysidia = Registry::get("mysidia");
	  $stmt = $mysidia->db->select("inventory", array(), "itemname ='{$this->itemname}' and owner ='{$this->owner}'"); 
	  return $stmt->fetchObject();
  }
 
  public function getvalue($quantity = 0, $discount = 0.5){
      // This method returns the cost of items.
	  
      $value = $this->price*$quantity*$discount;
	  return $value;
  }
  
  public function apply($adopt = "", $user = ""){
      // This method uses 
      $mysidia = Registry::get("mysidia");
	  require_once("functions/functions_items.php");
	  
      if(is_numeric($adopt)) $owned_adoptable = $mysidia->db->select("owned_adoptables", array(), "aid ='{$adopt}'")->fetchObject();
      if(!empty($user)) $theuser = $mysidia->db->select("users", array(), "username ='{$user}'")->fetchObject();
	  
      // Now we decide which function to call...
      switch($this->function){
         case "Valuable": 
            $message = items_valuable($this, $owned_adoptable);
            break;
         case "Level1":
            $message = items_level1($this, $owned_adoptable);
            break;
         case "Level2":
            $message = items_level2($this, $owned_adoptable);
            break;
         case "Level3":
            $message = items_level3($this, $owned_adoptable);
            break;
         case "Click1":
            $message = items_click1($this, $owned_adoptable);
            break;
         case "Click2":
            $message = items_click2($this, $owned_adoptable);
            break;
         case "Breed1":
            $message = items_breed1($this, $owned_adoptable);
            break;
         case "Breed2":
            $message = items_breed2($this, $owned_adoptable);
            break;
         case "Alts1":
            $message = items_alts1($this, $owned_adoptable);
            break;
         case "Alts2":
            $message = items_alts2($this, $owned_adoptable);
            break;
         case "Name1":
            $message = items_name1($this, $theuser);
            break;
         case "Name2":
            $message = items_name2($this, $theuser);
            break; 
case "Chiku1":
            $message = items_Chiku1($this, $owned_adoptable);
            break;  
case "Luv1":
            $message = items_Luv1($this, $owned_adoptable);
            break;  
case "Zoey1":
            $message = items_Zoey1($this, $owned_adoptable);
            break;  
case "Smoke1":
            $message = items_Smoke1($this, $owned_adoptable);
            break;  
	 default:
            throw new ItemException("The item function is invalid");		 
      }
	  return new String($message);
  }  

  public function add($quantity = 1, $owner){

  }

  public function sell($quantity = 1, $owner = ""){
      // This method sells items from user inventory
	  $mysidia = Registry::get("mysidia");
	  
      $this->owner = (!empty($owner))?$owner:$this->owner;
      $earn = $this->getvalue($quantity);      
      $newamount = $mysidia->user->money + $earn;
	  
      if($this->remove($quantity)){
         $mysidia->db->update("users", array("money" => $newamount), "username = '{$this->owner}'");
	     return TRUE;
      }
      else return FALSE; 	 
  }
  
  public function toss($owner = ""){
	  $this->remove($this->quantity);
	  return TRUE;
  }
  
  public function remove($quantity = 1, $owner = ""){
      // This method removes items from user inventory
  
      $mysidia = Registry::get("mysidia");
      $this->owner = (!empty($owner))?$owner:$this->owner;
      $newquantity = $this->quantity - $quantity;
	  if(empty($this->quantity) or $newquantity < 0) return FALSE;
	  else{
	     switch($newquantity){
		    case 0:
			   $mysidia->db->delete("inventory", "itemname='{$this->itemname}' and owner='{$this->owner}'");
			   break;
			default:
			   $mysidia->db->update("inventory", array("quantity" => $newquantity), "itemname ='{$this->itemname}' and owner='{$this->owner}'");
		 }
	     return TRUE;
	  }
  }
  
  public function checktarget($aid){
      // This method checks if the item is usable
	  $adopt = new OwnedAdoptable($aid);
      $id = $adopt->getID();
	  $item_usable = FALSE;
	  switch($this->target){
         case "all":
		    $item_usable = TRUE;
		    break;
         case "user":
		    $item_usable = TRUE;
		    break;
		 default:
		    $target = explode(",",$this->target);
            if(in_array($id, $target)) $item_usable = TRUE;			
	  }
	  return $item_usable;
  }
  
  public function randomchance(){
      // This method returns the item image in standard html form
	  $mysidia = Registry::get("mysidia");
	  switch($this->chance){
	     case 100:
            $item_usable = TRUE;
		    break;
         default:
		    $temp = mt_rand(0,99);
			$item_usable = ($temp < $this->chance)?TRUE:FALSE;
	  }
      return $item_usable;	  
  }
}
?>

I just cant figure this out.. x.x
 
Last edited:
I'm using v.1.3.3, so I'm not sure if you need this for your version, but did you remember to add these functions to your database?
 
yep I did that... x.x

I have no idea where its pulling "SpeciesAname" from...

Umm... not sure... but do you have any adoptables in your database with "SpeciesAname" as a species? If so, try removing them?
 
I dont...I didnt make a species with that name...
what happened was in the beginning I didnt realize what it meant- so when i made the first function it was called "species"

And Im sure I changed "Speciesaname" To species also...because I had no idea what I was doing...

Then I realized...and tried to fix it...so I have no clue where species a name is coming from...
 
Last edited:
Check to see if you have any owned adoptables with speciesA as the type. Go to your database owned_adoptables and check the type column. Click the arrow next to 'type' to get it ordered alphabetically. Makes it easier!

If you do, change it to the correct species
 
nope no adoptable by that type there...

EDIT Ah! yes there was... XD STupid me...

Thank you...Im an idiot

Now to get the Species changes to work XD
 
Last edited:

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,280
Messages
33,130
Members
1,603
Latest member
Monako
BETA

Latest Threads

Top