Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Addons and Modifications > Mys v1.3.x Mods

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 02-01-2017, 08:07 PM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 111,704
Abronsyth is on a distinguished road
Default Riddle Mod V. 1.1

2/3/17 update: There is now a time-based options for riddles. Read the 3rd post for more info! (Attachments and tutorial updated)

Next to do... Add option for choice between items and pets.

Hey all!
This is something I've been developing for a while (don't laugh, I'm not very handy with PHP).

So, a great activity on adoptable sites is rewarding people with exclusive adoptables by having them solve a riddle! Unfortunately Mysidia's promocode system doesn't make this easy, as you don't want one person adopting hundreds of these exclusive pets by just re-entering the code.

That is where this modification comes in!

What it does: This mod allows admins to create riddles with a riddle name, clue, and reward (must be an adoptable at this time). Then the admin can set a chosen riddle to be the active riddle, meaning that only one will be shown and solvable at a time. This means you can create a bunch of riddles in one go, but only use whichever one you want at that time.

Users then visit the page and see the riddle. If they haven't yet solved it then they can try to. If it is incorrect they can try again. If it is correct then they are rewarded with the pet you set as a reward! Then when they go to visit the page again, if they've already answered the current active riddle then they will not be able to solve it again, even if they get rid of their reward pet. Then, when the admin sets a new active riddle, they are able to solve once again!

So, let's get started with the mod! First you'll need to run this SQL:
Code:
CREATE TABLE IF NOT EXISTS `adopts_active_riddle` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `adopts_riddle` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) DEFAULT NULL,
  `clue` varchar(500) DEFAULT NULL,
  `solve` varchar(50) DEFAULT NULL,
  `fromdate` varchar(20) DEFAULT NULL,
  `reward` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `adopts_solved_riddles` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) DEFAULT NULL,
  `uid` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
That will create 3 new tables for you. If you ever forget what the clue, reward, name, etc is for a specific riddle just go to adopts_riddle in your database.

Now we're going to make the files, it is quite simple, no worries! ((Note that the two needed files are also attachments! Just make sure you put them in the correct directories!))

First up is riddle.php which goes in your home directory (the file the script is installed in):
PHP Code:
<?php

class RiddleController extends AppController{
    
    public function 
__construct(){
        
parent::__construct("member");
    }

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

}
?>
Save it (upload if you need to). Next up is the view file, which goes in the view folder; riddleview.php
PHP Code:
<?php 

use Resource\Native\String
use 
Resource\Collection\LinkedList

class 
RiddleView extends View
     
    public function 
index(){ 
        
$mysidia Registry::get("mysidia"); 
        
$document $this->document;         
        
$document->setTitle("Riddle"); 
        
        
$active $mysidia->db->select("active_riddle", array("name"))->fetchColumn();
    
$ridname $mysidia->db->select("riddle", array("name"), "name = '{$active}'")->fetchColumn();
    
$ridclue $mysidia->db->select("riddle", array("clue"), "name = '{$active}'")->fetchColumn();
    
$ridsolve $mysidia->db->select("riddle", array("solve"), "name = '{$active}'")->fetchColumn();
    
$reward $mysidia->db->select("riddle", array("reward"), "name = '{$active}'")->fetchColumn();
    
    
date_default_timezone_set('EST');
    
$today date('m/d/Y');
                    
            if(
$mysidia->input->post("answer")){
            if(
$mysidia->input->post("solved") == $ridsolve){
            
$document->add(new Comment"Congratulations, you have solved the riddle. You have recieved one {$reward} as a reward!")); 
            
$mysidia->db->insert("solved_riddles", array("name" => $active"uid" => $mysidia->user->uid));
                
$newadopt = new StockAdopt($reward);
                
$newadopt->append($mysidia->user->username);
            
$document->add(new Comment("<meta http-equiv='refresh' content='1;url=riddle' />")); 
                return 
TRUE;
            }
            else{
            
$document->add(new Comment"Sorry, that is not the correct answer. Feel free to try again!"));
            
$document->add(new Comment("<meta http-equiv='refresh' content='1;url=riddle' />")); 
                return 
TRUE;
            }        
        }
        
    if(
$mysidia->input->post("add")){
        
$mysidia->db->insert("riddle", array("id" => NULL"name" => $mysidia->input->post("name"), "clue" => $mysidia->input->post("clue"), "fromdate" => $mysidia->input->post("fromdate"), "solve" => $mysidia->input->post("solve"), "reward" => $mysidia->input->post("reward")));                
        
$document->add(new Comment"You have created a new riddle called {$mysidia->input->post("name")}.")); 
        
