Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Tutorials and Tips (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=27)
-   -   Held Items & Pet Companions (http://www.mysidiaadoptables.com/forum/showthread.php?t=5094)

tahbikat 03-29-2016 04:26 PM

Held Items & Pet Companions
 
Hello everyone!


Figured I'd post this little mod here today that I recently completed.

Preview:

http://i.imgur.com/uBW8dhK.png

Again as with my other mod (Species Rarity w/ Images!), you'll want a public pet profile mod in place. See this post: Clicky
This mod can work elsewhere, like the creature's manage page and such. You'll just need to make your own edits for that!

Alrighty, so we'll be modifying a few files as well as adding new item functions in the database. First go to your class_privateitem.php file in your classes folder.

Go to around line 50 where you see a list of item functions, and under them add this:
PHP Code:

         case "Companion":
            
$message items_companion($this$owned_adoptable);
            break; 
         case 
"HeldItem":
            
$message items_helditem($this$owned_adoptable);
            break; 

Next, go to your database table adopts_items_functions. Look for the Level1 item function and click the "Copy" link. Change the Level1 text to Companion, and change the description to something else like "This item function gives a pet a companion!". Press "Go". Now do this same thing again except change Level1 to "HeldItem". Press Go.

After that go to your database table adopts_owned_adoptables. We'll be adding two new columns called "companion" and "item". VARCHAR 60, latin1_swedish_ci. For default, put "noitem" for the item column, and "nocompanion" for the companion column. Press Go to save. You're done in the database now.

Now go to your functions folder, and to the functions_items.php file. Add this code to the file, preferably at the bottom, to get your new companion and held item functions added.
PHP Code:

function items_companion($item$adopt){ 
  
$mysidia Registry::get("mysidia"); 
   
  if (
$adopt->companion != "nocompanion") {   
    
$itemgive = new StockItem($adopt->companion);   
    
$itemgive->append(1$mysidia->user->username);   
    }  
     
  
$companion $item->itemname
  
$mysidia->db->update("owned_adoptables", array("companion" => $companion), "aid ='{$adopt->aid}' and owner='{$item->owner}'"); 
  
$note "You have given your pet a <b>{$item->itemname}</b>! It will now show up in your pet's profile. <br /><br /> <a href='http://mysgardia.com/inventory'><button type='button'>Return to Inventory</button></a><br>"
  
//Update item quantity... 
  
$delitem $item->remove();  
  return 
$note
}  

function 
items_helditem($item$adopt){
  
$mysidia Registry::get("mysidia");
  
  if (
$adopt->item != "noitem") {  
    
$itemgive = new StockItem($adopt->item);  
    
$itemgive->append(1$mysidia->user->username);  
    } 
    
  
$helditem $item->itemname;
  
$mysidia->db->update("owned_adoptables", array("item" => $helditem), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
  
$note "You have given your pet a <b>{$item->itemname}</b>! It will now show up in your pet's profile. <br /><br /> <a href='http://mysgardia.com/inventory'><button type='button'>Return to Inventory</button></a><br>";
  
//Update item quantity...
  
$delitem $item->remove(); 
  return 
$note;



Now in your picuploads folder, you'll need to create a new folder called "items" (for the sake of organization). In this folder you will need to upload the companion and held item images each time you create them. So if you create an item called Rubber Ball, go to this folder and upload the image as "Rubber Ball.png". It MUST have the same exact name as the existing item, along with .png as the extension.

ALMOST finished! Go to your classes folder again, and in class_ownedadoptable.php at the bottom, add this code:
PHP Code:

 public function getCompanion(){
        return 
$this->companion;
        }
        
        public function 
getItem(){
        return 
$this->item;
        } 

Also add these to the top of the file:
PHP Code:

public $companion;
    public 
$item


Finally, wherever you want to display the item and companions for your pets, go there and add this bit of code:

PHP Code:


            
<img src='/picuploads/items/{$this->adopt->getCompanion()}.png' title='Oh look! A {$this->adopt->getCompanion()} is following this creature.'/>
            
            
            <
img src='/picuploads/items/{$this->adopt->getItem()}.png' title='Oh look! This creature is holding a {$this->adopt->getItem()}'/> 

EDIT: Oops! Forgot an important part! Remember when we defined the default values in the database columns as "noitem" and "nocompanion"? In your picuploads/items folder, upload two images named "noitem.png" and "nocompanion.png". These two images will display whenever a pet doesn't have an item/companion. So for example, you might want to upload the image of a red X or question mark or something!

EDIT2: If you want two item functions that completely remove companions and held items from pets and put them back into the player's inventory, see this post: Removal Functions

Phew, all done! Hope you guys enjoy!

Kyttias 03-29-2016 04:46 PM

PHP Code:

if ($adopt->getCompanion() != "nocompanion") { 
    
$item = new StockItem($adopt->getCompanion()); 
    
$item->append(1$mysidia->user->username); 


How's that?

Personally, rather than creating getWhatever() functions I'd rather just set the values to public variables at the top of the owned adoptables class file, and then just use $adopt->companion instead of $adopt->getCompanion() but that's just my preference. That way I don't have to write a function and it looks less clunky.

tahbikat 03-29-2016 05:21 PM

I've tried that but it gives me this every time:
HTML Code:

Fatal error: Call to undefined method stdClass::getCompanion() in /home/mysgardia/public_html/functions/functions_items.php on line 194
If I substitute the getCompanion for adopt->companion instead, it gives me the companion the adoptable already has, but doesn't update the companion column or delete the used item. So I started with 0 Magic Wisps and 1 Fire Wisp. Now I have 3 Magic Wisps and 1 Fire Wisp. It also throws up this error:

HTML Code:

Fatal error: Call to undefined method StockItem::remove() in /home/mysgardia/public_html/functions/functions_items.php on line 202
And thanks! I didn't know I could just use adopt->companion. :x <3

Kyttias 03-29-2016 06:05 PM

Don't you already update the companion and delete the item in your existing functions???? The error has nothing to do with my code. I'm starting to think you removed your function and replaced with just my if statement -- all my code does is transform an old companion, if such a thing exists, into an item again.
PHP Code:

function items_companion($item$adopt){
  
$mysidia Registry::get("mysidia");

//MY CODE
if ($adopt->getCompanion() != "nocompanion") { 
    
$item = new StockItem($adopt->getCompanion()); 
    
$item->append(1$mysidia->user->username); 
}

//WITH YOURS
  
$companion $item->itemname;
  
$mysidia->db->update("owned_adoptables", array("companion" => $companion), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
  
$note "You have given your pet a <b>{$item->itemname}</b>! It will now show up in your pet's profile. ";
  
//Update item quantity...
  
$delitem $item->remove(); 
  return 
$note;


Try that?

tahbikat 03-29-2016 07:29 PM

Ahhh noo that's exactly what I did. Simply added your code to my code right where you've put it and I get those errors. I've tried doing this before but written a little differently and I always get the weird stdClass error line.

Kyttias 03-29-2016 08:01 PM

Mnn... it might be because the $adopt is a direct reference to the database but not to the class file. getCompanion() is in two places - try it like this, maybe?
PHP Code:

function items_companion($item$adopt){ 
  
$mysidia Registry::get("mysidia"); 

//MY CODE 
if ($adopt->companion != "nocompanion") {  
    
$item = new StockItem($adopt->companion);  
    
$item->append(1$mysidia->user->username);  


//WITH YOURS 
  
$companion $item->itemname
  
$mysidia->db->update("owned_adoptables", array("companion" => $companion), "aid ='{$adopt->aid}' and owner='{$item->owner}'"); 
  
$note "You have given your pet a <b>{$item->itemname}</b>! It will now show up in your pet's profile. "
  
//Update item quantity... 
  
$delitem $item->remove();  
  return 
$note



tahbikat 03-29-2016 11:24 PM

See post #3, lol.. :x

When I use $adopt->companion, it gives a different error, doesn't remove the used item, doesn't update the database column with the new item, but it does give back the item currently in the companion column.

tahbikat 04-13-2016 03:53 PM

OK WOW I figured out what the issue is after taking a break and coming back to this. I'm so dumb lol

Here's the modified code:

PHP Code:

function items_companion($item$adopt){
  
$mysidia Registry::get("mysidia");
  
  if (
$adopt->companion != "nocompanion") {  
    
$itemgive = new StockItem($adopt->companion);  
    
$itemgive->append(1$mysidia->user->username);  
    } 
    
  
$companion $item->itemname;
  
$mysidia->db->update("owned_adoptables", array("companion" => $companion), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
  
$note "You have given your pet a <b>{$item->itemname}</b>! It will now show up in your pet's profile. <br /><br /> <a href='http://mysgardia.com/inventory'><button type='button'>Return to Inventory</button></a><br>";
  
//Update item quantity...
  
$delitem $item->remove(); 
  return 
$note;


Just had to change $item to $itemgive, because doi, it was conflicting with the already set $item variable.

I also made two new item functions that remove the companion/held item and replaces it with the default text. So if a user just wants to remove the item without giving a new one they can do so. Will get first post edited soon.

Abronsyth 04-14-2016 12:17 PM

Awwww yeeeesss! Thank you for sharing this!

tahbikat 04-14-2016 05:21 PM

Okidokes, here's the two other item functions to remove companions and items without giving new ones. I named the functions "unbindingcompanion"/"unbindingitem", so if you want to name it something else just change that and be sure to match up everything else.

Add in functions_items.php:
PHP Code:

function items_unbindingcompanion($item$adopt){
  
$mysidia Registry::get("mysidia");
  
  if (
$adopt->companion != "nocompanion") {  
    
$itemgive = new StockItem($adopt->companion);  
    
$itemgive->append(1$mysidia->user->username);  
    } 

  
$mysidia->db->update("owned_adoptables", array("companion" => 'nocompanion'), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
  
$note "You use the <b>{$item->itemname}</b> on your pet, breaking the bond between it and its companion. The companion has been returned to your inventory!<br /><br /> <a href='/inventory'><button type='button'>Return to Inventory</button></a><br>";
  
//Update item quantity...
  
$delitem $item->remove(); 
  return 
$note;



function 
items_unbindingitem($item$adopt){
  
$mysidia Registry::get("mysidia");
  
  if (
$adopt->item != "noitem") {  
    
$itemgive = new StockItem($adopt->item);  
    
$itemgive->append(1$mysidia->user->username);  
    } 

  
$mysidia->db->update("owned_adoptables", array("item" => 'noitem'), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
  
$note "You use the <b>{$item->itemname}</b> on your pet, breaking the bond between it and its held item. The held item has been returned to your inventory!<br /><br /> <a href='/inventory'><button type='button'>Return to Inventory</button></a><br>";
  
//Update item quantity...
  
$delitem $item->remove(); 
  return 
$note;


Add in class_privateitem.php:
PHP Code:

         case "UnbindingCompanion":
            
$message items_unbindingcompanion($this$owned_adoptable);
            break; 
         case 
"UnbindingItem":
            
$message items_unbindingitem($this$owned_adoptable);
            break; 

Then add the new functions to your database prefix_items_functions like you did for the companion and held item functions. That's it! Then just create the items and select the new functions.


All times are GMT -5. The time now is 09:48 AM.

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