limit adopted eggs

Forum
Last Post
Threads / Messages

kristhasirah

Member
Member
Joined
Jan 22, 2010
Messages
197
Points
16
Location
In middle of the nothingness
Mysidian Dollar
20,995
need help converting this code from ver. 1.3.2 to 1.3.4
already tried to change the code but cant make it work.

PHP:
else
{
$stmt = $mysidia->db->select("owned_adoptables", array(), constant("PREFIX")."owned_adoptables.owner = '{$mysidia->user->username}'");
$count = 0;
while($adopt = $stmt->fetchObject())
{
if($adopt->currentlevel <= 6) { $count++;}
}
if($count >= 5)
{
$mysidia->page->settitle("Too many eggs");
$mysidia->page->addcontent("You've got too many eggs and should wait until you've hatched one.");
}
 
The way of writing the database query has changed, as well as setting a document's title and contents. I'll try to take a look at it a bit later.

From what I can make of it, you're trying to prevent a user from adopting any more pets if they already own so many pets under a certain level?
 
Alright, inside adoptview.php, find this function:

PHP:
if($mysidia->input->post("submit")){ 
     /* The current contents of this function... */ 
}

You'll be placing the current contents of this function inside an else statement.

PHP:
if($mysidia->input->post("submit")){
	$number = 5; /* You want users to have no more than THIS ($number) many pets with...*/
	$level = 6; /* ...a level less than or equal to THIS ($level) number! */
	$petsAtLevel = $mysidia->db->select("owned_adoptables", array(), "owner = '{$mysidia->user->username}' AND currentlevel <= $level")->rowCount();
	if ($petsAtLevel > $number){ /* If the number of pets at this level is greater than number... */
		$document->setTitle("Too Many Eggs!");
		$document->add(new Comment("You've got too many eggs and should wait until you've hatched one.", FALSE));
	}
	else { 
		/* Else show the previously existing contents of input->post("submit") and let users adopt things... */			
	}
}

Try this for me and see if it works as intended? Make sure the old contents of the function get pasted inside the else statement.

When a person goes to try to adopt a new pet now, the error will display instead.

However, the bottom of this file also contains the button that will send the form. You might consider wrapping it in an if statement and removing access to it entirely when the user has too many low level pets/eggs and replacing it with a memo instructing them to go level things up instead.
 
Last edited:
Umm... I've tried that.

but I got both. The comment, I've too many eggs AND "Congratulations...you just adopt..."

:ohnoes:

Is it possible to get this function for the adopt-shop too ?
 
Last edited:
yes im trying to prevent users from adopting more eggs...
I think im doing something wrong because i only get a blank page when i click the submit botton... and when i look at my owned adopts the adopt is there...

PHP:
<?php

class AdoptView extends View{
	
	public function index(){
	    $mysidia = Registry::get("mysidia");
		$document = $this->document;
 		
	    if($mysidia->input->post("submit")){
    $number = 5; /* You want users to have no more than THIS ($number) many pets with...*/
    $level = 6; /* ...a level less than or equal to THIS ($level) number! */
    $petsAtLevel = $mysidia->db->select("owned_adoptables", array(), "owner = '{$mysidia->user->username}' AND currentlevel <= $level")->rowCount();
    if ($petsAtLevel > $number){ /* If the number of pets at this level is greater than number... */
        $document->setTitle("Too Many Eggs!");
        $document->add(new Comment("You've got too many eggs and should wait until you've hatched one.", FALSE));
    }
    else { 
	    
		    $aid = $this->getField("aid")->getValue();
			$name = $this->getField("name")->getValue();
			$eggImage = $this->getField("eggImage")->getValue();
			$image = new Image($eggImage);
			$image->setLineBreak(TRUE);	
			
            $document->setTitle("{$name} adopted successfully");			
			$document->add($image);
			$document->addLangvar("Congratulations!  You just adopted {$name}.  You can now manage {$name} on the ");
			$document->add(new Link("myadopts", "Myadopts Page."));
			$document->add(new Comment(""));
			$document->add(new Link("myadopts/manage/{$aid}", "Click Here to Manage {$name}"));
			$document->add(new Comment(""));
			$document->add(new Link("myadopts/bbcode/{$aid}", "Click Here to get BBCodes/HTML Codes for {$name}"));
			$document->add(new Comment(""));
			$document->addLangvar("Be sure and");
			$document->add(new Link("levelup/click/{$aid}", "feed "));
			$document->addLangvar("{$name} with clicks so that they grow!");
		    return;
		}
}
		$document->setTitle($mysidia->lang->title);
        $document->addLangvar((!$mysidia->user->isloggedin)?$mysidia->lang->guest:$mysidia->lang->member); 

		
        $adoptForm = new Form("form", "adopt", "post");
		$adoptTitle = new Comment("Available Adoptables");
		$adoptTitle->setHeading(3);
		$adoptForm->add($adoptTitle);
		$adoptTable = new Table("table", "", FALSE);
 		
		$adopts = $this->getField("adopts");
		for($i = 0; $i < $adopts->length(); $i++){
		    $row = new TRow;
		    $idCell = new TCell(new RadioButton("", "id", $adopts[$i]->getID()));				
			$imageCell = new TCell(new Image($adopts[$i]->getEggImage(), $adopts[$i]->getType()));
			$imageCell->setAlign(new Align("center"));
				
			$type = new Comment($adopts[$i]->getType());
			$type->setBold();
            $description = new Comment($adopts[$i]->getDescription(), FALSE);
			$typeCell = new TCell;
            $typeCell->add($type);
            $typeCell->add($description);			

		    $row->add($idCell);
			$row->add($imageCell);
			$row->add($typeCell);
            $adoptTable->add($row);
		}
		
		$adoptForm->add($adoptTable);		
		$adoptSubtitle = new Comment("Adopt");
		$adoptSubtitle->setHeading(3);
		$adoptForm->add($adoptSubtitle);
		$adoptForm->add(new Comment("Adoptable Name: ", FALSE));
		$adoptForm->add(new TextField("name"));
		$adoptForm->add(new Comment(""));
        $adoptForm->add(new Button("Create this Adoptable", "submit", "submit"));
        $document->add($adoptForm);
	}
}

?>

no idea what im doing wrong... and im have 0 experience at coding... only know how to install mods and make small changes... so no idea how to do the wrapping of if statement for the submit botton...
 
Alright, let's just not display any pets here at all if the user has too many eggs, then? It'd just be teasing them, anyway.

Here's the whole document now:
PHP:
<?php

class AdoptView extends View{
	
	public function index(){
	    $mysidia = Registry::get("mysidia");
		$document = $this->document;

		$number = 5; /* You want users to have no more than THIS ($number) many pets with...*/
	    $level = 6; /* ...a level less than or equal to THIS ($level) number! */
	    $petsAtLevel = $mysidia->db->select("owned_adoptables", array(), "owner = '{$mysidia->user->username}' AND currentlevel <= $level")->rowCount();
	    if ($petsAtLevel > $number){ /* If the number of pets at this level is greater than number... */
	    	$document->setTitle("Too Many Eggs!");
	        $document->add(new Comment("You've got too many eggs and should wait until you've hatched one.", FALSE));
	    }
	    else { /* Else show existing things... */   
		
		    if($mysidia->input->post("submit")){
			    $aid = $this->getField("aid")->getValue();
				$name = $this->getField("name")->getValue();
				$eggImage = $this->getField("eggImage")->getValue();
				$image = new Image($eggImage);
				$image->setLineBreak(TRUE);	
				
	            $document->setTitle("{$name} adopted successfully");			
				$document->add($image);
				$document->addLangvar("Congratulations!  You just adopted {$name}.  You can now manage {$name} on the ");
				$document->add(new Link("myadopts", "Myadopts Page."));
				$document->add(new Comment(""));
				$document->add(new Link("myadopts/manage/{$aid}", "Click Here to Manage {$name}"));
				$document->add(new Comment(""));
				$document->add(new Link("myadopts/bbcode/{$aid}", "Click Here to get BBCodes/HTML Codes for {$name}"));
				$document->add(new Comment(""));
				$document->addLangvar("Be sure and");
				$document->add(new Link("levelup/{$aid}", "feed "));
				$document->addLangvar("{$name} with clicks so that they grow!");
			    return;
			}
			
			$document->setTitle($mysidia->lang->title);
	        $document->addLangvar((!$mysidia->user->isloggedin)?$mysidia->lang->guest:$mysidia->lang->member);  		
	        $adoptForm = new Form("form", "adopt", "post");
			$adoptTitle = new Comment("Available Adoptables");
			$adoptTitle->setHeading(3);
			$adoptForm->add($adoptTitle);
			$adoptTable = new Table("table", "", FALSE);
	 		
			$adopts = $this->getField("adopts");
			for($i = 0; $i < $adopts->length(); $i++){
			    $row = new TRow;
			    $idCell = new TCell(new RadioButton("", "id", $adopts[$i]->getID()));				
				$imageCell = new TCell(new Image($adopts[$i]->getEggImage(), $adopts[$i]->getType()));
				$imageCell->setAlign(new Align("center"));
					
				$type = new Comment($adopts[$i]->getType());
				$type->setBold();
	            $description = new Comment($adopts[$i]->getDescription(), FALSE);
				$typeCell = new TCell;
	            $typeCell->add($type);
	            $typeCell->add($description);			

			    $row->add($idCell);
				$row->add($imageCell);
				$row->add($typeCell);
	            $adoptTable->add($row);
			}
			
			$adoptForm->add($adoptTable);		
			$adoptSubtitle = new Comment("Adopt");
			$adoptSubtitle->setHeading(3);
			$adoptForm->add($adoptSubtitle);
			$adoptForm->add(new Comment("Adoptable Name: ", FALSE));
			$adoptForm->add(new TextField("name"));
			$adoptForm->add(new Comment(""));
	        $adoptForm->add(new Button("Adopt Me", "submit", "submit"));
	        $document->add($adoptForm);
	    }
	}
}
?>

@draugluin - As for the adopt shop, it's not a feature I'm making use of on my site so I wouldn't know how to make modifications there without creating one... If this is a feature to prevent new players from hoarding pets without patience, it's unlikely these new players will have enough funds to even purchase more eggs from a shop. And if they have money, why not let them, anyway? If you still really want this, classes/class_adoptshop.php, the display() function can be changed:

PHP:
public function display(){
    $mysidia = Registry::get("mysidia");	  
    $document = $mysidia->frame->getDocument();			  
    $document->addLangvar($mysidia->lang->select_adopt);
    if($this->gettotal() == 0){
        $document->addLangvar($mysidia->lang->empty);
	    return;
    }	 

    $number = 5; /* You want users to have no more than THIS ($number) many pets with...*/
    $level = 6; /* ...a level less than or equal to THIS ($level) number! */
    $petsAtLevel = $mysidia->db->select("owned_adoptables", array(), "owner = '{$mysidia->user->username}' AND currentlevel <= $level")->rowCount();
    if ($petsAtLevel > $number){ /* If the number of pets at this level is greater than number... */
    	$document->setTitle("Too Many Eggs!");
        $document->add(new Comment("You've got too many eggs and should wait until you've hatched one.", FALSE));
    }
    else { /* Else show existing things... */   
	  
        $adoptList = new TableBuilder("shop");
	    $adoptList->setAlign(new Align("center", "middle"));
        $adoptList->buildHeaders("Image", "Class", "Type", "Description", "Price", "Buy");	
	    $adoptList->setHelper(new ShopTableHelper);	  
        $this->adopts = $this->getadopttypes();
	  
	    foreach($this->adopts as $stockadopt){
	        $adopt = $this->getadopt($stockadopt->type);
		    $cells = new LinkedList;
	        $cells->add(new TCell($this->getadoptimage($adopt->eggimage)));
		    $cells->add(new TCell($adopt->class));
		    $cells->add(new TCell($adopt->type));
		    $cells->add(new TCell($adopt->description));
		    $cells->add(new TCell($adopt->cost));
		    $cells->add(new TCell($adoptList->getHelper()->getAdoptPurchaseForm($this, $adopt)));
		    $adoptList->buildRow($cells);
	    }	  
	    $document->add($adoptList);  	  
	}
}

Try that and let me know how it's working? :ooo:
 
Last edited:
Yay! Great, I'm glad things worked out. :meow:

Though this is completely unrelated, I think you might be able to learn a lot, coding-wise, if you read through this post I made while helping someone else -- I explained a lot of what I've come to understand about the framework (at least v1.3.4) so far here, including some basic explanation of object-oriented stuffs.
 
Yay! Great, I'm glad things worked out. :meow:

Though this is completely unrelated, I think you might be able to learn a lot, coding-wise, if you read through this post I made while helping someone else -- I explained a lot of what I've come to understand about the framework (at least v1.3.4) so far here, including some basic explanation of object-oriented stuffs.

I am glad you were able to find out how to use some of the APIs despite very poor to nonexistent documentation so far. I apologize for this, in Mys v1.4.x the documentation will be rich and very helpful. If you have any questions regarding the framework, lemme know and I will be able to answer on AIM when I get a chance.
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,122
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Top