Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Tutorials and Tips

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 04-21-2015, 12:07 PM
cailynmae's Avatar
cailynmae cailynmae is offline
Explorer of Imaginea
 
Join Date: Mar 2015
Posts: 17
Gender: Unknown/Other
Credits: 6,586
cailynmae is on a distinguished road
Default How To Create an Explore System in Mys. 1.3.4

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:
  • Exploring different areas
  • Chances of finding certain pets, items, amounts of currency, or nothing
  • Allowing a user to explore a certain area only if they have a certain item
  • Allowing a user to explore a certain area only if they have a premium membership
  • Allowing a user to explore a certain area only if they are in a certain usergroup
  • Allowing a user to explore an area a certain number of times each day
  • And maybe more that I have forgotten about


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");
	}
}
?>
Now, go to the view folder and create the exploreview.php page. Put this in it:
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
    
}
?>
We'll come back to this page later.

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");
	}
}
?>
in explorearea1.php, and
Code:
<?php

class Explorearea2Controller extends AppController{

    public function __construct(){
        parent::__construct("member");	
    }
	
	public function index(){
		$mysidia = Registry::get("mysidia");
	}
}
?>
in explorearea2.php. Next, we'll create explorearea1view.php and explorearea2view.php. First we'll put
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));
		}   

	}

}
?>
in explorearea1.php. We'll put the same in explorearea2.php, but instead we'll replace class Explorearea1View extends View{ with class Explorearea2View extends View{, and $document->setTitle("Exploring Area 1"); with $document->setTitle("Exploring Area 2");.

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));
			}
This bit determines the rarity out of a hundred: if($random >= 41 && $random <= 60){. This means that if the random number picked is in between 41 and 60, it will give the user that pet. It also means it has a 1 in 5 chance of getting picked. You can change the two numbers to grow or shrink the range. $species determines which species will be found, and $document->add(new Comment("Oh look! You found a $species! It's pretty common.", FALSE)); can be modified to determine what the page says.
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));
			}
This is the code for obtaining an item. Everything is as before, except you change $item to determine which item is given, and $qty to determine how much of that item is given.
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)); 
			}
This is the code for giving a user some currency. Everything is as before, except you change $amount to determine the amount of currency that is given.
Code:
			if($random >= 91 && $random <= 99){
				$document->add(new Comment("You didn't find anything. Better luck next time.", FALSE));
			}
This is the code for finding nothing. Poor explorer.

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){
Second Part:
Code:
}
		else{
        		$document->add(new Comment("[put text here]", FALSE));
		}
Premium Restriction: This will only let a user explore in a certain area if they have a premium membership. NOTE: This only works if you followed the second part of the database modifications I mentioned above.
First Part:
Code:
		if($mysidia->user->status->premium == "yes"){
Second Part:
Code:
		else{
			$document->add(new Comment("Whoops, looks like you aren't a premium member. Only premium members can explore here.", FALSE));
		}
More restrictions may come soon!


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(""));
Inside the quotes add the code for your form of links to the different area pages. For example, Area 1, or area1.php, would need something that linked to yoursite.com/area1. Make sure to replace all " within the quotes with ', or you'll have some problems.

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 01:24 PM.
Reply With Quote
  #2  
Old 04-28-2015, 09:26 AM
draugluin's Avatar
draugluin draugluin is offline
Member
 
Join Date: Oct 2011
Location: germany
Posts: 120
Gender: Unknown/Other
Credits: 12,581
draugluin is on a distinguished road
Default

Hey,

I've tried this. It's really good.
Reply With Quote
  #3  
Old 04-28-2015, 09:41 AM
cailynmae's Avatar
cailynmae cailynmae is offline
Explorer of Imaginea
 
Join Date: Mar 2015
Posts: 17
Gender: Unknown/Other
Credits: 6,586
cailynmae is on a distinguished road
Default

Thanks! I'm glad you like it.
__________________
The Cave of Crystals
site coming soon! - buzz thread
Reply With Quote
  #4  
Old 12-03-2015, 04:46 AM
tahbikat's Avatar
tahbikat tahbikat is offline
Member
 
Join Date: Feb 2014
Location: Louisiana
Posts: 408
Gender: Female
Credits: 57,933
tahbikat is on a distinguished road
Default

Really excited to get this working on my site, but when I do everything above and go to explore, it gives me this error:

Fatal error: Class 'Explorearea1View' not found in /home/mysgardia/public_html/classes/class_controller.php on line 135



Can someone help me? Not sure when the OP will see this. :c

EDIT: Nvm, I fixed it! However, everytime I explore, it gives me the item or adoptable, but always says "Ooops! Something went wrong." after the comment, so I just removed that part.

Last edited by tahbikat; 12-03-2015 at 05:53 AM.
Reply With Quote
  #5  
Old 12-03-2015, 05:10 PM
Distortion's Avatar
Distortion Distortion is offline
Member
 
Join Date: Dec 2015
Location: Somewhere beyond the sea
Posts: 31
Gender: Female
Credits: 4,569
Distortion is on a distinguished road
Default

Is there a way to add an image to every explore encounter?
Reply With Quote
  #6  
Old 12-03-2015, 05:27 PM
tahbikat's Avatar
tahbikat tahbikat is offline
Member
 
Join Date: Feb 2014
Location: Louisiana
Posts: 408
Gender: Female
Credits: 57,933
tahbikat is on a distinguished road
Default

Quote:
Originally Posted by Distortion View Post
Is there a way to add an image to every explore encounter?
I was thinking the same. I'd just put the image of the egg (or whatever your lvl0 image is) for each adopt in the comments.

