PDA

View Full Version : Direct Adopt Link?


Abronsyth
12-27-2015, 01:25 PM
Resolved

Hey so I'm trying to figure out how to do this so that I can give users the choice of whether or not they actually adopt a pet when they find one while exploring.

So I want to add a link that, once clicked, adds the specific adopt they found to their account.

Instead of;
"Oh, you found a kitten!" and it automatically adding the cat to their account, it'd be;
"Oh, you found a kitten! Adopt it?" with clicking "adopt it" adding the cat to their account.

Does anyone know how to do this?

Kyttias
12-27-2015, 02:27 PM
I can't fully test this, but it's worth a shot. On the 'view' version of whatever explore area, we're going to create a new function that'll post an invisible form -- all you'll see is the button. It'll be easy to call, so we're doing it with a function to save time later.


public function pickupPet($species){
$document = $this->document;
$document->add(new Comment("
<form id='pickup_pet' action='explore' name='pickup_pet' method='post' role='form'>
<input id='pet_found' name='pet_found' type='hidden' value='{$species}'>
<button id='acquire' value='species' name='acquire' type='submit'>
Pick up this {$species}?
</button>
</form>
", FALSE));
return;
}


It'll be called like this (so wherever you put this line, the button will appear):
$this->pickupPet("Dezh"); // one of my species is a Dezh, for example

When the form is submitted, it'll bounce back to this page. We want the page to do something when it detects form data has been submitted!

if($mysidia->input->post("pet_found")){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$species = $mysidia->input->post("pet_found");
$this->givePet($species);
$document->setTitle("Pet Acquired!");
$document->add(new Comment("You've collected a {$species}!. "));
}


Okay, but now need to include the function that'll actually give the pet to the user.

public function givePet($species){
$mysidia = Registry::get("mysidia");
$newadopt = new StockAdopt($species);
$newadopt->append($mysidia->user->username);
return;
}


Unfortunately, I'm out the door so I can't explain better. D; Hope some of this helps!
edit: Lots of bugs I fixed when I arrived home. -u- Hope you didn't find it in the hour meanwhile. Still untested.

Abronsyth
12-27-2015, 07:20 PM
OK, I know I'm doing something very wrong, but I attempted to put it together like this (and I am fairly certain this is incorrect), as instead of adding the cat to my account and displaying the "you've found..." page it is sending me to the .../explore page (and not adding the cat to the account). Is it the "action" part of the form that needs to be altered..?
public function pickupPet($species){
$document = $this->document;
$document->add(new Comment("
<form id='pickup_pet' action='explore' name='pickup_pet' method='post' role='form'>
<input id='pet_found' name='pet_found' type='hidden' value='{$species}'>
<button id='acquire' value='species' name='acquire' type='submit'>
<center>Pick up this cat?</center>
</button>
</form>
", FALSE));
return;
if($mysidia->input->post("pet_found")){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$species = $mysidia->input->post("pet_found");
$this->givePet($species);
$document->setTitle("Kitten Acquired!");
$document->add(new Comment("You've collected a new Fleet!. "));
}
}

public function givePet($species){
$mysidia = Registry::get("mysidia");
$newadopt = new StockAdopt($species);
$newadopt->append($mysidia->user->username);


return;
}

Also thank you for helping, Kyttias! I'm sorry I'm so very new with this all!

Kyttias
12-27-2015, 10:21 PM
Probably! If the form doesn't work, try changing the action to the name of the current page?

Unfortunately, this is meant to work with my explore system (http://www.mysidiaadoptables.com/forum/showthread.php?t=4752), not one by other users... It should be easily modified, though? I haven't tried using other people's since mine fits my needs. (I'd rather only have on page, than have to make a new page for each zone.)

And um...yeah, some of that stuff isn't quite right in right order, hang on...


//Normal page stuff
$document->add(new Comment("Lalala we're exploring.", FALSE));

//Call the function that'll add the button to pick up a cat
$this->pickupPet("Fleet");

//This function generates the form
public function pickupPet($species){
$document = $this->document;
$document->add(new Comment("
<form id='pickup_pet' action='explore' name='pickup_pet' method='post' role='form'>
<input id='pet_found' name='pet_found' type='hidden' value='{$species}'>
<button id='acquire' value='species' name='acquire' type='submit'>
<center>Pick up this {$species}?</center>
</button>
</form>
", FALSE));
return;
}

//When the page loads it'll check if there's post data
if($mysidia->input->post("pet_found")){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$species = $mysidia->input->post("pet_found");
$this->givePet($species);
$document->setTitle("Kitten Acquired!");
$document->add(new Comment("You've collected a new {$species}!"));
/* Might want to add a link here to continue exploring or go elsewhere? */
}

// This function is called in the function that only works if there's post data
public function givePet($species){
$mysidia = Registry::get("mysidia");
$newadopt = new StockAdopt($species);
$newadopt->append($mysidia->user->username);
return;
}

To fix it up any better than that, I'd have to see and test the whole page. @w@'

Abronsyth
12-28-2015, 12:50 AM
Ah, so it does work perfectly with your explore system (tested it)! Actually I'm really enjoying playing with your explore system, haha. Now if I can combine the randomness from the one I was using with yours...well then I'd be all set!

Thank you for the help Kyttias, I really do appreciate it <3

EDIT:
It's ridiculous how much I am grinning right now...so I figured out how to make it so when a user visits a location (as set up in Kyttias' explore system) they have a random chance of encountering an adoptable! In fact this could be used to make the chance of encountering anything random (items, specific texts, etc). Here's just the snippet that I've gotten to work right now;
case "Area_Name":
$random = rand(1,4);
# So you want to give users a pet?
if($random >= 1 && $random <= 2){
$document->add(new Comment("Look, a pet!", FALSE));
# Quantity, Item Name, Area Name
$this->pickupPet("Pet 1");
$this->exploreButton("Next_Area", FALSE, "Continue...");
}
elseif($random >= 3 && $random <= 4){
$document->add(new Comment("Huh, nothing here!", FALSE));
$this->exploreButton("Next_Area", FALSE, "Return to Map.");
}
break;

Just in case anyone else could use this <3

draugluin
02-11-2016, 06:46 AM
Hey ... thats great. :happyc: you're amazing

Thank you both. I take this for my side too, in a different version :)

NobodysHero
02-20-2017, 12:47 PM
OKAY! So, I tried implementing this on my own and I'm still too PHP Dense to get it. Here's the "test" page code for the explore system thing I use. My code is probably jacked, but it works for now. LOL (The explore works, this is the code without any modifications for buttons.) Can someone pretty please add the code for the buttons for me, so I can see what it's suppose to look like?

Thanks for your help in advance! 8D

<?php

class ExploretestView extends View{

public function index(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$document->setTitle("Explore Test");
$today = date('d');
if ($mysidia->user->lastday != $today) {
$mysidia->db->update("users", array("exploretimes" => (0)), "username = '{$mysidia->user->username}'");
$mysidia->user->exploretimes = 0;
}

$mysidia->db->update("users", array("lastday" => $today), "username = '{$mysidia->user->username}'");
$mysidia->db->update("users", array("exploretimes" => ($mysidia->user->exploretimes + 1)), "username = '{$mysidia->user->username}'");
if ($mysidia->user->exploretimes <= 100) {
$random = rand(1,10000);

if($random > 1 && $random < 25){
$species = "Cereus Pegasus";
$newadopt = new StockAdopt($species);
$newadopt->append($mysidia->user->username);
$adoptIMG = $mysidia->db->select("adoptables", array("eggimage"), "id = '84'")->fetchColumn();
$document->add(new Comment("<center><img src='$adoptIMG' alt='$species IMG' /><br> Oh look! You found a $species! Grab it before it flies away!.</center>", FALSE));
}
elseif($random >= 26 && $random <= 50){
$amount = rand(50,20000);
$mysidia->user->changecash($amount);
$document->add(new Comment("<center>Oh look! You found $amount tyleans!</center>", FALSE));
}
if($random >= 51 && $random <= 99){
$item = "Bottled Honey";
$qty = rand(1,5);
$newitem = new StockItem($item);
$newitem->append($qty, $mysidia->user->username);
$itemIMG = $mysidia->db->select("items", array("imageurl"), "id = '44'")->fetchColumn();
$document->add(new Comment("<center><img src='$itemIMG' alt='$item IMG' /><br>Oh look! You found a <b>$item</b>!</center>", FALSE));
}
if($random >= 100 && $random <= 149){
$document->add(new Comment("<center>Okay, so you didn't get any items, but the totem spirits give you a hug!</center>", FALSE));
}
if($random >= 150 && $random <= 179){
$document->add(new Comment("<center>You know what you should do? Keep looking! There's good stuff out there.</center>", FALSE));
}
if($random >= 180 && $random <= 199){
$species = "Cereus Fox";
$newadopt = new StockAdopt($species);
$newadopt->append($mysidia->user->username);
$adoptIMG = $mysidia->db->select("adoptables", array("eggimage"), "id = '157'")->fetchColumn();
$document->add(new Comment("<center><img src='$adoptIMG' alt='$species IMG' /><br> Oh look! You found a $species! Grab it while you can!</center>", FALSE));
}
if($random >= 200 && $random <= 249){
$document->add(new Comment("<center>Man, this place sure is quiet! Well, until you showed up. Haha, I'm kidding! Keep searching!</center>", FALSE));
}
if($random >= 250 && $random <= 299){
$item = "Black Rose";
$qty = rand(1,5);
$newitem = new StockItem($item);
$newitem->append($qty, $mysidia->user->username);
$itemIMG = $mysidia->db->select("items", array("imageurl"), "id = '15'")->fetchColumn();
$document->add(new Comment("<center><img src='$itemIMG' alt='$item IMG' /><br>Oh look! You found a <b>$item</b>!</center>", FALSE));
}
if($random >= 300 && $random <= 9999){
$document->add(new Comment("<center>You didn't find anything. Look on the bright side! Things can only get better from here, right? <br><br><a href='/exploretheruins'>Explore Again</a></center>", FALSE));
$document->add(new Comment("<br><center>You have explored <b>{$mysidia->user->exploretimes} out of 100</b> total explores today. If the number of explores is greater than 100, you won't get any reward from exploring.</center></br><br><br><img src='http://i.imgur.com/SQkjh80.png' />", FALSE));
}
elseif($random == 10000){
$item = "Cereus Unicorn Figurine";
$qty = rand(1,5);
$newitem = new StockItem($item);
$newitem->append($qty, $mysidia->user->username);
$itemIMG = $mysidia->db->select("items", array("imageurl"), "id = '32'")->fetchColumn();
$document->add(new Comment("<center><img src='$itemIMG' alt='$item IMG' /><br>Oh look! You found a <b>$item</b>! Whoa, those are so rare! Keep it!</center>", FALSE));
}
else{
$document->add(new Comment("<br><center>You have explored <b>{$mysidia->user->exploretimes} out of 100</b> total explores today. If the number of explores is greater than 100, you won't get any reward from exploring.</center></br>", FALSE));
$document->add(new Comment(" <br><center><a href='/exploretheruins'>Explore Again</a></center>", FALSE));
$document->add(new Comment(" <br><center><a href='/pages/view/exploremystfell'>Return To The Main Map</a></center>", FALSE));
$document->add(new Comment("<br><center><img src='http://i.imgur.com/SQkjh80.png'></center>", FALSE));
}
}
else{
$document->add(new Comment("<br><center>You have explored <b>{$mysidia->user->exploretimes} out of 100</b> total explores today. If the number of explores is greater than 100, you won't get any reward from exploring.</center></br>", FALSE));
$document->add(new Comment(" <br><center><a href='/exploretheruins'>Explore Again</a></center>", FALSE));
$document->add(new Comment(" <br><center><a href='/pages/view/exploremystfell'>Return To The Main Map</a></center>", FALSE));
$document->add(new Comment("<br><center><img src='http://i.imgur.com/SQkjh80.png'></center>", FALSE));
}


}

}
?>

Abronsyth
02-20-2017, 02:48 PM
I didn't test it, but I think this ought to work?
<?php

class ExploretestView extends View{

public function index(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$document->setTitle("Explore Test");
$today = date('d');
if ($mysidia->user->lastday != $today) {
$mysidia->db->update("users", array("exploretimes" => (0)), "username = '{$mysidia->user->username}'");
$mysidia->user->exploretimes = 0;
}

$mysidia->db->update("users", array("lastday" => $today), "username = '{$mysidia->user->username}'");
$mysidia->db->update("users", array("exploretimes" => ($mysidia->user->exploretimes + 1)), "username = '{$mysidia->user->username}'");
if ($mysidia->user->exploretimes <= 100) {
$random = rand(1,10000);

if($random > 1 && $random < 25){
$adoptIMG = $mysidia->db->select("adoptables", array("eggimage"), "id = '84'")->fetchColumn();
$document->add(new Comment("<center><img src='{$adoptIMG}' alt='{$species} IMG' /><br> Oh look! You found a {$species}! Grab it before it flies away!.</center>", FALSE));
$this->pickupPet("{$species}");
}
elseif($random >= 26 && $random <= 50){
$amount = rand(50,20000);
$mysidia->user->changecash($amount);
$document->add(new Comment("<center>Oh look! You found $amount tyleans!</center>", FALSE));
}
if($random >= 51 && $random <= 99){
$item = "Bottled Honey";
$qty = rand(1,5);
$newitem = new StockItem($item);
$newitem->append($qty, $mysidia->user->username);
$itemIMG = $mysidia->db->select("items", array("imageurl"), "id = '44'")->fetchColumn();
$document->add(new Comment("<center><img src='$itemIMG' alt='$item IMG' /><br>Oh look! You found a <b>$item</b>!</center>", FALSE));
}
if($random >= 100 && $random <= 149){
$document->add(new Comment("<center>Okay, so you didn't get any items, but the totem spirits give you a hug!</center>", FALSE));
}
if($random >= 150 && $random <= 179){
$document->add(new Comment("<center>You know what you should do? Keep looking! There's good stuff out there.</center>", FALSE));
}
if($random >= 180 && $random <= 199){
$adoptIMG = $mysidia->db->select("adoptables", array("eggimage"), "id = '157'")->fetchColumn();
$document->add(new Comment("<center><img src='$adoptIMG' alt='$species IMG' /><br> Oh look! You found a $species! Grab it while you can!</center>", FALSE));
$this->pickupPet("{$species}");
}
if($random >= 200 && $random <= 249){
$document->add(new Comment("<center>Man, this place sure is quiet! Well, until you showed up. Haha, I'm kidding! Keep searching!</center>", FALSE));
}
if($random >= 250 && $random <= 299){
$item = "Black Rose";
$qty = rand(1,5);
$newitem = new StockItem($item);
$newitem->append($qty, $mysidia->user->username);
$itemIMG = $mysidia->db->select("items", array("imageurl"), "id = '15'")->fetchColumn();
$document->add(new Comment("<center><img src='$itemIMG' alt='$item IMG' /><br>Oh look! You found a <b>$item</b>!</center>", FALSE));
}
if($random >= 300 && $random <= 9999){
$document->add(new Comment("<center>You didn't find anything. Look on the bright side! Things can only get better from here, right? <br><br><a href='/exploretheruins'>Explore Again</a></center>", FALSE));
$document->add(new Comment("<br><center>You have explored <b>{$mysidia->user->exploretimes} out of 100</b> total explores today. If the number of explores is greater than 100, you won't get any reward from exploring.</center></br><br><br><img src='http://i.imgur.com/SQkjh80.png' />", FALSE));
}
elseif($random == 10000){
$item = "Cereus Unicorn Figurine";
$qty = rand(1,5);
$newitem = new StockItem($item);
$newitem->append($qty, $mysidia->user->username);
$itemIMG = $mysidia->db->select("items", array("imageurl"), "id = '32'")->fetchColumn();
$document->add(new Comment("<center><img src='$itemIMG' alt='$item IMG' /><br>Oh look! You found a <b>$item</b>! Whoa, those are so rare! Keep it!</center>", FALSE));
}
else{
$document->add(new Comment("<br><center>You have explored <b>{$mysidia->user->exploretimes} out of 100</b> total explores today. If the number of explores is greater than 100, you won't get any reward from exploring.</center></br>", FALSE));
$document->add(new Comment(" <br><center><a href='/exploretheruins'>Explore Again</a></center>", FALSE));
$document->add(new Comment(" <br><center><a href='/pages/view/exploremystfell'>Return To The Main Map</a></center>", FALSE));
$document->add(new Comment("<br><center><img src='http://i.imgur.com/SQkjh80.png'></center>", FALSE));
}
}
else{
$document->add(new Comment("<br><center>You have explored <b>{$mysidia->user->exploretimes} out of 100</b> total explores today. If the number of explores is greater than 100, you won't get any reward from exploring.</center></br>", FALSE));
$document->add(new Comment(" <br><center><a href='/exploretheruins'>Explore Again</a></center>", FALSE));
$document->add(new Comment(" <br><center><a href='/pages/view/exploremystfell'>Return To The Main Map</a></center>", FALSE));
$document->add(new Comment("<br><center><img src='http://i.imgur.com/SQkjh80.png'></center>", FALSE));
}


}

//This function generates the form
public function pickupPet($species){
$document = $this->document;
$document->add(new Comment("
<form id='pickup_pet' action='Exploretest' name='pickup_pet' method='post' role='form'>
<input id='pet_found' name='pet_found' type='hidden' value='{$species}'>
<button id='acquire' value='species' name='acquire' type='submit'>
<center>Claim the pet?</center>
</button>
</form>
", FALSE));
return;
}

// This function is called in the function that only works if there's post data
public function givePet($species){
$mysidia = Registry::get("mysidia");
$newadopt = new StockAdopt($species);
$newadopt->append($mysidia->user->username);
return;
}

}
?>

NobodysHero
02-20-2017, 10:16 PM
Abronsyth, thanks for putting it together, but that didn't work. T_T It sends me to the home screen and no pet is awarded.

Abronsyth
02-21-2017, 04:25 PM
That might be because I apparently accidentally removed where you had $species defined ^^; Oops