Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Addons and Modifications > Mys v1.2.x Mods

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 03-13-2011, 05:41 AM
fadillzzz fadillzzz is offline
Dev Staff
 
Join Date: Jan 2010
Posts: 501
Gender: Male
Credits: 26,562
fadillzzz is an unknown quantity at this point
Default Secure Random Adoption V2

This mod is intended for people who already or wanted to have a random adoption process on their adoptables site.

Compatibility: Mys V1.2.x
NOTE:Please make a backup of your files before installing this mod!


1. Open your adopt.php and find
PHP Code:
    $query "SELECT * FROM ".$prefix."adoptables"
replace it with the code below to fetch only 1 random adoptables from the database
PHP Code:
    $query "SELECT * FROM ".$prefix."adoptables ORDER BY RAND() LIMIT 1"
2. A few lines after that, find
PHP Code:
    $article_content .= "<form name='form1' method='get' action='doadopt.php'> 
replace it with this
PHP Code:
    $article_content .= "<form name='form1' method='post' action='adopt.php'> 
3. And then, go find this code
PHP Code:
        if($canadopt == "yes"){
            
//If we can adopt the adoptable, show the image and adoption link...
            
$article_content .= "<tr>
            <td><input type='radio' name='id' id='id' value='
{$aid}' /></td>
            <td style='text-align: center'><img src='"
.$eggimage."' /></td>

            <td><strong>
{$type}</strong> -  {$row['cost']} {$GLOBALS['settings']['cost']}.<br  />{$description}</td></tr>";
        } 
Since we only want to show 1 adoptables and obviously without any information for randomness, replace that code with
PHP Code:
        if($canadopt == "yes"){
            
//If we can adopt the adoptable, show the image and adoption link...
            
$article_content .= "<tr>
            <td style='text-align: center'><img src='"
.$eggimage."' /></td>";
        }
        else{
            
$eresult runquery("SELECT * FROM ".$prefix."adoptables WHERE whenisavail='always' ORDER BY RAND() LIMIT 1");
            while(
$erow mysql_fetch_array($eresult)){
                
$aid=$erow['id']; //The adoptable's ID
                
$type=$erow['type'];
                
$description=$erow['description'];
                
$eggimage=$erow['eggimage'];
                
$article_content .= "<tr>

                <td style='text-align: center'><img src='"
.$eggimage."' /></td>";
            }

        } 
You may notice that I put an else statement. The else statement is used in case the first query fetch an adoptables that you can't adopt because you haven't met the necessary requirement. It will fetch an adoptables with the always available condition.
Anyway, let's move on.
4. Find the following
PHP Code:
    $query "SELECT * FROM ".$prefix."adoptables WHERE id='$id' LIMIT 1"
and replace it with
PHP Code:
    $query "SELECT * FROM ".$prefix."adoptables WHERE id='$id' AND whenisavail='promo' LIMIT 1"