So for example take this:

PHP 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));
            } 
and replace the $document->add(new Comment( part with this:

PHP Code:
$document->add(new Comment("Oh look! You found a <img src='imglinkhere' /> $species egg! It's pretty common."FALSE)); 

Make sure you use only 'single' quotes for any code instead of the "double" quotes. Also, you can experiment with image placement. So if you want it before the comment and centered on its own line just add some br tags after it with center tags around. Likewise, do the same for items, currency, and when a user turns up with nothing.

I also found it quite helpful to add a link called (Continue Exploring) to the same explorearea1 page after the comment, so that instead of having to refresh the page, a user just clicks it to continue exploring.

I'm gonna mess with it a little bit in the coming days, so I'll edit or post here again with what I come up with. (:
Reply With Quote
  #7  
Old 12-03-2015, 08:11 PM
Distortion's Avatar
Distortion Distortion is offline
Member
 
Join Date: Dec 2015
Location: Somewhere beyond the sea
Posts: 31
Gender: Female
Credits: 4,569
Distortion is on a distinguished road
Red face Merci Beacoup!

Thanks ^.^

Last edited by Distortion; 12-03-2015 at 08:21 PM.
Reply With Quote
  #8  
Old 12-06-2015, 08:57 PM
tahbikat's Avatar
tahbikat tahbikat is offline
Member
 
Join Date: Feb 2014
Location: Louisiana
Posts: 408
Gender: Female
Credits: 57,933
tahbikat is on a distinguished road
Default

Soooo I noticed a major problem.


I'm not sure but I *think* if a user visits the explore page too soon, before the 24 hours passes completely, it counts the explore times towards the new day. So essentially even though the page says "It seems you have explored too much today" it counts that visit as an exploration time, which adds all the exploration times to the new day, meaning users can't explore like... ever again unless they actually wait 24 hrs to the minute.

Or something like that is going wrong. I'm not a coder so I really don't know where/what the flaw is. If I knew how to just reset the exploretimes database column every 24hrs that'd be golden, but I feel like that would be a cron job or some complicated php script and that's way out of my capabilities. :/

I think I'll just add a crazy explore limit like 99999 (if possible) and set rare drop rates much much higher to remedy this in the meantime, until I can figure something out. Otherwise I really love this mod.
Reply With Quote
  #9  
Old 12-07-2015, 03:47 PM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 133,822
Abronsyth is on a distinguished road
Default

Excellent tutorial! Had to tweak some things, but very nice!
__________________
My Mods Site (1.3.4, 2020 Mods)
Reply With Quote
  #10  
Old 12-19-2015, 02:02 PM
Distortion's Avatar
Distortion Distortion is offline
Member
 
Join Date: Dec 2015
Location: Somewhere beyond the sea
Posts: 31
Gender: Female
Credits: 4,569
Distortion is on a distinguished road
Default Explore System Modifications

Add explore page text
place the code below before
PHP Code:
if ($mysidia->user->exploretimes <= 100) { 
:
PHP Code:
$document->add(new Comment("Page Text<br>")); 
Adding Adopt Images
PHP Code:
if($random >= 41 && $random <= 60){
$species "AdoptName";
$newadopt = new StockAdopt($species);
$newadopt->append($mysidia->user->username);
$adoptIMG $mysidia->db->select("adoptables", array("eggimage"), "id = 'PlaceAdoptIDHere'")->fetchColumn();
$document->add(new Comment("<center><img src='$adoptIMG' alt='$species IMG' /><center><br> Oh look! You found a $species! It's pretty common."FALSE));
            } 
Adding item images
PHP Code:
if($random >= 81 && $random <= 90){
$item "ItemName";
$qty 1;
$newitem = new StockItem($item);
$newitem->append($qty$mysidia->user->username);  
$itemIMG $mysidia->db->select("items", array("imageurl"), "id = 'PlaceItemIDHere'")->fetchColumn();
$document->add(new Comment("<center><img src='$itemIMG' alt='$item IMG' /></center><br>Oh look! You found a <b>$item</b>!"FALSE));
            } 
Explore Again Link
Find this line
PHP Code:
else{
            
$document->add(new Comment(" Oops! Something went wrong."FALSE));
            } 
replace with:
PHP Code:
else{
            
$document->add(new Comment(" <a href='/explorearea1'>Explore?</a>"FALSE));
            } 
find:
PHP Code:
if($random >= 91 && $random <= 99){
$document->add(new Comment("You didn't find anything. Better luck next time."FALSE));
            } 
replace with:
PHP Code:
if($random >= 91 && $random <= 99){
$document->add(new Comment("You didn't find anything. Better luck next time. <a href='/explorearea1'>Explore?</a>"FALSE));
            } 
Random Item Quantity
Find this:
PHP Code:
$qty 4
Replace:
PHP Code:
$qty rand(1,5); 

Last edited by Distortion; 12-19-2015 at 02:04 PM.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Quest- Explore System (Open Source) squiggler Tutorials and Tips 4 07-23-2020 01:07 PM
How to create an image map collierox Tutorials and Tips 3 03-13-2018 05:11 AM
Explore Help? cailynmae Questions and Supports 7 03-30-2017 12:37 AM
Help Create This? Abronsyth Templates and Themes 16 10-24-2011 04:05 PM
How to create a a battle system ,shop and currency?? SieghartZeke Questions and Supports 9 11-02-2009 01:15 AM


All times are GMT -5. The time now is 07:37 AM.

Currently Active Users: 1202 (0 members and 1202 guests)
Threads: 4,081, Posts: 32,032, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636