$document->add(new Comment("<meta http-equiv='refresh' content='1;url=riddle' />")); 
        return 
TRUE;        
    }
    

        
$checkdate $mysidia->db->select("riddle", array("fromdate"), "fromdate ='{$today}'")->fetchColumn();
        
$name $mysidia->db->select("riddle", array("name"), "fromdate ='{$today}'")->fetchColumn();

    if(
$checkdate){
        
$mysidia->db->query("TRUNCATE TABLE adopts_active_riddle"); 
        
$mysidia->db->insert("active_riddle", array("id" => NULL"name" => $name));
    }

    
    if(
$mysidia->input->post("activate")){
        
$mysidia->db->query("TRUNCATE TABLE adopts_active_riddle"); 
        
$mysidia->db->insert("active_riddle", array("id" => NULL"name" => $mysidia->input->post("currname")));
        
$document->add(new Comment"You have activated a new riddle.")); 
        
$document->add(new Comment("<meta http-equiv='refresh' content='1;url=riddle' />")); 
        return 
TRUE;                
    }
            
            if(
$mysidia->user instanceof Admin){ 
        
$document->add(new Comment"<h2>Manage Riddles</h2>")); 
             
$document->add(new Comment"You can add a new riddle below. Creating a new riddle will not make it the new shown riddle, you do that below. 
                 Riddle answers and names must be the exact name of the pet reward, and they are case sensitive."
));
                 
                 
        
$currForm = new Form("currform""""post");
        
$currForm->add(new Comment("<br><u>Set the Active Riddle:</u><br>"TRUE"b"));
        
$currForm->add(new Comment("<br><b>Current Active Riddle:</b> {$ridname}<br>"TRUE""));
        
$currForm->add(new Comment("Name:"));
        
$currForm->add(new TextField("currname"));
        
$currForm->add(new Button("Activate""activate""submit"));
        
$document->add($currForm);  
         
        
$ridForm = new Form("addform""""post");
        
$ridForm->add(new Comment("<br><u>Create A New Riddle:</u><br>"TRUE"b"));
        
$ridForm->add(new Comment("Name:"));
        
$ridForm->add(new TextField("name"));
        
$ridForm->add(new Comment("Clue:"));
        
$ridForm->add(new TextArea("clue"));
        
$ridForm->add(new Comment("Solve: (answer to the riddle)"));
        
$ridForm->add(new TextField("solve"));
        
$ridForm->add(new Comment("Start Date:(MM/DD/YYYY) or leave blank")); 
            
$ridForm->add(new TextField("fromdate"));
        
$ridForm->add(new Comment("Reward:(the adoptable your member can obtain by solving this riddle.)"));
        
$ridForm->add(new TextField("reward"));
        
$ridForm->add(new Button("Create Riddle""add""submit"));
        
$document->add($ridForm);    
                     
                     
$document->add(new Comment"<hr>"));
        }
                else{ 
$document->add(new Comment"")); 
}
    
