1.3.6 Quest Page!!

Forum
Last Post
Threads / Messages

dlithehil

Member
Member
Joined
Jun 10, 2022
Messages
83
Points
18
Mysidian Dollar
699
I didn't see a tutorial for a quest page ANYWHERE, so I decided to make one myself. This took FOREVER, so I hope it works for you!

First things first, let's create a couple new columns in the database, namely questsdone and questday under [prefix]_users.
You want both to be set to int with the length set to 100 and with a default value of 0. (You don't technically need a length of 100 for questday, but you need at least 2. I'd go higher to be on the safe side though.) Here's an example of questsdone, but you set up both the same way.
1725642446506.png

Next, we need to set up a new file called questscontroller.php under controller/main. (You can name it anything, but it will be found at yourURL/quests in my example.)
It should look like this.
PHP:
<?php

namespace Controller\Main;
use Resource\Core\AppController;
use Resource\Core\Registry;

class QuestsController extends AppController{
//You need to name the controller the same name as your file, but make sure the first word and "controller" are both capitalized where it says
//"class QuestsController"
    public function __construct(){
        //This means only members can access the page.
        parent::__construct("member"); 
    }
  
    public function index(){
        $mysidia = Registry::get("mysidia");
    }
}

Now we need to set up the other half of the webpage. Go to view/main and make a file called questsview.php. If you used a different name, make sure this file matches. Begin by adding this code.
PHP:
<?php

namespace View\Main;
use Resource\Core\Registry;
use Resource\Core\View;
use Resource\Core\Model;
//I'm not going to lie, I just covered all my bases with the "use" things below.
//They allow you to call certain variables, and make different containers or components.
use Model\DomainModel\Member;
use Model\DomainModel\User;
use Model\DomainModel\UserProfile;
use Model\DomainModel\Adoptable;
use Model\DomainModel\OwnedAdoptable;
use Model\DomainModel\Item;
use Model\DomainModel\OwnedItem;
use Resource\GUI\Document\Comment;
use Resource\GUI\Component\Link;
use Resource\GUI\Component\Image;
use Resource\GUI\Container\Form;
use Resource\GUI\Component\Button;


class QuestsView extends View{
//Make sure, yet again, that the first word and "View" are both capitalized.
//Also make sure it matches your filename.
    public function index(){
        $mysidia = Registry::get("mysidia");
        $document = $this->document;
        $document->setTitle("Quest Board");
        //Title the page whatever you like. This will be the header for the page.
    }
}

I will finish this in a reply when I get out of class!
 
Last edited:
Okay. There's two types of quests I have figured out how to do: fetch quests for items (will consume the item), and pet level quests (basically your fav pet has to reach a certain level and then you're rewarded.) I tend to give money for fetch quests and items for level quests, but that's just my preference. You could totally trade an item for an item or whatever you'd like.

We're going to start with adding a way to get and set our questsdone and questday in the model/domainmodel/user.php file.
Put these with the other protected variables:
PHP:
protected $questsDone;
protected $questDay;
And I don't really understand each function of this part but you need to put this under all the getThing() functions but before public function __toString()
PHP:
public function getQuestsDone(){
  return $this->questsdone;
}
public function setQuestsDone($quests, $assignMode=""){
   if($assignMode == Model::UPDATE) $this->save("questsdone", $quests);
   $this->questsdone = $quests;
}
public function getQuestDay(){
    return $this->questday;
}
public function setQuestDay($today, $assignMode=""){
    if($assignMode == Model::UPDATE) $this->save("questday", $today);
    $this->questday = $today;
}

Okay, on to what I understand...
Inside the public function index() we need to define a few variables.
PHP:
$profile = $mysidia->user->getID();
$mysidia->user->getID();
$questsdone = $mysidia->user->getQuestsDone();
$mysidia->user->getQuestsDone();
//If you would like users to be able to complete as many quests as they would like in a single day, ignore the following three variables.
$today = date('d');
$lastday = $mysidia->user->questday;
//$next is completely optional and is used if you would like more than one day between when quests can be completed.
$next = $today - $lastday;

