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.

lotus 10-17-2016 06:49 AM

Actually, this can be used for backgrounds and foregrounds/decors for pets using a background and foreground layer using div.

Dinocanid 10-17-2016 06:03 PM

Can someone explain to me a bit more of how I use this? I followed the tutorial, but I'm confused about what you put in the item image field in the adminCP when making the item, and once I get the item in my inventory I can't use it, it just says N/A. Also, where would I put the "img src" codes? In class_ownedadoptable?

Ittermat 12-14-2016 12:42 PM

Hi there Im trying to get them to appear below something but it keeps giving me an error-

This is my petview.php
but Im trying to get it to appear below the pet- and right above the play, manage, freeze, etc links.

PHP Code:

 <?php 
class PetView extends View

    public function 
profile(){ 
        
$mysidia Registry::get('mysidia'); 
        
$d $this->document
        
$adopt $this->getField('adopt'); 
        
$isdead $adopt->isdead
        
$name $adopt->getName(); 
        
$title 'Viewing '
        if (
$isdead) { 
            
$title '<img src="/picuploads/dead.png"> Here Lies '
            
$name .= ' <img src="/picuploads/dead.png">'
        } 
        else{ 
            if (
$adopt->getOwner() == 'SYSTEM') { 
                
$title '<img src="/picuploads/shackle.png"> ' $title
                
$name .= '<img src="/picuploads/shackle.png">'
            } 
        } 
        if (
$adopt->getOwner() == $mysidia->user->username$title 'Managing '
        
$d->setTitle(' '); 
        
$d->addLangVar('<table border=1px><tr><td valign="top">'); 
        
$d->addLangvar("<b>{$title}{$name}</b><hr>"); 
        if (
$isdead == false) { 
            if (
$adopt->getOwner() == 'SYSTEM') { 
                
$d->addLangVar("Owned by <a href='/profile/view/POUND'>The Pound</a><br><br>"); 
            }else{ 
                
$d->addLangVar("Owned by <a href='/profile/view/{$adopt->getOwner()}'>{$adopt->getOwner()}</a><br><br>"); 
            } 
        } 
        if (
$isdead) { 
            
$d->addLangvar("<div style='background:url({$mysidia->path->getAbsolute()}picuploads/paw.png); position:relative; height:248px; width:268px;'><div style='background:url({$mysidia->path->getAbsolute()}picuploads/wreath.png);height:248px; width:268px;position:absolute;z-index:30;'></div><div style='position:absolute;z-index:2;left:50px;bottom:10px'>".$adopt->getImage("gui") .'</div></div>'); 
        }else{ 
            if (
$adopt->class == 'Colorful'){ 
            
$d->addLangvar($adopt->getImage('gui')); 
            }else{ 
                
$d->add($adopt->getImage('gui')); 
                     
            } 
        } 
     
        if (
$isdead){ 
            
$d->addLangvar('</div>'); 
        } 
         
        if (
$adopt->isdead == false){ 
            if(
$adopt->isfrozen() == 'no'){ 
                
$d->addLangvar("<br><a href='/levelup/click/{$adopt->aid}'>Play</a>"); 
            }else{ 
                
$d->addLangvar('<br>Frozen'); 
            } 
        } 
         
        
$freeze 'Freeze'
        if (
$adopt->isFrozen() == 'yes'$freeze 'Unfreeze'
        if (
$mysidia->user->username == $adopt->getOwner()){ 
         
            
$d->addLangVar(" | <a href='/myadopts/manage/{$adopt->aid}'>Manage</a> | <a href='/myadopts/bbcode/{$adopt->aid}'>Codes</a> | <a href='/myadopts/freeze/{$adopt->aid}'>$freeze</a><br><a href='/pound/pound/{$adopt->aid}'>Pound $name</a><br> <a href='/pet/release/{$adopt->aid}'>Release $name</a>"); 
        } 
        
$d->addLangVar('</td><td valign="top">'); 

        
$d->add(new Comment('<div id="tabs" class="c-tabs no-js"><div class="c-tabs-nav">',false)); 

        if (
$adopt->class != 'Colorful') { 
            
$d->addLangVar("<a href='#' class='c-tabs-nav__link'>Bio</a><a href='#' class='c-tabs-nav__link'>About</a>"); 
            
$d->addLangVar("</div><div class='c-tab is-active'><div class='c-tab__content'>{$adopt->getBio()}</div></div><div class='c-tab'> 
                <div class='c-tab__content'>
{$adopt->getDescription()}</div></div>"); 
             
        }else{ 
            
$d->addLangVar("<a href='#' class='c-tabs-nav__link'>Bio</a><a href='#' class='c-tabs-nav__link'>Skills</a><a href='#' class='c-tabs-nav__link'>Lineage</a><a href='#' class='c-tabs-nav__link'>Offspring</a><a href='#' class='c-tabs-nav__link'>Stats</a>"); 
            
$d->addLangVar("</div><div class='c-tab is-active'> 
                <div class='c-tab__content'>"
); 
            if (
$mysidia->user->username == $adopt->getOwner()){ 
                
$d->addLangvar('<a href="/myadopts/updatebio/'.$adopt->aid.'">Click Here to Update Bio</a><br><br>'); 
            } 
            
$d->addLangvar("{$adopt->getBio()}</div></div> 
                <div class='c-tab'><div class='c-tab__content'><b>Trophies:</b> 
{$adopt->trophies}<br><br>
                    <b>Sense:</b> 
{$adopt->sense}<br> 
                    <b>Speed:</b> 
{$adopt->speed}<br> 
                    <b>Strength:</b> 
{$adopt->strength}<br> 
                    <b>Stamina:</b> 
{$adopt->stamina}<br></div></div>"); 

            
// Lineage 
            
include('pedigree.php'); 

            
$offspring = []; $parent 'sire_id'
            if (
$adopt->getGender() == 'f'$parent 'dam_id'
            
$offspring $mysidia->db->select('owned_adoptables', [], "$parent = {$adopt->aid}")->fetchAll(PDO::FETCH_CLASS,'OwnedAdoptable'); 

            
$d->addLangVar("<div class='c-tab'><div class='c-tab__content'><b>Offspring</b>"); 
            if (
count($offspring) == 0$d->addLangVar('<hr>None.'); 
            foreach (
$offspring as $baby) { 
                
$d->addLangVar("<hr><a href='/pet/profile/{$baby->aid}'>{$baby->name}<br><img src='{$baby->getImage()}'></a>"); 
            } 
             
            
$d->addLangVar('</div></div>'); 

            
$d->addLangVar("<div class='c-tab'><div class='c-tab__content'>"); 
            
$d->addLangvar("<b>Personality:</b> {$adopt->personality()}<br> 
                <b>Happiness:</b> 
{$adopt->happiness}/50<br> 
                <b>Hunger:</b> 
{$adopt->hunger}/50<br> 
                <b>Thirst:</b> 
{$adopt->thirst}/50<br> 
                <b>Closeness:</b> 
{$adopt->closeness}/50<br> 
                "
); 
                 
            
$d->add($adopt->getStats()); 
            if (
$adopt->breeder != null) { 
                
$d->addLangvar("<br><br><b>Breeder:</b> <a href='/profile/view/{$adopt->breeder}'>{$adopt->breeder}</a>"); 
                 
            } 
             

            
$d->addLangvar("</div></div>"); 
        } 
        
$d->addLangVar('</td></tr></table>'); 

        
$d->add(new Comment
            
"<script src='/js/otherTabs.js'></script> 
            <script> 
                var myTabs = tabs({ 
                    el: '#tabs', 
                    tabNavigationLinks: '.c-tabs-nav__link', 
                    tabContentContainers: '.c-tab' 
                }); 

                myTabs.init(); 
            </script>"
FALSE)); 
    } 

    public function 
release(){ 
        
$d $this->document
        
$adopt $this->getField('adopt'); 
        
$d->setTitle($this->lang->release); 
        
$d->addLangvar($adopt->getName().'<br>'.$adopt->getImage('gui').'<br><br>'); 
        
$d->addLangvar($this->lang->release_warning); 
        
$d->addLangvar('<br><br><form method="post" action="/myadopts/release/'.$adopt->aid.'"><label for="password">Type your password below to confirm:</label><br><input type="password" name="password"><br><input type="submit" value="Release Pet?"></form>'); 
    } 

    public function 
bio(){ 
     
        
$d $this->document
        
$adopt $this->getField('adopt'); 
         
        
$d->setTitle('Update Bio'); 
        
$d->addLangvar($adopt->getName().'<br>'.$adopt->getImage('gui').'<br><br>'); 
        
$d->addLangvar('<form method="post"><textarea name="bio">'.$adopt->bio.'</textarea><br><input type="submit" value="Update Bio" name="submit"></form>'); 
           
    } 
     

}

Thanks in advance ^^;

Edit: Another question- how exactly do you set the companions and items to a pet?

EDIT 2-:

After installing this I also seem to be having a problem with "key" items working..
It gives me this error: Fatal error: Call to undefined function items_key() in /home/atrocity/public_html/classes/class_privateitem.php on line 109

Heres my items functions.php

PHP Code:

<?php

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

function items_valuable($item$adopt){
  if (
check_stats() == true){
    
$note "{$item->itemname} has been used on {$adopt->name}.";
    
$item->remove(); 
    return 
$note;
  }
  return 
"The item {$item->itemname} is a valuable item, which cannot be used on any adoptable but may sell for a good deal of money.";
}
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_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 != 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 != 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_recipe($item$adopt){
  if (
check_stats($item) == false){
    return 
"The item {$item->itemname} is a recipe item, which is only useful if you are preforming alchemy.";
  }
  
$note "The item {$item->itemname} is a recipe item, which is more useful if you are performing alchemy. However your {$adopt->name} has greedily used it up anyway!";
  
$item->remove();
  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;
}

/* Increase players pet storage size */
function items_space($item) {
  
$mysidia Registry::get("mysidia");
  
$max $mysidia->user->getStatus()->max_pets;
  
$limit $mysidia->getSettings()->maximumpets;
  if (
$max >= $limit) return $mysidia->lang->global_sitewide_maximum_pets_reached;
  
$newMax $max+$item->value;
  if (
$newMax $limit) return "Sorry but you can't use {$item}, it'd increase your size beyond the site pet limits.";

  
$mysidia->db->update('users_status', ['max_pets'=>$newMax], "username='{$mysidia->user->username}'");
  
$delitem $item->remove();
  return 
$mysidia->lang->global_size_increase_item_used;
}

function 
items_key($item) {
  if (
check_stats($item) == false) {
    return 
"This {$item->itemname} can not be used on your pet.";
  }
  
$item->remove(); 
  return 
$item->itemname ' has been used.';
}


function 
check_stats($item) {
  
$stats = ['hunger''thirst''closeness''happiness'];
  foreach (
$stats as $s) {
    if (
$item->$s != 0) {
      return 
TRUE;
    }
  }
  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;
}  
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;
}  
  return 
FALSE;
}
}
?>

Im really sorry that I suck at this so much x.x Im trying honest.

EDIT: I was trying to make it so that there was a seperate button for "Giving items to pets" For the Held items and pet companions because I have some items that can actually be used that I'd like them o be able to hold without using them for the stats.... This is what I tried to Do in my Inventoryview.php... in the Use area..

PHP Code:

   # Rendering items now
            
$document->add(new Comment("
                <div class=\"s_panel sc_item\">
                    <img rel=\"tooltip\" title=\"
{$item->description} <em>{$usage}</em>\" src=\"{$item->imageurl}\"/><br/>
                    <b>
{$item->itemname}</b><br> Own &times;{$item->quantity}<br/>"FALSE));

            
# If item is consumable, add use button
            
if ($item->consumable == "yes") {
                
$useForm = new FormBuilder("useform""inventory/uses""post");
                
$useForm->setLineBreak(FALSE);
                
$useForm->buildPasswordField("hidden""action""uses")
                    ->
buildPasswordField("hidden""itemname"$item->itemname)
                    ->
buildButton("Use""use""use");
                
$document->add($useForm);
            }
             if (
$item->helditem == "yes") {
                
$useForm = new FormBuilder("useform""inventory/uses""post");
                
$useForm->setLineBreak(FALSE);
                
$useForm->buildPasswordField("hidden""action""uses")
                    ->
buildPasswordField("hidden""itemname"$item->itemname)
                    ->
buildButton("Give to Pet""Give to Pet""Give to Pet");
                
$document->add($useForm);
            }
       if (
$item->companion == "yes") {
                
$useForm = new FormBuilder("useform""inventory/uses""post");
                
$useForm->setLineBreak(FALSE);
                
$useForm->buildPasswordField("hidden""action""uses")
                    ->
buildPasswordField("hidden""itemname"$item->itemname)
                    ->
buildButton("Give to Pet""Give to Pet""Give to Pet");
                
$document->add($useForm);
            } 

Im really trying to figure this out.. x.x

parayna 12-20-2016 01:00 PM

I seem to be having a little issue with it. If I add the companions through the PHP myadmin bit it works perfectly, but when trying to do it through the inventory and use the item it gives me a blank page. Is there something I need to add to an inventory page, or is it something else that's wrong? (Other items still work, so I know it's only with these functions :usedusedused:)

tahbikat 12-21-2016 10:53 AM

Sorry guys, I would try to help with this but I don't have access to the mysidia script at the moment. Hopefully someone else can help.

parayna 12-23-2016 11:31 AM

I'm not sure if anyone will be around to help (and it's fine if not) but just in case others are getting the same error it is basically telling me that the function items_companion() is undefined and so won't let me use the item. I've put all the files onto my remote server so I can see the errors, as my online one has them turned off xD

Abronsyth 12-23-2016 12:59 PM

Did you make sure to include the function in functions/functions_items.php ?

parayna 12-23-2016 01:16 PM

Yeah, the error is actually for class_privateitem (forgot to say lol) and I've checked both that one and functions_items o.O

Abronsyth 12-23-2016 02:01 PM

Can you post your class_privateitem file?

parayna 12-23-2016 03:03 PM

Sure!

  Spoiler: Code 
PHP 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 
"Companion":
            
$message items_companion($this$owned_adoptable);
            break; 
        case 
"HeldItem":
            
$message items_helditem($this$owned_adoptable);
            break;  
         default:
            throw new 
ItemException("The item function is invalid");         
        case 
"UnbindingCompanion":
            
$message items_unbindingcompanion($this$owned_adoptable);
            break; 
         case 
"UnbindingItem":
            
$message items_unbindingitem($this$owned_adoptable);
            break;  
      }
      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;      
  }
}
?>



