PDA

View Full Version : Simple quests


Dinocanid
11-05-2016, 02:33 PM
-What we will do-
Create a simple item quest in which you get an item from an npc and give it to another npc; getting currency in return. Afterwards, this can be used to create more complex quests.

-Step 0-
Create an item to use in the quest. I recommend that it's a key item that can't be bought, traded, or consumed. This way, users can't give quest items to each other or buy them from a shop. What you name it and everything else is up to you. In order for this to work properly, you should have custom pages for your npcs. If you don't know how to make a page from scratch, go here:
http://www.mysidiaadoptables.com/forum/showpost.php?p=32248&postcount=2
If you don't use custom-made pages, this can only be used on pages that have a .php file and a view.php file. So no pages made in the adminCP.

-Step 1-
Where is your first npc located? In which view file? Wherever they are, go to that view file and add this under the npc's image:
$item = "ItemName";
$hasitem = $mysidia->db->select("inventory", array("quantity"), "itemname ='{$item}' and owner='{$mysidia->user->username}'")->fetchColumn();
if($hasitem > 0){
$document->add(new Comment("You're on this quest already!"));
}
else{
$document->add(new Comment("Please deliver this to Name"));
$document->add(new Comment("<font size='3'>You received 1 {$item}!</font>"));
$newitem = new StockItem($item);
$newitem->append(1, $mysidia->user->username);
}
What this does is check if the user has the quest item already. If they do, the user won't be given one. If they don't the user will be given the item to deliver. This makes sure the user only has one of the item.

-Step 2-
Go to your next npc. They should be on a different page (and view file) from the first one. Right under their image, put this code:
$item = "ItemName";
$hasitem = $mysidia->db->select("inventory", array("quantity"), "itemname ='{$item}' and owner='{$mysidia->user->username}'")->fetchColumn();
if($hasitem){
$document->add(new Comment("<br></br>You have $hasitem {$item}! Why not hand it over?"));
if($mysidia->input->post("submit")){
$qty = 1;
$item = new PrivateItem($item, $mysidia->user->username);
$amount = rand(10,20);
$mysidia->user->changecash($amount);
$item->remove($qty, $mysidia->user->username);
$document->add(new Comment('"Thanks!"', FALSE));
$document->add(new Comment("<br></br><font size='3'>You earned $ {$amount}!</font>", FALSE));
return;}
$questForm = new FormBuilder("questform", "", "post");
$questForm->buildButton("Give item", "submit", "submit");
$document->add($questForm);
}
This is the part that takes the quest item from the user and gives currency in return. Where it says $amount = rand(10,20);, it gives the user a random amount of currency between 10 and 20. You can change this to whatever amount you want, or you could change it to $amount = + 10; if you wanted it to not be random (change 10 to whatever you like).

-End-
That's it! You should now have a simple system for quests. Please let me know if you get any errors, but it shouldn't cause any.
Here's what it looks like on my site:
http://i.imgur.com/DBAVAAL.gif

lotus
11-11-2016, 09:52 AM
It works perfectly! Thanks!