Then, we make the quest. Under all our variables, we are going to have an if statement with an else statement following it.
PHP:
if($questsdone == 0){
    //This makes sure that this is the first quest they see.
} else{
    //If they've already completed quests, aka questsdone does not equal 0, it'll run this script instead.
}
The else statement is the easiest so let's do that first.
PHP:
else {
    $document->add(new Comment("Put a message here to tell them they have already completed the quests or have to wait before completing the next."));
    //Don't be me and forget the ; at the end.
}

Now on to the if statement. Inside the {curly brackets} of the if statement, put the following code:
PHP:
//------------ Berry Fetch Quest ------------------------
$document->add(new Comment("Heya! I was wondering if you could find me 3 berries. Not the strawberries. Those are gross... I just don't like going foraging. I have some gold to spare."));
//----------The Confirmation Button Itself----------
//--------Make sure to add your quest page/the random string for your quest confirmation for the location spot-------------------
//I used a random string so that people can't skip to future quests without completing the quest they're on first.
$berryForm = new Form ("berries", "quests/hRlp31F", "post");
//I'm not sure what the first "berries" does, but the second set of " " is the url that will go after the slash of yourURL.com/ 
//So if you want to make a separate page, leave out the [I]quests/[/I] but if you would like to just have subpages and not overflow your view folder, 
//make sure to add that [I]quests/[/I] before your string.
$berryForm->add(new Button("Give Berries", "submit"));
$document->add($berryForm);
// Don't be me and forget to add the form and then wonder why the heck the button is gone...
//--------Quest continued on sub-page --------------------------

To add the subpage, we first need to go back to controller/main/questscontroller.php Under the public function index() add the following code:
Code:
//Make sure the string after "function" matches the string you set for your form/button link.
public function hRlp31F(){
        $mysidia = Registry::get("mysidia");
}

Now, back to view/main/questsview.php This part is long. I apologize in advance.
PHP:
public function hRlp31F(){
//------Berry Fetch Quest--------
$mysidia = Registry::get("mysidia");
$document = $this->document;
$document->setTitle("Quest Board");
$profile = $mysidia->user->getID();
$mysidia->user->getID();
$questsdone = $mysidia->user->getQuestsDone();
$mysidia->user->getQuestsDone();
$today = date('d');
//------------- Selects Item: change the '2' to the item id of the item they are to fetch ------------------------
//You can find the item id in the [prefix]_item database.
$item = new OwnedItem(2, $profile);
//----------Counts the number of item on a given profile ----------------
$berries = $item->getQuantity($profile);
//------Now we need to make sure they have the correct number of berries.
if($berries >= 3){
    $document->add(new Comment("Thank you so much! Here's your reward!"));
    $item->remove(3, $profile);
    $mysidia->user->changeMoney(50);
    $mysidia->user->setQuestsDone(1, "update");
    $mysidia->user->setQuestDay($today, "update");
} elseif( $questsdone != 0){
    // -------- If they come back again, they can't re-complete it-----------
    $document->add(new Comment("You have already completed this quest."));
} else {
    //------ Not enough berries ----------------
    $document->add(new Comment("You don't have enough berries yet..."));
}
 
Let's add a second quest. This time an adoptable leveling quest. This one doesn't even need a subpage!
In view/main/questsview.php under public function index() there should be your if/else statement. After if($questsdone == 0){ [...] } but before else{ [...] } put the following code (make sure it's after the if's closing } ).
PHP:
//This checks both that they've only completed one quest. It also checks that the day they completed the last quest is at least two days before.
elseif ($questsdone == 1 && ($next >1 || $next < 0)){
    //---------Checks if they have a favorite pet assigned ------------
    $favpet = $profile->getFavpet();
    if($favpet == 0){
        //------No Pet Assigned. Replace the url with your manage profile url -----------
        $document->add(new Comment("Aww. You don't have a pet with you. Assign one as your favorite pet <a href='https://adopts.ashenblade.click/account/profile'>here</a> if you want your quest."));
    } elseif ($favpet->getCurrentLevel() < 5){
        // ------- Pet is too small -----------
        $document->add(new Comment("Your pet is so cute! You said their name is {$favpet->getName()}? Absolutely adorable!<br>"));
        $document->add(new Comment("If you can raise their level to 5, I'll give you and them a present."));
    } elseif ($questsdone != 2){
        //--------- Already Completed -------------
        $document-add(new Comment("You have already completed this quest"));
    } else {
        //-------Success-----------------
        $document->add(new Comment("They've gotten so big!!! Take some gummies for them and some gold for you!"));
        $mysidia->user->changeMoney(25);
        $mysidia->user->setQuestsDone(2, "update");
        $mysidia->user->setQuestDay($today, "update");
    }
}
//Your "else" would go immediately after the last }

