Mys 1.3.5 Companion pets

Forum
Last Post
Threads / Messages

GeneticAlpha

Loving Mysidia!
Member
Joined
May 24, 2020
Messages
287
Points
18
Age
31
Location
Tennessee
Mysidian Dollar
13,377
So I had been meaning to share this mod, but I struggled a bit to find everything we did to make the mod what it is XD so after installing it again on my second site, I now was able to make this tutorial. Huge thank you to Abron and Kristahsirah!

This mod allows you to create pets for your site that are separate from adoptables. It also allows you to use css to place them somewhere in your pages. For example, my members will be able to buy these pets in the pet shop then display them on their character image as their current equipped companion. This works like an achievement mod, where you go to your pets list and you see all the available ones are locked and blackened out, and when you collect them, they become available to you. Your pets could also show up in your home or on your property if you have them collected depending where you place them. I'm only going to give a tutorial on setting up the database though and the pages you need and what the code looks like that will display the companion where you want it to display. I'll also show the code that you use that the member gets linked to, to collect the pet. I'll edit later how to get it to cost the member to collect it , but as of right now I still gotta get that figured out, lol.
__________
Anyway, setting up the database. You want to go into your phpMyAdmin and create a new category called: adopts_users_companions
and inside you want these tables:​

id int 3 No null Default None auto_increment
petid int 3 Null Null
name var char 50 Null Null
username var char 50 No null Default none

Then that's done. Next make another category called: adopts_companion
and inside you want these tables:

id int 200 No null Default none auto_increment
name var char 200 Null Null
locked var char 500 Null Null
unlocked var char 500 Null Null
usergroup var char 200 No null As defined: registered
css var char 50 Null Null
display var char 50 Null Null

Then that's done. Inside this adopts_companion category is where you create the pets. You'll need to insert a pet into the table manually. You'll need to have your pet images uploaded to your picuploads also. I created a file within picuploads called companion, then in there, uploaded a regular image of the squirrel, an empty image, then the locked black silhouette image.

So for example, my table looked like this:

id: 1
name: squirrel
locked: /picuploads/companion/PetSquirrelLocked.png
unlocked: /picuploads/companion/PetSquirrel.png
usergroup: (this auto fills as registered, it doesn't need anything added or changed)
css: Squirrel (though you can change it, it's basically just what you need to call when you want to change the image with css)
display: /picuploads/companion/PetSquirrelUnlocked.png (This is what you want to be displayed when the pet can be seen places, so this can be different from the regular unlocked image if you want.)

So now, you should have your image folder for pets set up, and your two database categories, with one pet created in the adopts_companion for testing purposes.

Next we need to make some files in the root folder and also add some things to your account file. The public_html. I'll post another comment since I was hitting my character cap on this one.
1623699467501.png
 
in your account.php folder you want to paste at the bottom, this:

public function companion(){

$mysidia = Registry::get("mysidia");

//change companion
if($mysidia->input->post("submit")){

$mysidia->db->update("users_profile", array("companion" => $mysidia->input->post("companion")), "username = '{$mysidia->user->username}'");

return;

}

//Determine if user is staff or not (use this later)

$group = $mysidia->db->select("users", array("usergroup"), "username = '{$mysidia->user->username}'")->fetchColumn();

//Find their unlocked companions
$unlocked = $mysidia->db->select("users_companions", array("petid"), "username = '{$mysidia->user->username}'");

$this->setField("unlocked", new DatabaseStatement($unlocked));

//Find all possible companions
$allpets = $mysidia->db->select("companion", array("id"), "usergroup = 'registered'");

$this->setField("allpets", new DatabaseStatement($allpets));

}

and add to your accountview.php file, this:

public function companion(){

$mysidia = Registry::get("mysidia");

$document = $this->document;

$document->setAlign(new Align("center", "middle"));
$document->setTitle("Companions");

//Form Submit
if($mysidia->input->post("submit")){

$document->setTitle("<br>Companion Changed Successfully!");

$document->add(new Comment("<br>You successfully changed your companion! <a href='../account'>Click Here</a> to manage your account <br>or <a href='http://dinotracks.mysidiahost.com/profile/view/{$mysidia->user->username}'>Click Here</a> to view your profile now."));

return;

}

//UNLOCKED companions, selectable
$unlocked = $this->getField("unlocked")->get();
$document->add(new Paragraph());
$document->add(new Comment("<br><h3>Unlocked Companions</h3><br><br>
<form action='../../account/companion' method='post'>
<div style='width:34%;display: inline-block;'><input type='radio' name='companion' value='../../picuploads/companion/PetEmpty.png'>

<label for='companion'>Remove Companion</label></div><br><br>"));


if($unlocked->rowCount() == 0){

$document->add(new Comment("No available companions / familiars.<br></form>"));

}

while($id = $unlocked->fetchColumn()){

$name = $mysidia->db->select("companion", array("name"), "id = $id")->fetchColumn();

$url = $mysidia->db->select("companion", array("unlocked"), "id = '{$id}'")->fetchColumn();
$display = $mysidia->db->select("companion", array("display"), "id = '{$id}'")->fetchColumn();


$document->add(new Comment("<div style='width:34%;display: inline-block;'><label for='companion'><img id='unlocked' src='{$url}'/></label><img id='display' src='{$display}'/><input type='radio' id='{$name}' name='companion' value='{$url}'>
{$name}
</div>", FALSE));

}

$document->add(new Comment(""));
$document->add(new Comment(""));
$document->add(new Comment(""));
$document->add(new Comment("<input type='submit' id='submit' name='submit' value='Select'>

</form>"));

//LOCKED companions (non-selectable) (for now we're just going to show ALL possible companions)

//$document->add(new Paragraph());
$document->add(new Comment("_________________________________
<br><h3>Locked Companions</h3><br>The following companions have not been unlocked yet.
<br>Note: You can unlock companions by finding them in doing things such as: collect daily rewards, questing, events, etc.<br>"));
$allpets = $this->getField("allpets")->get();



if($allpets->rowCount() == 0){

$document->add(new Comment("You don't have any Locked companions. Good job!"));

}
$unlockedpets = $mysidia->db->select("users_companions", array("petid"), "username = '{$mysidia->user->username}'")->fetchColumn();
while($id = $allpets->fetchColumn()){

$name = $mysidia->db->select("companion", array("name"), "id = $id")->fetchColumn();

$url = $mysidia->db->select("companion", array("locked"), "id = $id")->fetchColumn();

$unlockedcheck = $mysidia->db->select("users_companions", array("id"), "petid = $id and username = '{$mysidia->user->username}'")->fetchColumn();


if($unlockedcheck == NULL){
$document->add(new Comment("<div style='width:34%;display: inline-block;'><img rel='tooltip' title='<em>Own to unlock<em>' src='{$url}'/></div>", FALSE));
}
else{}

}

}

Don't forget you'll need to customize these view files to be more what you're wanting.

If you have your users that travel through an image map and you want them to stumble upon a pet, you can create the pet a page where they get linked to where they collect it. So when they click the link, it tells them what pet they found and allows them to collect it. If they already have the pet, it'll reject them getting another of that type. So you can put a switch type statement that determines what pets get spotted, based on page visit, etc. Lots of options really if you know what you're doing.

Anyway, so I created a squirrel.php page with, this:

<?php

use Resource\Native\Integer;
use Resource\Native\String;
use Resource\Native\Arrays;
use Resource\Native\Null;

class SquirrelController extends AppController{

public function __construct(){
parent::__construct("member");
$mysidia = Registry::get("mysidia");
}

public function index(){
$mysidia = Registry::get("mysidia");
}

}
?>

then a squirrelview.php page with:

<?php

class SquirrelView extends View{

public function index(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
//when submitting...
if($mysidia->input->post("submit")){
$document->setTitle("Spotted a squirrel<br><br>");
//first we're gonna make sure they don't already have a squirrel
$havepet = $mysidia->db->select("users_companions", array("petid"), "name = '{$mysidia->input->post("name")}' AND username = '{$mysidia->user->username}'")->fetchColumn();
if($havepet == NULL){

$document->add(new Comment("Wow! A {$mysidia->input->post("name")} has become a companion!<br><br></a>"));

//Uncomment the below to actually use it
$mysidia->db->insert("users_companions", array("id" => NULL, "petid" => $mysidia->input->post("id"), "username" => $mysidia->user->username, "name" => $mysidia->input->post("name")));
}
else{
$document->add(new Comment("You already have a {$mysidia->input->post("name")} companion!<br>"));
}
return;
}

$document->setTitle("Companion found!<br><br>");

$animal = "squirrel"; //the companion name
$cid = 1; //The ID as stored in adopts_companion

$document->add(new Comment("Wow! Look at that, a {$animal}!<br><br>
<img src='/picuploads/companion/PetSquirrel.png'><br></br>
<form action='../../squirrel' method='post'>
<input type='hidden' name='id' value='{$cid}'>
<input type='hidden' name='name' value='{$animal}'>
<input type='submit' name='submit' value='Befriend the {$animal}'>
</form><br><br>"));
}
}
?>

and you just link to that page wherever you need the link to show up.

The pet collection page is going to be YOURSITE/account/companion

Like I say I will have to update this to add more things but this is all I could write up right now.
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,274
Messages
33,114
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top