![]() |
Home Community Mys-Script Creative Off-Topic |
|
|
Thread Tools | Display Modes |
#1
|
||||
|
||||
![]() How to Create an Explore System
"In this tutorial we will go over how you can create an exploration system. It will start with a few basic questions and answers, and then will move onto the acutal coding and tutorial. Questions and Answers What sort of exploration system are we going to be making? We'll be making a basic system where your users can explore different locations and have different chances of finding different pets and items. What are the features of this exploration system? Here's a list:
Okay then! Tell me anything else I might need to know and then can you get on with the tutorial? Well, I use this exploration system on my own site. Also, certain bits of code(pretty much the MySQL bits) I learned from Kyttias(Seriously helpful member who has earned her premium membership many times over), but the basic idea of what I needed to do I came up with myself. Anyway, I feel like I should share this script with the community, because all the other exploration systems I have seen on here either are basically just interactive stories, not informative enough, or outdated. This script is tried and tested for Mys. 1.3.4, but not for anything else. Let me know how it works for older things! Oh yeah. I can start the tutorial now. Tutorial and Script Step One - Creating the explore pages: We need to create the explore pages before we can do anything. First, let's create the explore.php page. Put this inside: Code:
<?php class ExploreController extends AppController{ public function __construct(){ parent::__construct("member"); } public function index(){ $mysidia = Registry::get("mysidia"); } } ?> Code:
<?php class ExploreView extends View{ public function index(){ $mysidia = Registry::get("mysidia"); $document = $this->document; $document->setTitle("Explore"); $document->add(new Comment("Choose a location that you wish to explore.", FALSE)); }bl } ?> Step Two - Modifying the database We need to modify the database in order for this to work. You will need to add two columns to the adopts_users table. The first one will be named lastday. Its type will be VARCHAR(20), Collation utf8_unicode_ci, and Default 0. The second will be named exploretimes, with type INT(20). They should look something like this when you are creating them: ![]() If you want to have premium members, add a column in adopts_users_status named premium, type VARCHAR(20), Collation utf8_unicode_ci, and Default 'No'. Step Three - Creating the exploration areas For each area a user can explore, create a page called explore[put area name here].php and explore[put area name here].php. For the purpose of this tutorial, we'll just make two areas: Area 1 and Area 2. We'll create explorearea1.php and explorearea2.php. In them we'll put: Code:
<?php class Explorearea1Controller extends AppController{ public function __construct(){ parent::__construct("member"); } public function index(){ $mysidia = Registry::get("mysidia"); } } ?> Code:
<?php class Explorearea2Controller extends AppController{ public function __construct(){ parent::__construct("member"); } public function index(){ $mysidia = Registry::get("mysidia"); } } ?> Code:
<?php class Explorearea1View extends View{ public function index(){ $mysidia = Registry::get("mysidia"); $document = $this->document; $document->setTitle("Exploring Area 1"); $today = date(d); if ($mysidia->user->lastday != $today) { $mysidia->db->update("users", array("exploretimes" => (0)), "username = '{$mysidia->user->username}'"); } $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 <= 5) { $random = rand(1,100); if($random > 1 && $random < 20){ $species = "Common Species"; $newadopt = new StockAdopt($species); $newadopt->append($mysidia->user->username); $document->add(new Comment("Oh look! You found a $species! It's pretty common.", FALSE)); } elseif($random >= 21 && $random <= 30){ $amount = rand(5,20); $mysidia->user->changecash($amount); $document->add(new Comment("Oh look! You found $amount cash!", FALSE)); } elseif($random >= 31 && $random <= 40){ $item = "Item"; $qty = 1; $newitem = new StockItem($item); $newitem->append($qty, $mysidia->user->username); $document->add(new Comment("Oh look! You found a <b>$item</b>!", FALSE)); } if($random >= 41 && $random <= 60){ $species = "Another Common Species"; $newadopt = new StockAdopt($species); $newadopt->append($mysidia->user->username); $document->add(new Comment("Oh look! You found a $species! It's pretty common.", FALSE)); } if($random >= 61 && $random <= 70){ $species = "Uncommon Species"; $newadopt = new StockAdopt($species); $newadopt->append($mysidia->user->username); $document->add(new Comment("Oh look! You found a $species! It's uncommon.", FALSE)); } if($random >= 71 && $random <= 75){ $species = "Rare Species"; $newadopt = new StockAdopt($species); $newadopt->append($mysidia->user->username); $document->add(new Comment("Oh look! You found a $species! It's rare and hard to find.", FALSE)); } if($random >= 76 && $random <= 80){ $item = "Item"; $qty = 1; $newitem = new StockItem($item); $newitem->append($qty, $mysidia->user->username); $document->add(new Comment("Oh look! You found a <b>$item</b>!", FALSE)); } if($random >= 81 && $random <= 90){ $item = "Rock"; $qty = 1; $newitem = new StockItem($item); $newitem->append($qty, $mysidia->user->username); $document->add(new Comment("Oh look! You found a <b>$item</b>!", FALSE)); } if($random >= 91 && $random <= 99){ $document->add(new Comment("You didn't find anything. Better luck next time.", FALSE)); } elseif($random == 100){ $species = "Very Rare Species"; $newadopt = new StockAdopt($species); $newadopt->append($mysidia->user->username); $document->add(new Comment("Oh look! You found a$species! Wow, it's really rare.", FALSE)); } else{ $document->add(new Comment("Oops! Something went wrong.", FALSE)); } } else{ $document->add(new Comment("It seems you have explored too much today, why don't you take a rest?", FALSE)); } } } ?> Step Four - Choosing the chances and types of pets and items You probably want to decide how often a pet or item or currency pops up. You also probably wish to decide which pets or items can be found. So, I'll show you the code for obtaining a pet: Code:
if($random >= 41 && $random <= 60){ $species = "Another Common Species"; $newadopt = new StockAdopt($species); $newadopt->append($mysidia->user->username); $document->add(new Comment("Oh look! You found a $species! It's pretty common.", FALSE)); } Code:
if($random >= 81 && $random <= 90){ $item = "Rock"; $qty = 1; $newitem = new StockItem($item); $newitem->append($qty, $mysidia->user->username); $document->add(new Comment("Oh look! You found a <b>$item</b>!", FALSE)); } Code:
elseif($random >= 21 && $random <= 30){ $amount = rand(5,20); $mysidia->user->changecash($amount); $document->add(new Comment("Oh look! You found $amount cash!", FALSE)); } Code:
if($random >= 91 && $random <= 99){ $document->add(new Comment("You didn't find anything. Better luck next time.", FALSE)); } Step Five - Restrictions Here's how to input a restriction: Right after the $document->setTitle(""); line, put the first part of the restriction code. Then, right after the else{ $document->add(new Comment("It seems you have explored too much today, why don't you take a rest?", FALSE)); } lines, paste the second part of the restriction code. Item Restriction: This will only let a user explore in that area if they have a specific item. First Part: Code:
$item = "[put item name here]"; $hasitem = $mysidia->db->select("inventory", array("quantity"), "itemname ='{$item}' and owner='{$mysidia->user->username}'")->fetchColumn(); if($hasitem){ Code:
} else{ $document->add(new Comment("[put text here]", FALSE)); } First Part: Code:
if($mysidia->user->status->premium == "yes"){ Code:
else{ $document->add(new Comment("Whoops, looks like you aren't a premium member. Only premium members can explore here.", FALSE)); } Sixth Part: Links and/or image maps Now you need to go back to the exploreview.php file and add this right after the $document->add(new Comment("Choose a location that you wish to explore.", FALSE)); line: Code:
$document->add(new Comment("")); Now save everything and visit yoursite.com/explore and look around! You've coded an explore system! Let me know if you have any issues with this. Let me know if this was helpful! Thank you and you're welcome!
__________________
The Cave of Crystals
site coming soon! - buzz thread Last edited by cailynmae; 04-21-2015 at 12:24 PM. |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Quest- Explore System (Open Source) | squiggler | Tutorials and Tips | 4 | 07-23-2020 12:07 PM |
How to create an image map | collierox | Tutorials and Tips | 3 | 03-13-2018 04:11 AM |
Explore Help? | cailynmae | Questions and Supports | 7 | 03-29-2017 11:37 PM |
Help Create This? | Abronsyth | Templates and Themes | 16 | 10-24-2011 03:05 PM |
How to create a a battle system ,shop and currency?? | SieghartZeke | Questions and Supports | 9 | 11-02-2009 12:15 AM |
What's New? |
What's Hot? |
What's Popular? |