Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Tutorials and Tips

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 03-29-2016, 04:26 PM
tahbikat's Avatar
tahbikat tahbikat is offline
Member
 
Join Date: Feb 2014
Location: Louisiana
Posts: 408
Gender: Female
Credits: 48,950
tahbikat is on a distinguished road
Lightbulb Held Items & Pet Companions

Hello everyone!


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

Preview:



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!

Last edited by tahbikat; 04-14-2016 at 05:23 PM.
Reply With Quote
  #2  
Old 03-29-2016, 04:46 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 87,057
Kyttias is on a distinguished road
Default

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.
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 03-29-2016 at 04:49 PM.
Reply With Quote
  #3  
Old 03-29-2016, 05:21 PM
tahbikat's Avatar
tahbikat tahbikat is offline
Member
 
Join Date: Feb 2014
Location: Louisiana
Posts: 408
Gender: Female
Credits: 48,950
tahbikat is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 03-29-2016, 06:05 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 87,057
Kyttias is on a distinguished road
Default

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?
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 03-29-2016 at 06:10 PM.
Reply With Quote
  #5  
Old 03-29-2016, 07:29 PM
tahbikat's Avatar
tahbikat tahbikat is offline
Member
 
Join Date: Feb 2014
Location: Louisiana
Posts: 408
Gender: Female
Credits: 48,950
tahbikat is on a distinguished road
Default

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.
Reply With Quote
  #6  
Old 03-29-2016, 08:01 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 87,057
Kyttias is on a distinguished road
Default

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

__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.
Reply With Quote
  #7  
Old 03-29-2016, 11:24 PM
tahbikat's Avatar
tahbikat tahbikat is offline
Member
 
Join Date: Feb 2014
Location: Louisiana
Posts: 408
Gender: Female
Credits: 48,950
tahbikat is on a distinguished road
Default

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.
Reply With Quote
  #8  
Old 04-13-2016, 03:53 PM
tahbikat's Avatar
tahbikat tahbikat is offline
Member
 
Join Date: Feb 2014
Location: Louisiana
Posts: 408
Gender: Female
Credits: 48,950
tahbikat is on a distinguished road
Default

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.
Reply With Quote
  #9  
Old 04-14-2016, 12:17 PM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 111,779
Abronsyth is on a distinguished road
Default

Awwww yeeeesss! Thank you for sharing this!
__________________
My Mods Site (1.3.4, 2020 Mods)
Reply With Quote
  #10  
Old 04-14-2016, 05:21 PM
tahbikat's Avatar
tahbikat tahbikat is offline
Member
 
Join Date: Feb 2014
Location: Louisiana
Posts: 408
Gender: Female
Credits: 48,950
tahbikat is on a distinguished road
Default

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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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

Currently Active Users: 666 (0 members and 666 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636