View Full Version : Mys 1.3.4 Item Function: Gender Change Potion
Kyttias
12-09-2014, 11:37 PM
Item Function: Gender Change Potion for Mysidia 1.3.4
*may work for earlier versions, definitely adaptable, but the db update query bit may need some changing - if it looks like other queries in your version, then this works out fine for you!
**and I didn't immediately see this thread (http://www.mysidiaadoptables.com/forum/showthread.php?t=4209), so while this is technically a duplicate, Wallie's was in the Questions and Supports board, and it's good to have this as a mod clearly visible in the mods board
1 - First we will add our function to the database. Open up your database. In the items_functions table, make note of how many rows there are (check out the ifid column for help), hit the word Copy on the row holding the Level1 function. Fill in the first blank with the next number. If you had 13 item functions, this will be 14. The description seen here is mostly for your sake on the admin side of things.
http://fc03.deviantart.net/fs70/f/2014/343/a/1/help_by_kyttias-d89b9ub.gif
2 - Next we'll add the function into functions/functions_items.php.
This code updated Feb 9, 2015. If you added it prior to this, please update it!
function items_gender($item, $adopt){
$mysidia = Registry::get("mysidia");
$delitem = $item->remove();
$gender = $adopt->gender;
switch($gender){
case "m":
$newgender = "f";
$newgender_full = "girl";
break;
default:
$newgender = "m";
$newgender_full = "boy";
}
$mysidia->db->update("owned_adoptables", array("gender" => $newgender), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note = "Success! The <b>{$item->itemname}</b> has worked its magic. {$adopt->name} is now a {$newgender_full}.";
return $note;
}
**Use this version if you're using the Alternate Gender Images mod (http://www.mysidiaadoptables.com/forum/showpost.php?p=31618&postcount=26):
function items_gender($item, $adopt){
$mysidia = Registry::get("mysidia");
$delitem = $item->remove();
$gender = $mysidia -> db -> select ("owned_adoptables", array("gender"), "aid='{$adopt->aid}' and owner ='{$item->owner}'") -> fetchColumn();
switch($gender){
case "m":
$alts = "no";
$newgender = "f";
$newgender_full = "girl";
break;
default:
$alts = "yes";
$newgender = "m";
$newgender_full = "boy";
}
$mysidia->db->update("owned_adoptables", array("gender" => $newgender, "usealternates" => $alts), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note = "Success! The <b>{$item->itemname}</b> has worked its magic. {$adopt->name} is now a {$newgender_full}.";
return $note;
}
3 - With both these steps complete, you can now Create an Item from the Items section in your AdminCP, as the new function will show on the list of item functions. Don't have an image prepared for your item? You may temporarily make use this image for testing purposes:
http://th05.deviantart.net/fs71/150/f/2014/343/3/f/item_genderpotion_by_kyttias-d89bc0f.png?1
4 - Before you can use an item, you will need to make one last change inside classes/class_privateitem.php. Inside public function apply is a switch statement containing the list of item functions. Add your new item to this list.
case "Gender":
$message = items_gender($this, $owned_adoptable);
break;
parayna
12-11-2014, 07:31 AM
I really like this idea :3 Thank you for sharing this!
Abronsyth
11-21-2015, 03:30 PM
I'm sure I've done something wrong, but I'm getting this error when I try to use the item:
Fatal error: Call to undefined method stdClass::getGender() in /home/catisserie/public_html/functions/functions_items.php on line 180
Here's my functions_items.php:
<?php
// File ID: functions_items.php
// Purpose: Provides specific functions defined for items
function items_valuable($item, $adopt){
$note = "The item {$item->itemname} is a valuable item, which cannot be used on any adoptable but may sell a good deal of money.";
return $note;
}
function items_level1($item, $adopt){
$mysidia = Registry::get("mysidia");
$newlevel = $adopt->currentlevel + $item->value;
$lev = $mysidia->db->select("levels", array(), "adoptiename='{$adopt->type}' and thisislevel ='{$newlevel}'")->fetchObject();
//Check if the adoptable's level is already at maximum.
if(!is_object($lev)){
// object not created, the level is already at maximum.
$note = "Unfortunately, your selected adoptable's level cannot be raised by using item {$item->itemname}.";
}
else{
//Update item quantity...
$delitem = $item->remove();
//Execute the script to update adoptable's level and clicks.
$mysidia->db->update("owned_adoptables", array("currentlevel" => $newlevel, "totalclicks" => $lev->requiredclicks), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note = "Congratulations, the item {$item->itemname} raised your adoptable's level by {$item->value}";
}
return $note;
}
function items_level2($item, $adopt){
$mysidia = Registry::get("mysidia");
$newlevel = $item->value;
$lev = $mysidia->db->select("levels", array(), "adoptiename='{$adopt->type}' and thisislevel ='{$newlevel}'")->fetchObject();
//Check if the adoptable's level is already at maximum.
if(!is_object($lev)){
// object not created, the level is already at maximum.
$note = "Unfortunately, your selected adoptable's level cannot be raised by using item {$item->itemname}.";
}
else{
//Update item quantity...
$delitem = $item->remove();
//Execute the script to update adoptable's level and clicks.
$mysidia->db->update("owned_adoptables", array("currentlevel" => $newlevel, "totalclicks" => $lev->requiredclicks), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note = "Congratulations, the item {$item->itemname} increases your adoptable's level to {$item->value}";
}
return $note;
}
function items_level3($item, $adopt){
$mysidia = Registry::get("mysidia");
//Update item quantity...
$delitem = $item->remove();
//Execute the script to update adoptable's level and clicks.
$mysidia->db->update("owned_adoptables", array("currentlevel" => 0, "totalclicks" => 0), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note = "Congratulations, the item {$item->itemname} has reset the level and clicks of your adoptable.";
return $note;
}
function items_click1($item, $adopt){
$mysidia = Registry::get("mysidia");
$newclicks = $adopt->totalclicks + $item->value;
$mysidia->db->update("owned_adoptables", array("totalclicks" => $newclicks), "aid='{$adopt->aid}'and owner='{$item->owner}'");
$note = "By using {$item->itemname}, the adoptable's total number of clicks has raised by {$item->value}<br>";
//Now lets check if the adoptable has reached a new level.
$ownedAdopt = new OwnedAdoptable($adopt->aid);
if($ownedAdopt->hasNextLevel()){
//new level exists, time to check if the total clicks have reached required minimum clicks for next level.
$nextLevel = $ownedAdopt->getNextLevel();
$requiredClicks = $nextLevel->getRequiredClicks();
if($newclicks >= $requiredClicks and $requiredClicks != 0 and $requiredClicks != ""){
// We need to level this adoptable up...
$mysidia->db->update("owned_adoptables", array("currentlevel" => $nextLevel->getLevel()), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note .= "And moreover, it has gained a new level!";
}
}
//Update item quantity...
$delitem = $item->remove();
return $note;
}
function items_click2($item, $adopt){
$mysidia = Registry::get("mysidia");
$newclicks = $item->value;
$mysidia->db->update("owned_adoptables", array("totalclicks" => $newclicks), "aid='{$adopt->aid}'and owner='{$item->owner}'");
$note = "By using {$item->itemname}, the adoptable's total number of clicks has raised by {$item->value}<br>";
//Now lets check if the adoptable has reached a new level.
$ownedAdopt = new OwnedAdoptable($adopt->aid);
if($ownedAdopt->hasNextLevel()){
//new level exists, time to check if the total clicks have reached required minimum clicks for next level.
$nextLevel = $ownedAdopt->getNextLevel();
$requiredClicks = $nextLevel->getRequiredClicks();
if($newclicks >= $requiredClicks and $requiredClicks != 0 and $requiredClicks != ""){
// We need to level this adoptable up...
$mysidia->db->update("owned_adoptables", array("currentlevel" => $nextlevel), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note .= "And moreover, it has gained a new level!";
}
}
//Update item quantity...
$delitem = $item->remove();
return $note;
}
function items_click3($item, $adopt){
$mysidia = Registry::get("mysidia");
$date = date('Y-m-d');
$mysidia->db->delete("vote_voters", "adoptableid = '{$adopt->aid}' and date='{$date}'");
//Update item quantity...
$delitem = $item->remove();
$note = "By using item {$item->name}, you have make your adoptables eligible for clicking by everyone again!";
return $note;
}
function items_breed1($item, $adopt){
$mysidia = Registry::get("mysidia");
// Update the lastbred info.
$mysidia->db->update("owned_adoptables", array("lastbred" => 0), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note = "The item has been successfully used on your adoptable, it can breed again!<br>";
//Update item quantity...
$delitem = $item->remove(1, $item->owner);
return $note;
}
function items_breed2($item, $adopt){
$mysidia = Registry::get("mysidia");
// Note this function exists but is not useful until Mys v1.3.2, when adoptables can carry/attach items.
$mysidia->db->update("owned_adoptables", array("lastbred" => 0), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note = "The item has been successfully used on your adoptable, it can breed again!<br>";
//Update item quantity...
$delitem = $item->remove();
return $note;
}
function items_alts1($item, $adopt){
$mysidia = Registry::get("mysidia");
// First lets check if alternative image exists for an adoptable at this level.
$lev = $mysidia->db->select("levels", array(), "adoptiename='{$adopt->type}' and thisislevel ='{$adopt->currentlevel}'")->fetchObject();
if($lev->alternateimage == ""){
// The alternate image does not exist, cannot convert adoptable into its alternate form
$note = "It appears that your adoptable does not have an alternate image at its given level...<br>";
}
else{
// The alternate image exists, conversion between primary and alternate image is possible.
switch($adopt->usealternates){
case "yes":
$mysidia->db->update("owned_adoptables", array("usealternates" => 'no'), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note = "Your adoptable has assume the species primary form.";
break;
default:
$mysidia->db->update("owned_adoptables", array("usealternates" => 'yes'), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note = "Your adoptable {$adopt->name} has assume the species alternate form.";
}
//Update item quantity...
$delitem = $item->remove();
}
return $note;
}
function items_alts2($item, $adopt){
$note = "This feature will be available soon after we redesign the adoptable class, enjoy!";
return $note;
}
function items_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_gender($item, $adopt){
$mysidia = Registry::get("mysidia");
$delitem = $item->remove();
$gender = $adopt->getGender();
switch($gender){
case "m":
$newgender = "f";
$newgender_full = "female";
break;
default:
$newgender = "m";
$newgender_full = "male";
}
$mysidia->db->update("owned_adoptables", array("gender" => $newgender), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note = "Success! The <b>{$item->itemname}</b> has worked its magic. {$adopt->name} is now a {$newgender_full}.";
return $note;
}
?>
Nieth
11-21-2015, 09:59 PM
It sounds like you didn't implement step 4 correctly.
Abronsyth
11-22-2015, 02:54 PM
I'm fairly sure I did? My class_privateitem.php file;
<?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 "Gender":
$message = items_gender($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;
}
}
?>
Nieth
11-22-2015, 05:51 PM
Have you had issues adopting adoptables? Its saying that the getGender function isn't being defined, but it should be in class_adoptable.php
Abronsyth
11-22-2015, 08:12 PM
Nope, I haven't had any issues. I've checked class_adoptable.php and gender is indeed defined in there.
Distortion
12-09-2015, 11:48 AM
This is late, but if you're still having trouble, you have to use the second code for the functions_items.php for it to work :)
NobodysHero
02-03-2016, 01:11 AM
My mistake for staying up way past my normal bed time. Heh. When I use the gender swap item, it gives me a blank page and the gender doesn't change. Now, I'm certain I did something wrong, but I have no idea what it is.
item_functions.php:
<?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_level4($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{
//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_click1($item, $adopt){
$mysidia = Registry::get("mysidia");
$newclicks = $adopt->totalclicks + $item->value;
$mysidia->db->update("owned_adoptables", array("totalclicks" => $newclicks), "aid='{$adopt->aid}'and owner='{$item->owner}'");
$note = "By using {$item->itemname}, the adoptable's total number of clicks has raised by {$item->value}<br>";
//Now lets check if the adoptable has reached a new level.
$ownedAdopt = new OwnedAdoptable($adopt->aid);
if($ownedAdopt->hasNextLevel()){
//new level exists, time to check if the total clicks have reached required minimum clicks for next level.
$nextLevel = $ownedAdopt->getNextLevel();
$requiredClicks = $nextLevel->getRequiredClicks();
if($newclicks >= $requiredClicks and $requiredClicks != 0 and $requiredClicks != ""){
// We need to level this adoptable up...
$mysidia->db->update("owned_adoptables", array("currentlevel" => $nextLevel->getLevel()), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note .= "And moreover, it has gained a new level!";
}
}
//Update item quantity...
$delitem = $item->remove();
return $note;
}
function items_click2($item, $adopt){
$mysidia = Registry::get("mysidia");
$newclicks = $item->value;
$mysidia->db->update("owned_adoptables", array("totalclicks" => $newclicks), "aid='{$adopt->aid}'and owner='{$item->owner}'");
$note = "By using {$item->itemname}, the adoptable's total number of clicks has raised by {$item->value}<br>";
//Now lets check if the adoptable has reached a new level.
$ownedAdopt = new OwnedAdoptable($adopt->aid);
if($ownedAdopt->hasNextLevel()){
//new level exists, time to check if the total clicks have reached required minimum clicks for next level.
$nextLevel = $ownedAdopt->getNextLevel();
$requiredClicks = $nextLevel->getRequiredClicks();
if($newclicks >= $requiredClicks and $requiredClicks != 0 and $requiredClicks != ""){
// We need to level this adoptable up...
$mysidia->db->update("owned_adoptables", array("currentlevel" => $nextlevel), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note .= "And moreover, it has gained a new level!";
}
}
//Update item quantity...
$delitem = $item->remove();
return $note;
}
function items_click3($item, $adopt){
$mysidia = Registry::get("mysidia");
$date = date('Y-m-d');
$mysidia->db->delete("vote_voters", "adoptableid = '{$adopt->aid}' and date='{$date}'");
//Update item quantity...
$delitem = $item->remove();
$note = "By using item {$item->name}, you have make your adoptables eligible for clicking by everyone again!";
return $note;
}
function items_breed1($item, $adopt){
$mysidia = Registry::get("mysidia");
// Update the lastbred info.
$mysidia->db->update("owned_adoptables", array("lastbred" => 0), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note = "The item has been successfully used on your adoptable, it can breed again!<br>";
//Update item quantity...
$delitem = $item->remove(1, $item->owner);
return $note;
}
function items_breed2($item, $adopt){
$mysidia = Registry::get("mysidia");
// Note this function exists but is not useful until Mys v1.3.2, when adoptables can carry/attach items.
$mysidia->db->update("owned_adoptables", array("lastbred" => 0), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note = "The item has been successfully used on your adoptable, it can breed again!<br>";
//Update item quantity...
$delitem = $item->remove();
return $note;
}
function items_alts1($item, $adopt){
$mysidia = Registry::get("mysidia");
// First lets check if alternative image exists for an adoptable at this level.
$lev = $mysidia->db->select("levels", array(), "adoptiename='{$adopt->type}' and thisislevel ='{$adopt->currentlevel}'")->fetchObject();
if($lev->alternateimage == ""){
// The alternate image does not exist, cannot convert adoptable into its alternate form
$note = "It appears that your adoptable does not have an alternate image at its given level...<br>";
}
else{
// The alternate image exists, conversion between primary and alternate image is possible.
switch($adopt->usealternates){
case "yes":
$mysidia->db->update("owned_adoptables", array("usealternates" => 'no'), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note = "Your adoptable has assume the species primary form.";
break;
default:
$mysidia->db->update("owned_adoptables", array("usealternates" => 'yes'), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note = "Your adoptable {$adopt->name} has assume the species alternate form.";
}
//Update item quantity...
$delitem = $item->remove();
}
return $note;
}
function items_alts2($item, $adopt){
$note = "This feature will be available soon after we redesign the adoptable class, enjoy!";
return $note;
}
function items_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_gender($item, $adopt){
$mysidia = Registry::get("mysidia");
$delitem = $item->remove();
$gender = $adopt->getGender();
switch($gender){
case "m":
$newgender = "f";
$newgender_full = "female";
break;
default:
$newgender = "m";
$newgender_full = "male";
}
$mysidia->db->update("owned_adoptables", array("gender" => $newgender), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note = "Success! The <b>{$item->itemname}</b> has worked its magic. {$adopt->name} is now a {$newgender_full}.";
return $note;
}
?>
class_privateitem.php:
<?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 "Level4":
$message = items_level4($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 "Gender":
$message = items_gender($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;
}
}
?>
Abronsyth
02-04-2016, 02:24 PM
Did you remember to add the new function into your database?
NobodysHero
02-06-2016, 11:29 PM
Yep, inserted everything it said to as far as I can tell, but it won't work. Not sure what I missed or did wrong.
Kyttias
02-07-2016, 01:16 AM
There are four steps. First, to add it to your database, second to edit functions/functions_items.php, third to create the item, and fourth to make it so the item will work by adding it to classes/class_privateitem.php. Can I see what you did for step four?
NobodysHero
02-07-2016, 01:30 AM
Here's what I posted before, Kyttias. I believe this has the information you're asking about.
My mistake for staying up way past my normal bed time. Heh. When I use the gender swap item, it gives me a blank page and the gender doesn't change. Now, I'm certain I did something wrong, but I have no idea what it is.
item_functions.php:
<?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_level4($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{
//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_click1($item, $adopt){
$mysidia = Registry::get("mysidia");
$newclicks = $adopt->totalclicks + $item->value;
$mysidia->db->update("owned_adoptables", array("totalclicks" => $newclicks), "aid='{$adopt->aid}'and owner='{$item->owner}'");
$note = "By using {$item->itemname}, the adoptable's total number of clicks has raised by {$item->value}<br>";
//Now lets check if the adoptable has reached a new level.
$ownedAdopt = new OwnedAdoptable($adopt->aid);
if($ownedAdopt->hasNextLevel()){
//new level exists, time to check if the total clicks have reached required minimum clicks for next level.
$nextLevel = $ownedAdopt->getNextLevel();
$requiredClicks = $nextLevel->getRequiredClicks();
if($newclicks >= $requiredClicks and $requiredClicks != 0 and $requiredClicks != ""){
// We need to level this adoptable up...
$mysidia->db->update("owned_adoptables", array("currentlevel" => $nextLevel->getLevel()), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note .= "And moreover, it has gained a new level!";
}
}
//Update item quantity...
$delitem = $item->remove();
return $note;
}
function items_click2($item, $adopt){
$mysidia = Registry::get("mysidia");
$newclicks = $item->value;
$mysidia->db->update("owned_adoptables", array("totalclicks" => $newclicks), "aid='{$adopt->aid}'and owner='{$item->owner}'");
$note = "By using {$item->itemname}, the adoptable's total number of clicks has raised by {$item->value}<br>";
//Now lets check if the adoptable has reached a new level.
$ownedAdopt = new OwnedAdoptable($adopt->aid);
if($ownedAdopt->hasNextLevel()){
//new level exists, time to check if the total clicks have reached required minimum clicks for next level.
$nextLevel = $ownedAdopt->getNextLevel();
$requiredClicks = $nextLevel->getRequiredClicks();
if($newclicks >= $requiredClicks and $requiredClicks != 0 and $requiredClicks != ""){
// We need to level this adoptable up...
$mysidia->db->update("owned_adoptables", array("currentlevel" => $nextlevel), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note .= "And moreover, it has gained a new level!";
}
}
//Update item quantity...
$delitem = $item->remove();
return $note;
}
function items_click3($item, $adopt){
$mysidia = Registry::get("mysidia");
$date = date('Y-m-d');
$mysidia->db->delete("vote_voters", "adoptableid = '{$adopt->aid}' and date='{$date}'");
//Update item quantity...
$delitem = $item->remove();
$note = "By using item {$item->name}, you have make your adoptables eligible for clicking by everyone again!";
return $note;
}
function items_breed1($item, $adopt){
$mysidia = Registry::get("mysidia");
// Update the lastbred info.
$mysidia->db->update("owned_adoptables", array("lastbred" => 0), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note = "The item has been successfully used on your adoptable, it can breed again!<br>";
//Update item quantity...
$delitem = $item->remove(1, $item->owner);
return $note;
}
function items_breed2($item, $adopt){
$mysidia = Registry::get("mysidia");
// Note this function exists but is not useful until Mys v1.3.2, when adoptables can carry/attach items.
$mysidia->db->update("owned_adoptables", array("lastbred" => 0), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note = "The item has been successfully used on your adoptable, it can breed again!<br>";
//Update item quantity...
$delitem = $item->remove();
return $note;
}
function items_alts1($item, $adopt){
$mysidia = Registry::get("mysidia");
// First lets check if alternative image exists for an adoptable at this level.
$lev = $mysidia->db->select("levels", array(), "adoptiename='{$adopt->type}' and thisislevel ='{$adopt->currentlevel}'")->fetchObject();
if($lev->alternateimage == ""){
// The alternate image does not exist, cannot convert adoptable into its alternate form
$note = "It appears that your adoptable does not have an alternate image at its given level...<br>";
}
else{
// The alternate image exists, conversion between primary and alternate image is possible.
switch($adopt->usealternates){
case "yes":
$mysidia->db->update("owned_adoptables", array("usealternates" => 'no'), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note = "Your adoptable has assume the species primary form.";
break;
default:
$mysidia->db->update("owned_adoptables", array("usealternates" => 'yes'), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note = "Your adoptable {$adopt->name} has assume the species alternate form.";
}
//Update item quantity...
$delitem = $item->remove();
}
return $note;
}
function items_alts2($item, $adopt){
$note = "This feature will be available soon after we redesign the adoptable class, enjoy!";
return $note;
}
function items_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_gender($item, $adopt){
$mysidia = Registry::get("mysidia");
$delitem = $item->remove();
$gender = $adopt->getGender();
switch($gender){
case "m":
$newgender = "f";
$newgender_full = "female";
break;
default:
$newgender = "m";
$newgender_full = "male";
}
$mysidia->db->update("owned_adoptables", array("gender" => $newgender), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
$note = "Success! The <b>{$item->itemname}</b> has worked its magic. {$adopt->name} is now a {$newgender_full}.";
return $note;
}
?>
class_privateitem.php:
<?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 "Level4":
$message = items_level4($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 "Gender":
$message = items_gender($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;
}
}
?>
Kyttias
02-07-2016, 02:09 AM
(For some reason I thought that was someone else's post, sorry. x'D)
Hmm... but all other item functions work? If you were to create a new item where all it did was put out a note that said 'Hello this item worked'... it would work? The code looks fine, and it's really baffling that there's no error message at all.
Can you confirm for me whether or not you have the Alternate Gender Images mod installed? I see that you're using the version of the code for those that don't have it installed.
NobodysHero
02-07-2016, 10:31 AM
At current, we are not interested in using that mod. There is only one species on our site that has a different outcome, it seems unnecessary at this time. ^.^ So, in short, no, it's not installed. LOL I've no idea what to do on this. x.x Completely lost.
Kyttias
02-07-2016, 11:06 AM
I can't find any syntax errors with an automatic checker, but HoF suggests for me to have you look in your error logs. For some hosts, it'll be a file in the same directory as the Mysidia installation. With others it'll be grouped in php management tools. If you can't figure out where to find your error logs, let me know what hosting you're on (or ask around your hosting's forums)?
NobodysHero
02-09-2016, 09:29 PM
The error log is pretty easy to find on my hosting. XD But the only entry there is a lil cryptic.
2016-02-09 21:23:41.073 [INFO] [5.254.97.87:54411-0#APVH_mystfell.com] File not found [/home/mystfell/public_html/403.shtml]
I have no idea what that means. >.> So... If that helps you help me, then yay! XD
Kyttias
02-09-2016, 10:25 PM
=/ That's probably not it, then.
Hall of Famer
02-09-2016, 10:41 PM
The issue is with this line:
$gender = $adopt->getGender();
The $adopt from item functions is not an instance of class OwnedAdoptable, but an instance of StdClass with properties of the same name as the database columns. This has a historical reason, as the model class for Adoptable and OwnedAdoptable were available after Mys v1.3.2, while item functions existed back since Mys v1.3.0.
So the fix is very simple, change this line to the code below:
$gender = $adopt->gender;
Lemme know if it works.
NobodysHero
02-10-2016, 12:08 PM
YAY! Thanks, HoF! It worked! WHOO!
Kyttias
02-10-2016, 12:13 PM
Great! I've updated the first post letting people know to use a fixed version if they installed this mod before now. Weird that it took so long for this error to be found out! :ooo:
LUC1G07CH1
10-12-2016, 07:52 PM
When i started doing my site,that worked.
But now it shows that message:
Parse error: syntax error, unexpected '?>', expecting function (T_FUNCTION) in /home/enchante/public_html/classes/class_privateitem.php on line 175
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.