Mysidia Adoptables Support Forum  

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

Notices

Reply
 
Thread Tools Display Modes
  #21  
Old 08-20-2013, 10:21 PM
Hwona's Avatar
Hwona Hwona is offline
Member
 
Join Date: Mar 2013
Posts: 620
Gender: Female
Credits: 48,801
Hwona is on a distinguished road
Default re

Uh oh, I'm a bummer - can someone show me an example or the location of the source codes? :(
__________________
Reply With Quote
  #22  
Old 08-20-2013, 10:50 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,383
IntoRain is on a distinguished road
Default

Hall Of Famer means the function you made, the whole code from the file

Btw you have the if still liek this?

if($gender = 'f')

It should be if($gender == 'f')

= means you are giving the variable a value. == means you are comparing it (it's a function that says if it is false or true)

Btw if you already have the switch-case you can take the if off. Like

PHP Code:
switch(...)
{

  case 
'f':
     
//it's female
     
break;
  case 
'm':
    
// it's male
     
break;
  default:
   
//error
     
break;

Also if the function receives an adopt, to get the gender of it you don't need to use select, you even use $adopt->gender on the switch. That is confusing me a lot xD To verify if the owner of the item and the owner of the adopt are the same you can use an if($adopt->owner == $item->owner), right?

Last edited by IntoRain; 08-20-2013 at 11:41 PM.
Reply With Quote
  #23  
Old 08-21-2013, 07:57 AM
Hwona's Avatar
Hwona Hwona is offline
Member
 
Join Date: Mar 2013
Posts: 620
Gender: Female
Credits: 48,801
Hwona is on a distinguished road
Default Re

Oh, it has to be 2 equal signs - I'll try that! Thanks for the tip. :3

Edit: Thanks, you fixed half of my problem! The item says "action completed" and gets deleted, but my male adoptable is still male, and the "gender change successful messge" does not pop up. :L

Also, here's the code:
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_genderf($item$adopt){
        
$mysidia Registry:: get("mysidia");
        
//Let's check if the adoptable is already female.
        
$gender $mysidia -> db -> select ("owned_adoptables", array("gender"), "aid='{$adopt->aid}' and owner ='{$item->owner}'") -> fetchColumn();  
        if(
$gender == "f") {
            
//The adoptable is already female
            
$note "Your adoptable is already female.";
        }
        else{
            
//The adoptable is male. It's gender can be switched to female.
            
switch($adopt->gender){
                case 
"f":
                    
$mysidia -> db -> update("owned_adoptables", array("gender" => 'f'),"aid='{$adopt->aid}' and owner ='{$item->owner}'");
                    
$note "Your adoptable {$adopt->name} is now female.";
            }
            
//Update item quantity...
            
$delitem $item->remove();
        }
        return 
$note;
        }  
?>
__________________

Last edited by Hwona; 08-21-2013 at 08:06 AM.
Reply With Quote
  #24  
Old 08-21-2013, 11:03 AM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,383
IntoRain is on a distinguished road
Default

I simulated what you wanted to do and it's working, I used only if's instead switch-cases (not to mix if's and switch-cases since they both do the same):

PHP Code:
function items_genderf($item$adopt){
  
$mysidia Registry::get("mysidia");
   
                
//Let's check if the adoptable is already female.
            
if($adopt->gender == 'f')
            {   
//The adoptable is already female
                
$note "Your adoptable is already female.";
            }
            else{
            
//The adoptable is male
             
$mysidia->db->update("owned_adoptables", array("gender" => 'f'),"aid='{$adopt->aid}' and owner ='{$item->owner}'");
             
$delitem $item->remove();  
                 
$note "Your adoptable {$adopt->name} is now female.";    
              }
            
        return 
$note;
 } 
Just switch:

PHP Code:
       $mysidia Registry:: get("mysidia");
        
//Let's check if the adoptable is already female.
            
       
switch($adopt->gender)
       {
               case 
"f":
            
$note "Your adoptable is already female.";
            break;
               case 
"m":
                          
$mysidia->db->update("owned_adoptables", array("gender" => 'f'),"aid='{$adopt->aid}' and owner='{$item->owner}'");
                   
$note "Your adoptable is now female.";
                   
$delitem $item->remove();
                   break;
               default:
                   
$note "It appears your adoptable doesn't have a gender.";                   
           
       }
          return 
$note
You can also use your own code, you one error only. In the switch-case, it should be case 'm'. Case 'f' means "if it is female, change to female.", so case 'm' means "If it is male, change to female.".

Also, the item deletes anyway at the end because it's not inside the the case. You have to delete the item if it succeeds, so it should be inside the case.

Also each case must end with break; so it knows when to stop.

Since your adopt was male, it was reaching the switch-case (the else). But it would only activate if it was female, so it ignored it and proceeded to item deletion so that's why it was decreasing and not changing the gender. To avoid this kind of confusion, you only delete the item if the switch-case is sucessful.

With your own code:

PHP Code:
       $mysidia Registry:: get("mysidia");
        
//Let's check if the adoptable is already female.
        
$gender $mysidia -> db -> select ("owned_adoptables", array("gender"), "aid='{$adopt->aid}' and owner ='{$item->owner}'") -> fetchColumn();  
        if(
$gender == "f") {
            
//The adoptable is already female
            
$note "Your adoptable is already female.";
        }
        else{
            
//The adoptable is male. It's gender can be switched to female.
            
switch($adopt->gender){
                case 
"m":
                    
$mysidia -> db -> update("owned_adoptables", array("gender" => 'f'),"aid='{$adopt->aid}' and owner ='{$item->owner}'");
                    
$note "Your adoptable {$adopt->name} is now female.";
                   
//Update item quantity...
                   
$delitem $item->remove();
                    break;
            }
        }
        return 
$note
One thing, you really don't need to get the gender from a select, it's ok to just do $adopt->gender

Last edited by IntoRain; 08-21-2013 at 05:15 PM. Reason: removed part of text
Reply With Quote
  #25  
Old 08-21-2013, 12:49 PM
Hall of Famer's Avatar
Hall of Famer Hall of Famer is offline
Administrator, Lead Coder
 
Join Date: Dec 2008
Location: South Brunswick
Posts: 4,448
Gender: Male
Credits: 334,366
Hall of Famer is on a distinguished road
Default

I guess my post was a bit misleading, I was merely referring to the source code of the very item function you created, not the source code of the entire functions_items.php file. For this case it is not a problem, but at some circumstances it may be time consuming to read through an entire script file. Id say just post the code that aint working is sufficient when bringing up a problem.
__________________


Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site.
Reply With Quote
  #26  
Old 08-21-2013, 04:35 PM
Hwona's Avatar
Hwona Hwona is offline
Member
 
Join Date: Mar 2013
Posts: 620
Gender: Female
Credits: 48,801
Hwona is on a distinguished road
Default Re

Ah. I see! xP
Well, in that case, here's the code! :D

PHP Code:
function items_genderf($item$adopt){
        
$mysidia Registry:: get("mysidia");
        
//Let's check if the adoptable is already female.
        
$gender $mysidia -> db -> select ("owned_adoptables", array("gender"), "aid='{$adopt->aid}' and owner ='{$item->owner}'") -> fetchColumn();  
        if(
$gender == "f") {
            
//The adoptable is already female
            
$note "Your adoptable is already female.";
        }
        else{
            
//The adoptable is male. It's gender can be switched to female.
            
switch($adopt->gender){
                case 
"f":
                    
$mysidia -> db -> update("owned_adoptables", array("gender" => 'f'),"aid='{$adopt->aid}' and owner ='{$item->owner}'");
                    
$note "Your adoptable {$adopt->name} is now female.";
            }
            
//Update item quantity...
            
$delitem $item->remove();
        }
        return 
$note;
        } 
Edit: O.o Thank you guys sooooooo much! - It works! :D

Here's the finished code :D:
PHP Code:
function items_genderf($item$adopt){
        
$mysidia Registry:: get("mysidia");
        
//Let's check if the adoptable is already female.
        
$gender $mysidia -> db -> select ("owned_adoptables", array("gender"), "aid='{$adopt->aid}' and owner ='{$item->owner}'") -> fetchColumn();  
        if(
$gender == "f") {
            
//The adoptable is already female
            
$note "Your adoptable is already female.";
        }
        else{
            
//The adoptable is male. It's gender can be switched to female.
            
switch($adopt->gender){
                case 
"m":
                    
$mysidia -> db -> update("owned_adoptables", array("gender" => 'f'),"aid='{$adopt->aid}' and owner ='{$item->owner}'");
                    
$note "Your adoptable {$adopt->name} is now female.";
            }
            
//Update item quantity...
            
$delitem $item->remove();
        }
        return 
$note;
        } 
__________________

Last edited by Hwona; 08-21-2013 at 04:48 PM.
Reply With Quote
  #27  
Old 08-21-2013, 04:40 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,383
IntoRain is on a distinguished road
Default

I already explained why it wasn't working, see the post above Hall Of Famer's. Your switch case is wrong

case "f":
....

^ The switch-case only does the code (update thingy) you have after it if your adopt's gender is female. So it will only change the gender from female to female. You need to change it to case "m".

Last edited by IntoRain; 08-21-2013 at 05:12 PM.
Reply With Quote
  #28  
Old 08-21-2013, 04:51 PM
Hwona's Avatar
Hwona Hwona is offline
Member
 
Join Date: Mar 2013
Posts: 620
Gender: Female
Credits: 48,801
Hwona is on a distinguished road
Default

Yeah, I edited my last post. Anyways, thank you so much! I probably would have kept changing the code and fixing nothing if you didn't point that out. >^.^<
__________________
Reply With Quote
  #29  
Old 08-21-2013, 05:04 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,383
IntoRain is on a distinguished road
Default

Quote:
Originally Posted by Wallie987 View Post
Yeah, I edited my last post. Anyways, thank you so much! I probably would have kept changing the code and fixing nothing if you didn't point that out. >^.^<
Yay that's great! :D
Reply With Quote
  #30  
Old 09-26-2014, 03:31 PM
ilrak ilrak is offline
Goldfish Fanatic
 
Join Date: Aug 2014
Location: Utah
Posts: 57
Gender: Female
Credits: 11,631
ilrak is on a distinguished road
Default

Sorry to bump up this thread, but I was seeing if I could try out this mod (and then do one similar for color/marking changing) and have been running into the same item function invalid error. I'm using 1.3.4, so I'm not sure if maybe that's the issue or not or if I've run into an error with my itemfunctions table in general (I assume that the intent is for adoptable, but I may have done it wrong) . ^v^;
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with a item function kristhasirah Questions and Supports 35 04-03-2017 10:17 AM
Mys v1.3.4 Item Function: Gender Change Potion Kyttias Mys v1.3.x Mods 21 10-12-2016 07:52 PM
Calling a function in a function from the same class page Hwona Questions and Supports 2 04-25-2015 08:41 AM
Item Function Suggestions NobodysHero Suggestions and Feature Requests 5 06-23-2014 03:45 AM


All times are GMT -5. The time now is 02:14 PM.

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





What's New?

What's Hot?

What's Popular?


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