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
  #21  
Old 12-24-2016, 08:58 AM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 133,165
Abronsyth is on a distinguished road
Default

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

?>
__________________
My Mods Site (1.3.4, 2020 Mods)
Reply With Quote
  #22  
Old 12-24-2016, 10:33 AM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 342
Gender: Female
Credits: 22,566
parayna is on a distinguished road
Default

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

  Spoiler: Image 


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!
Reply With Quote
  #23  
Old 12-30-2016, 03:18 AM
Silver_Brick Silver_Brick is offline
Designer || Coder
 
Join Date: Oct 2016
Location: In Earth
Posts: 205
Gender: Male
Credits: 31,261
Silver_Brick is on a distinguished road
Default

i also can't use held item or companion and i did all thing correct
Reply With Quote
  #24  
Old 12-30-2016, 01:02 PM
Pear's Avatar
Pear Pear is offline
Woah man.
 
Join Date: Dec 2013
Location: The Underworld
Posts: 169
Gender: Female
Credits: 48,206
Pear is on a distinguished road
Default

Quote:
Originally Posted by Silver_Brick View Post
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:
__________________
Noot noot! Gotta get a new signooture. >->
Reply With Quote
  #25  
Old 12-30-2016, 01:59 PM
tahbikat's Avatar
tahbikat tahbikat is offline
Member
 
Join Date: Feb 2014
Location: Louisiana
Posts: 408
Gender: Female
Credits: 57,668
tahbikat is on a distinguished road
Default

@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.
Reply With Quote
  #26  
Old 01-01-2017, 01:37 PM
Silver_Brick Silver_Brick is offline
Designer || Coder
 
Join Date: Oct 2016
Location: In Earth
Posts: 205
Gender: Male
Credits: 31,261
Silver_Brick is on a distinguished road
Default

Three times i checked and with fresh install also it say undefined function helditem in private
Reply With Quote
  #27  
Old 01-06-2017, 10:40 PM
Ittermat's Avatar
Ittermat Ittermat is offline
The awesomesauce
 
Join Date: Feb 2016
Location: in front of my laptop
Posts: 272
Gender: Female
Credits: 38,513
Ittermat is on a distinguished road
Default

I did recheck and redo and everything- I still cant figure it out... x.x
Reply With Quote
  #28  
Old 01-31-2017, 08:49 PM
Ittermat's Avatar
Ittermat Ittermat is offline
The awesomesauce
 
Join Date: Feb 2016
Location: in front of my laptop
Posts: 272
Gender: Female
Credits: 38,513
Ittermat is on a distinguished road
Default

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


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 05:11 PM.

Currently Active Users: 681 (0 members and 681 guests)
Threads: 4,081, Posts: 32,031, 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