$done $mysidia->db->select("solved_riddles", array("name""uid"), "name = '{$active}' and uid = '{$mysidia->user->uid}'")->fetchObject();
    if(
$done){
      
$document->add(new Comment("<h2>Riddle Center</h2><br> {$today} Welcome to the Riddle Center! Here you can put your mind to the test and try to solve a riddle for the chance of a reward."));
           
                
$doneForm = new Form("doneform""""post");
        
$doneForm->add(new Comment("<br><h3><u>Active Riddle</u></h3>"TRUE"b"));
        
$doneForm->add(new Comment("<b>{$ridname}</b>"TRUE"b"));
        
$doneForm->add(new Comment("{$ridclue}"));
        
$doneForm->add(new Comment("<br><h3>You have completed this riddle, good job!</h3>"TRUE"b"));
        
$document->add($doneForm);
        
    }
    
    else{    
        
$document->add(new Comment("<h2>Riddle Center</h2><br> {$today} Welcome to the Riddle Center! Here you can put your mind to the test and try to solve a riddle for the chance of a reward."));
                
$solveForm = new Form("solveform""""post");
        
$solveForm->add(new Comment("<br><h3><u>Active Riddle</u></h3>"TRUE"b"));
        
$solveForm->add(new Comment("<b>{$ridname}</b>"TRUE"b"));
        
$solveForm->add(new Comment("{$ridclue}<br><br>"));
        
$solveForm->add(new Comment("Answer:""""b"));
        
$solveForm->add(new TextField("solved"));
        
$solveForm->add(new Button("Submit Answer""answer""submit"));
        
$document->add($solveForm); 
        
        
    }            
        
            
            
     }
     
}
?>
Save, and now go visit your new page at http://yoursite.com/riddle

As long as you're logged in as an admin then you'll be able to create and manage riddles! Regular users cannot see this part, don't worry

Thank you
Thank you to DinoCanid, your raffle mod gave me the inspiration and some resources needed to complete this mod.
Thank you to IntoRain, your help with some of my faulty code made this possible.

Let me know if you encounter any issues or have questions :)
Attached Files
File Type: php riddle.php (232 Bytes, 3 views)
File Type: php riddleview.php (6.0 KB, 2 views)
__________________
My Mods Site (1.3.4, 2020 Mods)

Last edited by Abronsyth; 02-03-2017 at 11:46 AM.
Reply With Quote
  #2  
Old 02-02-2017, 07:40 PM
Chaos77777 Chaos77777 is offline
Member
 
Join Date: Jan 2017
Posts: 43
Gender: Male
Credits: 3,693
Chaos77777 is on a distinguished road
Default

Pretty cool. Do you happen to know where I could put in the code to make each riddle appear based on the date?
Reply With Quote
  #3  
Old 02-03-2017, 11:09 AM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 111,704
Abronsyth is on a distinguished road
Default

[lots of babbling about what and where and how]

So what we need to do:
Add a new column to adopts_riddle called "fromdate";
Code:
ALTER TABLE  `adopts_riddle` ADD  `fromdate` VARCHAR( 20 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL AFTER  `solve` ;
Then we go into riddleview.php for the fun stuff!

Replace your riddleview.php with this;
PHP Code:
<?php 

use Resource\Native\String
use 
Resource\Collection\LinkedList

class 
RiddleView extends View
     
    public function 
index(){ 
        
$mysidia Registry::get("mysidia"); 
        
$document $this->document;         
        
$document->setTitle("Riddle"); 
        
        
$active $mysidia->db->select("active_riddle", array("name"))->fetchColumn();
    
$ridname $mysidia->db->select("riddle", array("name"), "name = '{$active}'")->fetchColumn();
    
$ridclue $mysidia->db->select("riddle", array("clue"), "name = '{$active}'")->fetchColumn();
    
$ridsolve $mysidia->db->select("riddle", array("solve"), "name = '{$active}'")->fetchColumn();
    
$reward $mysidia->db->select("riddle", array("reward"), "name = '{$active}'")->fetchColumn();
    
    
date_default_timezone_set('EST');
    
$today date('m/d/Y');
                    
            if(
$mysidia->input->post("answer")){
            if(
$mysidia->input->post("solved") == $ridsolve){
            
$document->add(new Comment"Congratulations, you have solved the riddle. You have recieved one {$reward} as a reward!")); 
            
$mysidia->db->insert("solved_riddles", array("name" => $active"uid" => $mysidia->user->uid));
                
$newadopt = new StockAdopt($reward);
                
$newadopt->append($mysidia->user->username);
            
$document->add(new Comment("<meta http-equiv='refresh' content='1;url=riddle' />")); 
                return 
TRUE;
            }
            else{
            
$document->add(new Comment"Sorry, that is not the correct answer. Feel free to try again!"));
            
$document->add(new Comment("<meta http-equiv='refresh' content='1;url=riddle' />")); 
                return 
TRUE;
            }        
        }
        
    if(
$mysidia->input->post("add")){
        
$mysidia->db->insert("riddle", array("id" => NULL"name" => $mysidia->input->post("name"), "clue" => $mysidia->input->post("clue"), "fromdate" => $mysidia->input->post("fromdate"), "solve" => $mysidia->input->post("solve"), "reward" => $mysidia->input->post("reward")));                
        
$document->add(new Comment"You have created a new riddle called {$mysidia->input->post("name")}.")); 
        
$document->add(new Comment("<meta http-equiv='refresh' content='1;url=riddle' />")); 
        return 
TRUE;        
    }
    

        
$checkdate $mysidia->db->select("riddle", array("fromdate"), "fromdate ='{$today}'")->fetchColumn();
        
$name $mysidia->db->select("riddle", array("name"), "fromdate ='{$today}'")->fetchColumn();

    if(
$checkdate){
        
$mysidia->db->query("TRUNCATE TABLE adopts_active_riddle"); 
        
$mysidia->db->insert("active_riddle", array("id" => NULL"name" => $name));
    }

    
    if(
$mysidia->input->post("activate")){
        
$mysidia->db->query("TRUNCATE TABLE adopts_active_riddle"); 
        
$mysidia->db->insert("active_riddle", array("id" => NULL"name" => $mysidia->input->post("currname")));
        
$document->add(new Comment"You have activated a new riddle.")); 
        
$document->add(new Comment("<meta http-equiv='refresh' content='1;url=riddle' />")); 
        return 
TRUE;                
    }
            
            if(
$mysidia->user instanceof Admin){ 
        
$document->add(new Comment"<h2>Manage Riddles</h2>")); 
             
$document->add(new Comment"You can add a new riddle below. Creating a new riddle will not make it the new shown riddle, you do that below. 
                 Riddle answers and names must be the exact name of the pet reward, and they are case sensitive."
));
                 
                 
        
$currForm = new Form("currform""""post");
        
$currForm->add(new Comment("<br><u>Set the Active Riddle:</u><br>"TRUE"b"));
        
$currForm->add(new Comment("<br><b>Current Active Riddle:</b> {$ridname}<br>"TRUE""));
        
$currForm->add(new Comment("Name:"));
        
$currForm->add(new TextField("currname"));
        
$currForm->add(new Button("Activate""activate""submit"));
        
$document->add($currForm);  
         
        
$ridForm = new Form("addform""""post");
        
$ridForm->add(new Comment("<br><u>Create A New Riddle:</u><br>"TRUE"b"));
        
$ridForm->add(new Comment("Name:"));
        
$ridForm->add(new TextField("name"));
        
$ridForm->add(new Comment("Clue:"));
        
$ridForm->add(new TextArea("clue"));
        
$ridForm->add(new Comment("Solve: (answer to the riddle)"));
        
$ridForm->add(new TextField("solve"));
        
$ridForm->add(new Comment("Start Date:(MM/DD/YYYY) or leave blank")); 
            
$ridForm->add(new TextField("fromdate"));
        
$ridForm->add(new Comment("Reward:(the adoptable your member can obtain by solving this riddle.)"));
        
$ridForm->add(new TextField("reward"));
        
$ridForm->add(new Button("Create Riddle""add""submit"));
        
$document->add($ridForm);    
                     
                     
$document->add(new Comment"<hr>"));
        }
                else{ 
$document->add(new Comment"")); 
}
    
$done $mysidia->db->select("solved_riddles", array("name""uid"), "name = '{$active}' and uid = '{$mysidia->user->uid}'")->fetchObject();
    if(
$done){
      
$document->add(new Comment("<h2>Riddle Center</h2><br> {$today} Welcome to the Riddle Center! Here you can put your mind to the test and try to solve a riddle for the chance of a reward."));
           
                
$doneForm = new Form("doneform""""post");
        
$doneForm->add(new Comment("<br><h3><u>Active Riddle</u></h3>"TRUE"b"));
        
$doneForm->add(new Comment("<b>{$ridname}</b>"TRUE"b"));
        
$doneForm->add(new Comment("{$ridclue}"));
        
$doneForm->add(new Comment("<br><h3>You have completed this riddle, good job!</h3>"TRUE"b"));
        
$document->add($doneForm);
        
    }
    
    else{    
        
$document->add(new Comment("<h2>Riddle Center</h2><br> {$today} Welcome to the Riddle Center! Here you can put your mind to the test and try to solve a riddle for the chance of a reward."));
                
$solveForm = new Form("solveform""""post");
        
$solveForm->add(new Comment("<br><h3><u>Active Riddle</u></h3>"TRUE"b"));
        
$solveForm->add(new Comment("<b>{$ridname}</b>"TRUE"b"));
        
$solveForm->add(new Comment("{$ridclue}<br><br>"));
        
$solveForm->add(new Comment("Answer:""""b"));
        
$solveForm->add(new TextField("solved"));
        
$solveForm->add(new Button("Submit Answer""answer""submit"));
        
$document->add($solveForm); 
        
        
    }            
        
            
            
     }
     
}
?>
As far as I can tell this is working. So you can set a current active riddle with no date manually, then as soon as the date matches a date of a riddle in the database, that riddle becomes active until you manually set a new one or a new date/riddle association occurs.
__________________
My Mods Site (1.3.4, 2020 Mods)

Last edited by Abronsyth; 02-03-2017 at 11:40 AM.
Reply With Quote
Reply

Thread Tools
Display Modes

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


All times are GMT -5. The time now is 05:37 PM.

Currently Active Users: 465 (0 members and 465 guests)
Threads: 4,080, Posts: 32,024, 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