PDA

View Full Version : Adopt many adoptables at once.


Aasixx
09-14-2012, 04:16 PM
Does anyone know how to make a code where I can set a number of adoptables (making custom adoption center/place) that they can adopt all at once? Like, let's say I set it to where you can adopt 14 horses, in the dropdown box you can choose how many you'd like to adopt 1-14 and whatever number they choose, that's how many adoptables will show up in their myadopts.php

I tried making one myself but it didn't turn out too great. Any help would be awesome! Thanks.

Hall of Famer
09-15-2012, 07:20 PM
Well you can just create a textfield in adopt.php in the adoption form, in which users can enter the number of adoptables they want to adopt for this particular species.

Aasixx
09-16-2012, 01:58 PM
Well you can just create a textfield in adopt.php in the adoption form, in which users can enter the number of adoptables they want to adopt for this particular species.

What would I need to do to make it give that user that many adoptables? So, like I said, 14 adoptables.

Hall of Famer
09-16-2012, 10:45 PM
Well you can see a section of adoption form code in adopt.php like these:


$article_content = $article_content."<br><img src='{$eggimage}' border='0'><br>
<form name='form1' method='get' action='doadopt.php'>
<p>Adoptable Name:
<input name='name' type='text' id='name'>
<input name='id' type='hidden' id='id' value='{$id}'>
<input name='promocode' type='hidden' id='promocode' value='{$promocode}'>
</p>
<p>
<input type='submit' name='Submit' value='Adopt Me'>
</p>

You can add a new textfield called 'quantity' in this form section. You can place it anywhere above the submit line and below the form opening tag:


<input name='number' type='text' id='number' value='1'>
Now you will need to go to doadopt.php and retrieve this number from $_GET array:

$id = $_GET["id"];
$promocode = $_GET["promocode"];
$name = $_GET["name"];
Add below:


$number = $_GET['number']
The processing of multi-adopts is quite tricky, you will need a while or for loop to complete the task. Find this section of code:


// 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 = $row->type;

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

$alts = getaltstatus($id, 0, 0);

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

$code = codegen(10, 0);
$genders = array('f', 'm');
$rand = rand(0,1);

$adopts->insert("owned_adoptables", array("aid" => NULL, "type" => $row->type, "name" => $name, "owner" => $loggedinname, "currentlevel" => 0, "totalclicks" => 0, "code" => $code,
"imageurl" => NULL, "usealternates" => $alts, "tradestatus" => 'fortrade', "isfrozen" => 'no', "gender" => $genders[$rand], "lastbred" => 0));

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

$owned_adoptable = $adopts->select("owned_adoptables", array(), "code='{$code}' and owner='{$loggedinname}'")->fetchObject();
$id = $owned_adoptable->aid;

$article_title = $name." adopted successfully";
$article_content = "<img src='{$row->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!";
unset($_SESSION["allow"]);
// 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.";
}
}
Replace with:


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

for(i = 0; i < $number; i++){

// First we see if we have a custom name; if not, we use the default name
if($name == "") $name = $row->type;

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

$alts = getaltstatus($id, 0, 0);

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

$code = codegen(10, 0);
$genders = array('f', 'm');
$rand = rand(0,1);

$adopts->insert("owned_adoptables", array("aid" => NULL, "type" => $row->type, "name" => $name, "owner" => $loggedinname, "currentlevel" => 0, "totalclicks" => 0, "code" => $code,
"imageurl" => NULL, "usealternates" => $alts, "tradestatus" => 'fortrade', "isfrozen" => 'no', "gender" => $genders[$rand], "lastbred" => 0));

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

$owned_adoptable = $adopts->select("owned_adoptables", array(), "code='{$code}' and owner='{$loggedinname}'")->fetchObject();
$id = $owned_adoptable->aid;

$article_title = $name." adopted successfully";
$article_content = "<img src='{$row->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!";
unset($_SESSION["allow"]);
// 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 with the entered quantity. Earn some money and then try again.";
}
}
Keep in mind that this is a drastic change of the script and I cannot promise that you won't be getting lots of unexpected errors. Lemme know if anything happens though, they should not be hard to fix.

Aasixx
09-17-2012, 09:14 AM
At first I got this after pressing "Adopt Me"
Parse error: syntax error, unexpected T_IF in /home/albisian/public_html/doadopt.php on line 17

and then I added a missing ";" for this
$number = $_GET['number']

and got a new error:
Parse error: syntax error, unexpected '=', expecting ';' in /home/albisian/public_html/doadopt.php on line 47

Hall of Famer
09-17-2012, 09:17 AM
Well what is line 47 for you?

Aasixx
09-17-2012, 09:23 AM
Opened doadopt.php in Notepad++ and this is at line 47:
for(i = 0; i < $number; i++){

Hall of Famer
09-17-2012, 09:34 AM
Oh my what was I thinking... Replace this line with the code below:


for($i = 0; $i < $number; $i++){


Guess I was so lost in the last Java programming assignment, which does not use dollar sign as their variable name. XD

Aasixx
09-17-2012, 10:14 AM
Haha, it's okay. Thank you!

Hall of Famer
09-17-2012, 11:16 AM
No worries, I find it easier to use PHP's syntax though, since I am still at heart a PHP programmer. I am learning a Java course at school at this moment, hoping to strengthen my skills as an object-oriented programmer. Of course I try not to let this interfere with my php coding, since sometimes it can. XD