Restrict the GET method only for adopting adoptables with promo code
5. Finally, find the last closing curly bracket
PHP Code:
// This bracket ends the else statements for whether or not an ID was entered 
and below that add this code
PHP Code:
if($_POST)
{
$id $aid;
$name $_POST["name"];

    if(
$isloggedin == "yes"){
        
// I guess the first thing to do is see if we have a valid adoptable ID submitted...
        
if($id == "" or !is_numeric($id)){
            
$article_title $err_idnoexist;
            
$article_content $err_idnoexist_text;
        }
        else{
            
// The adoptable ID appears to be valid, so we need to  double check that it is valid by pulling up the adoptable in the DB

            
$query "SELECT * FROM ".$prefix."adoptables WHERE id='$id'";
            
$result runquery($query);

            
$result runquery($query);
            
$row mysql_fetch_array($result);

            
$aid $row['id'];
            
$type=$row['type'];
            
$description=$row['description'];
            
$eggimage=$row['eggimage'];

            if(
$id == $aid){
                
// The ID submitted matches an existing adoptable type
                
$canadopt canadopt($aid"adopting"$promocode$row);

                
// If we can adopt this creature, do the adoption
                
if($canadopt == "yes") {
                    if (
changecash(-$row['cost'], $GLOBALS['loggedinname'], $GLOBALS['money'])==true) {                
                        
// BEGIN the actual adoption process

                        // First we see if we have a custom name; if not, we use the default name
                        
if($name == ""){
                            
$name "Mystery Egg";
                        }

                        
// Now we determine if we are using alternate images or not

                        
$alts getaltstatus($id00);

                        
// We need a unique code for the adoptable so we can show it to the user when we're done here...

                        
$code rand(120000);
                        
$genders = array('f''m');
                        
$rand rand(0,1);
                        
                        
runquery("INSERT INTO  ".$prefix."owned_adoptables VALUES ('', '$type',  '$name','$loggedinname','0','0', '$code', '','$alts','fortrade','no',  '$genders[$rand]','0')");

                        
// Adoption complete, show the user a confirmation screen...

                        
$query "SELECT * FROM ".$prefix."owned_adoptables WHERE code='$code' and owner='$loggedinname'";
                        
$result runquery($query);
                        
$num mysql_numrows($result);
                         
                        
$id=@mysql_result($result,0,"aid"); 

                        
$article_title $name." adopted successfully";
                        
$article_content "<img  src='".$eggimage."'><br>".$congrats1." ".$name.".  You can now  manage ".$name." on the 
                        <a href='myadopts.php'>My Adopts</a>  page.<br><br><b><a  href='myadopts.php?act=manage&id="
.$id."'>Click Here to Manage  ".$name."</a><br>
                        <a  href='myadopts.php?act=bbcode&id="
.$id."'>Click Here to get  BBCodes / HTML Codes for  ".$name."</a></b><br><br>
                        Be sure and <a  href='levelup.php?id="
.$id."'>feed</a> ".$name." with clicks so  that they grow!";

                        
// END the actual adoption process
                    
}
                    else {
                        
$article_title "Not enough money.";
                        
$article_content "You don't have enough  {$GLOBALS['settings']['cost']} to buy this adoptable. Earn some money  and then try again.";
                    }
                }
                else {
                    
$article_title $accden;
                    
$article_content $adoptnoper;
                }
            } 
// End the if for if $id == $aid
            
else {
                
// Adoptable does not exist, show an error.

                
$article_title $err_idnoexist;
                
$article_content $err_idnoexist_text;
            } 
// End the else for if $id == $aid
        
// End the valid ID input else test statement (bulk of code goes above here)
    
// End the log in check IF
    
else {
        
// Guests cannot adopt pets, so why bother...
        
$article_title $guesttitleerror;
        
$article_content $guesterror;
    } 
// End the log in check ELSE 


6.
Now, to prevent some users from cheating. Open your doadopt.php, we'll just do a slight query modification.
Find this query
PHP Code:
        $query "SELECT * FROM ".$prefix."adoptables WHERE id='$id'"
replace that query with this one
PHP Code:
        $query "SELECT * FROM ".$prefix."adoptables WHERE id='$id' AND whenisavail = 'promo'"
We just restricted the doadopt.php file to only work with adoptables with promo code.

Done!

Let me know if there's any problem with this mod. :)
Reply With Quote
  #2  
Old 03-15-2011, 09:58 AM
Missy Master's Avatar
Missy Master Missy Master is offline
Pet-Sim.Online
 
Join Date: Jan 2010
Posts: 475
Gender: Unknown/Other
Credits: 30,056
Missy Master is an unknown quantity at this point
Default

Excellent, this happens to be exactly what I needed right now!! Thank you so much!!
Reply With Quote
  #3  
Old 03-18-2011, 12:50 PM
RoconzaArt's Avatar
RoconzaArt RoconzaArt is offline
Member
 
Join Date: Jan 2011
Location: NJ Shore (and proud of it)
Posts: 479
Gender: Female
Credits: 29,143
RoconzaArt is an unknown quantity at this point
Default

I'd like to thank you very much this is just what I needed for my site and it works perfectly.
__________________
Reply With Quote
  #4  
Old 03-18-2011, 01:00 PM
fadillzzz fadillzzz is offline
Dev Staff
 
Join Date: Jan 2010
Posts: 501
Gender: Male
Credits: 26,562
fadillzzz is an unknown quantity at this point
Default

You're welcome!
I'm glad that this mod help some people on building their adoptables site.
Reply With Quote
  #5  
Old 02-28-2012, 11:33 AM
Kesstryl's Avatar
Kesstryl Kesstryl is offline
Member
 
Join Date: Feb 2012
Posts: 125
Gender: Female
Credits: 12,250
Kesstryl is on a distinguished road
Default

I noticed that the code in the doadopt.php has some minor variation, will this effect the above changes?

Here's the current code, noticing brackets instead of single quotes:

$query = "SELECT * FROM {$prefix}adoptables WHERE id={$id}";
Reply With Quote
  #6  
Old 02-28-2012, 12:20 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: 227,332
Hall of Famer is on a distinguished road
Default

Nope, the bracket and single quote both work perfectly. In fact the bracket version is preferred and used in current Mysidia Adoptables script, as it is easier to read from the viewpoints of mine and my coders'.
__________________


Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site.
Reply With Quote
  #7  
Old 02-28-2012, 12:29 PM
Kesstryl's Avatar
Kesstryl Kesstryl is offline
Member
 
Join Date: Feb 2012
Posts: 125
Gender: Female
Credits: 12,250
Kesstryl is on a distinguished road
Default

Thanks for the quick reply
Reply With Quote
  #8  
Old 02-28-2012, 02:57 PM
Kesstryl's Avatar
Kesstryl Kesstryl is offline
Member
 
Join Date: Feb 2012
Posts: 125
Gender: Female
Credits: 12,250
Kesstryl is on a distinguished road
Default

I'm not sure if this is the place to ask, and if not, let me know, but I would like to add an extra feature to this code which makes some of the random pets more rare than others. I found this code on this site which uses a 'chance' variable which will decrease the odds of the random pick on some of the images:

http://www.chickensmoothie.com/tutorial/tut3/index.html

If anyone has time to take a peek and let me know how this can be added into this mod code, I would be very grateful as I'm good at following directions, but not so good at knowing how to do this myself.
Reply With Quote
Reply

Thread Tools
Display Modes

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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adoption Problems Kamalya Questions and Supports 8 01-27-2013 02:15 PM
Secure Random Adoption Process fadillzzz Mys v1.1.x Mods 19 02-14-2011 12:12 PM
Random Adoption nitrogen Questions and Supports 4 05-10-2009 10:10 AM
Random 5 is not realy random! RipJawWolfFang Questions and Supports 9 04-30-2009 07:03 AM


All times are GMT -5. The time now is 12:31 AM.

Currently Active Users: 286 (0 members and 286 guests)
Threads: 4,078, Posts: 31,984, 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 - 2021, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636