Thanks ^_^

Abronsyth 12-24-2016 07:58 AM

Try this:
PHP 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 
"Companion"
            
$message items_companion($this$owned_adoptable); 
            break;  
        case 
"HeldItem"
            
$message items_helditem($this$owned_adoptable); 
            break;   
        case 
"UnbindingCompanion"
            
$message items_unbindingcompanion($this$owned_adoptable); 
            break;  
         case 
"UnbindingItem"
            
$message items_unbindingitem($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;       
  } 

?>


parayna 12-24-2016 09:33 AM

That still didn't work :/ This is the exact message if anyone can see what the issue is...



My class_privateitem is the updated code, and if you needed it, here's the funtions_items one..

PHP 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 != 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 != 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_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;
}

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_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;
}  

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

  
$mysidia->db->update("owned_adoptables", array("companion" => 'No Companion'), "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 != "No Item") {  
    
$itemgive = new StockItem($adopt->item);  
    
$itemgive->append(1$mysidia->user->username);  
    } 

  
$mysidia->db->update("owned_adoptables", array("item" => 'No Item'), "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;
}  
}
?>

I did just redo every step to see if I had followed them wrong but it still came out the same. Thanks for helping!

Silver_Brick 12-30-2016 02:18 AM

i also can't use held item or companion and i did all thing correct

Pear 12-30-2016 12:02 PM

Quote:

Originally Posted by Silver_Brick (Post 35533)
i also can't use held item or companion and i did all thing correct

If it's not working, there's a high chance somewhere was done wrong. I'd go over everything and make sure you have all the coding in the right places if I were you. C:

tahbikat 12-30-2016 12:59 PM

@parayna, @Ittermat, @dinocanid,

I also would suspect if the code isn't working or you're getting errors, perhaps it is conflicting with other mods you've added. Again I'd try to help but I would need the code in front of me. I haven't looked at the mysidia script in ages. :x

I would say go over each step again and make sure you've done everything right. Also make sure your item images all end in the same format and the format is correct with the img src code. So they should all be .png or .gif or whatever you're using. I remember I had issues with that.

Silver_Brick 01-01-2017 12:37 PM

Three times i checked and with fresh install also it say undefined function helditem in private

Ittermat 01-06-2017 09:40 PM

I did recheck and redo and everything- I still cant figure it out... x.x

Ittermat 01-31-2017 07:49 PM

Sorry for double posting- but I still need help with this... x.x


All times are GMT -5. The time now is 03:31 PM.

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