And that's it! Add as many elseif scripts as you would like before the else. Just make sure the $questsdone is equal to one less than the number quest you're on!
 
You can also spiff things up by putting
PHP:
$document->add(new Image("https://f2.toyhou.se/file/f2-toyhou-se/images/48099834_6UANYYh43BEs4OU.png", "Alt Name for Screenreaders"));
//Replace the image URL. That's my character...
 
And here's the full code I made:
  Spoiler: questsview.php 
PHP:
<?php

namespace View\Main;
use Resource\Core\Registry;
use Resource\Core\View;
use Resource\Core\Model;
use Model\DomainModel\Member;
use Model\DomainModel\User;
use Model\DomainModel\UserProfile;
use Model\DomainModel\Adoptable;
use Model\DomainModel\OwnedAdoptable;
use Model\DomainModel\Item;
use Model\DomainModel\OwnedItem;
use Resource\GUI\Document\Comment;
use Resource\GUI\Component\Link;
use Resource\GUI\Component\Image;
use Resource\GUI\Container\Form;
use Resource\GUI\Component\Button;


class QuestsView extends View{
    
    public function index(){
        $mysidia = Registry::get("mysidia");
        $document = $this->document;
        $document->setTitle("Quest Board");
        $document->add(new Comment("Welcome to the quest board. When there's someone who needs someone to help them with something, they come here. They usually offer compensation, too.<br><br>"));
        
        $profile = $mysidia->user->getID();
        $mysidia->user->getID();
        $questsdone = $mysidia->user->getQuestsDone();
        $mysidia->user->getQuestsDone();
        $today = date('d');
        $lastday = $mysidia->user->questday;
        $next = $today - $lastday;
        
        
        if($questsdone == 0 ){
            //------------ Berry Fetch Quest ------------------------
            $document->add(new Comment("Heya! I was wondering if you could find me 3 berries. Not the strawberries. Those are gross... I just don't like going foraging. I have some gold to spare."));
            //----------The Confirmation Button Itself----------
            //--------Make sure to add your quest page/the random string for your quest confirmation for the location spot-------------------
            $berryForm = new Form ("berries", "quests/hRlp31F", "post");
            $berryForm->add(new Button("Give Berries", "sumbmit"));
            $document->add($berryForm);
            //--------Quest continued on sub-page --------------------------
            
            
            //--------Pet Level Quest---------------
        }  elseif ($questsdone == 1 && ($next >1 || $next < 0)){
            //---------Checks if they have a favorite pet assigned ------------
            $favpet = $profile->getFavpet();
            if($favpet == 0){
                //------No Pet Assigned. Replace the url with your manage profile url -----------
                $document->add(new Comment("Aww. You don't have a pet with you. Assign one as your favorite pet <a href='https://adopts.ashenblade.click/account/profile'>here</a> if you want your quest."));
            } elseif ($favpet->getCurrentLevel() < 5){
                // ------- Pet is too small -----------
                $document->add(new Comment("Your pet is so cute! You said their name is {$favpet->getName()}? Absolutely adorable!<br>"));
                $document->add(new Comment("If you can raise their level to 5, I'll give you and them a present."));
            } elseif ($questsdone != 2){
                //--------- Already Completed -------------
                $document-add(new Comment("You have already completed this quest"));
            }         
            else {
                //-------Success-----------------
                $document->add(new Comment("They've gotten so big!!! Take some gummies for them and some gold for you!"));
                $mysidia->user->changeMoney(25);
                $mysidia->user->setQuestsDone(2, "update");
                $mysidia->user->setQuestDay($today, "update");
            }
        
        
        
            
        }       /* Add your elseif($questsdone == 1 && $next > 1) or whatever number of quests done below here. You need to keep $next greater than however many days you want them to wait minus 1*/
        
        //------If all quests are completed (aka quests done = the number of quests) or you're waiting for the days to pass ---------------------
        else { $document->add(new Comment("<center>You've completed all the quests we have right now! Check back later. </center><br>
            <span style='font-size:10px;'>(If you haven't completed all the quests we have to offer, you can do a new quest 2 days after your last <em>completed</em> quest.If you wait exactly one month after completing a quest, it will show as the same day of the month, and show this message. Just wait a couple days)"));
            
        }
    }
    //----------Random URLs to keep people from skipping to random quests-------------
    public function hRlp31F(){
        //------Berry Fetch Quest--------
        $mysidia = Registry::get("mysidia");
        $document = $this->document;
        $document->setTitle("Quest Board");
        $profile = $mysidia->user->getID();
        $mysidia->user->getID();
        $questsdone = $mysidia->user->getQuestsDone();
        $mysidia->user->getQuestsDone();
        $today = date('d');
        
        //------------- Selects Item: change the '2' to the item id of the item they are to fetch ------------------------
        $item = new OwnedItem(2, $profile);
        //----------Counts the number of item on a given profile ----------------
        $berries = $item->getQuantity($profile);
            
        //------Now we need to make sure they have the correct number of berries.
        if($berries >= 3){
            $document->add(new Comment("Thank you so much! Here's your reward!"));
            $item->remove(3, $profile);
            $mysidia->user->changeMoney(50);
            $mysidia->user->setQuestsDone(1, "update");
            $mysidia->user->setQuestDay($today, "update");
        } elseif( $questsdone != 0){
            // -------- If they come back again, they can't re-complete it-----------
            $document->add(new Comment("You have already completed this quest."));
        } else {
            //------ Not enough berries ----------------
            $document->add(new Comment("You don't have enough berries yet..."));
        }
    }
}


  Spoiler: questscontroller.php 

PHP:
<?php

namespace Controller\Main;
use Resource\Core\AppController;
use Resource\Core\Registry;

class QuestsController extends AppController{

    public function __construct(){
        parent::__construct("member");   
    }
    
    public function index(){
        $mysidia = Registry::get("mysidia");
    }
    
    //-----Berry Fetch Quest---------
    public function hRlp31F(){
        $mysidia = Registry::get("mysidia");
    }
}
 
Thank you for this!! It's really appreciated :) Its nice to see something new offered, its been soooooooo quiet here!
 
Thank you for this!! It's really appreciated :) Its nice to see something new offered, its been soooooooo quiet here!
Yeah. I was scouring for ages trying to find a quest system in literally any 3.x server but to no avail. Let me know if it doesn't work. I think I goofed in a place or two, but I have it fixed on my site. Idk where the discrepancies are, but if you find one, I'll edit the post to fix it!
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,295
Messages
33,186
Members
1,606
Latest member
kandriamage
BETA

Latest Threads

Latest Posts

Top