Mysidia Adoptables Support Forum  

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

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 02-05-2016, 01:28 AM
Ittermat's Avatar
Ittermat Ittermat is offline
The awesomesauce
 
Join Date: Feb 2016
Location: in front of my laptop
Posts: 272
Gender: Female
Credits: 33,959
Ittermat is on a distinguished road
Red face Giving users things (timed)

I was looking at this Code (shown below)

And I was wondering if there was a way to edit it so a specific user could only...lets say collect something from this page...once a month? so basically every 30 days they'd come back to claim their reward... and otherwise they cant access the page.

PHP Code:
 <?php

include("functions/functions.php");
include(
"functions/functions_users.php");
include(
"functions/functions_adopts.php");
include(
"functions/functions_friends.php");
include(
"functions/functions_items.php");
include(
"inc/lang.php");
include(
"inc/bbcode.php");

//***************//
//  START SCRIPT //
//***************//

$cashname grabanysetting("cost");
$reward1;

if(
$isloggedin == "yes"){
changecash($reward$GLOBALS['username'], $GLOBALS['money']);
$article_title "Hello, {$username}!";
$article_content "You have gained {$reward} {$cashname}.";
}
else{
$article_title "You are not logged in!";
$article_content "You must be logged in to view this page!";
}

//***************//
//  OUTPUT PAGE  //
//***************//

echo showpage($article_title$article_content$date);
?>
Please and thank you in advance. ^^
Reply With Quote
  #2  
Old 02-05-2016, 02:38 AM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 89,098
Kyttias is on a distinguished road
Default

Okay that code is from a much, much older version of Mysidia and shouldn't be referenced and use cannot be made of it. Some of those include files don't even exist anymore.

You should read this guide on making custom pages and it should cover everything you need. Please do read through it all before continuing down this post, or at least reread this post after you've read everything there.

To be specific, and this is covered, you'll need to add a column to a table in your database. Now, depending on the amount of things like this you want to, I'd suggest making a table just to hold data on this. But if it's only going to be a few things, you can always just add a column to the end of the 'adopts_users' table in your database to hold a time reference.

In the examples in the link I gave, we add a column 'lastday' and use it to check time. (Logically, if you're going to have more than one sort of time-based event, you'll need many more intuitively-named columns because they can't all share one.)

Say your page is "/awesomepage".

You will need to make awesomepage.php -
PHP Code:
<?php
class AwesomePageController extends AppController{

    public function 
__construct(){
        
parent::__construct("member");
    }
    
    public function 
index(){
        
$mysidia Registry::get("mysidia");
    }
    
}
?>
And then view/awesomepageview.php (so that's inside the view folder) -
PHP Code:
<?php
class AwesomePage extends View{

    public function 
index(){
        
$mysidia Registry::get("mysidia");
        
$document $this->document;        
        
$document->setTitle("Super Awesome Page");    
        if (
strtotime($mysidia->user->lastday) < strtotime("-30 days")) {
            
$document->add(new Comment("It has been at least 30 days since your last visit!"FALSE));
            
// Give User Item
            
$item "Cupcake";
            
$qty 1;
            
$newitem = new StockItem($item);
            
$newitem->append($qty$mysidia->user->username);  
            
// Reset Timestamp
            
$now = new DateTime();
            
$today $now->format('Y-m-d');
            
$mysidia->db->update("users", array("lastday" => $today), "username = '{$mysidia->user->username}'");
        } else {
            
$daysleft strtotime($mysidia->user->lastday);
            
$document->add(new Comment("We're sorry, 30 days have not yet passed! Please wait {$daysleft} more days!"FALSE));
        }  
    }
    
}
?>
So long as you've added the column to the database, this should just automatically work. However, it leaves very little room for testing since it will automatically attempt to give the item "Cupcake" and then any visits for the next 30 days should be prevented. You can "comment out" php code to temporarily disable it by wrapping it in /* These */, starting a line with //, and/or starting a line with #.

I super recommend you obtain a nice text editor with syntax highlighting such as Notepad++ or Sublime Text, as it makes coding much easier on the eyes and you can easily see at a glance where things are breaking because the colors will mess up.
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 02-05-2016 at 02:54 AM.
Reply With Quote
  #3  
Old 02-05-2016, 12:33 PM
Ittermat's Avatar
Ittermat Ittermat is offline
The awesomesauce
 
Join Date: Feb 2016
Location: in front of my laptop
Posts: 272
Gender: Female
Credits: 33,959
Ittermat is on a distinguished road
Default

Ohh!! Thank you so much Kyttias! you're amazing!
Reply With Quote
  #4  
Old 02-05-2016, 08:40 PM
Ittermat's Avatar
Ittermat Ittermat is offline
The awesomesauce
 
Join Date: Feb 2016
Location: in front of my laptop
Posts: 272
Gender: Female
Credits: 33,959
Ittermat is on a distinguished road
Default

I have another quick question- what if I wanted to have them need items to do a mission, and some of the items are consumed and others arent when they click yes?

I also cant figure out how to add a column... >_>

Or what to do for that..

I pretty much need things written out in Kindergarten terms.

Last edited by Ittermat; 02-05-2016 at 10:23 PM.
Reply With Quote
  #5  
Old 02-06-2016, 01:38 AM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 89,098
Kyttias is on a distinguished road
Default

"Some of the items are and others aren't" -- based on what criteria?

To remove an item - You need to know it's name and the amount you want to remove. You'd need something this on a form (or ajax) submission.

PHP Code:
$item_name "Flower";
$qty 5;
$item = new PrivateItem($item$mysidia->user->username);
$item->remove($qty$mysidia->user->username); 
As for a button - Anything with a button will either send users to another page (with a form) or require ajax (which I know how to do now, but it isn't built into Mysidia's core functionality to allow ajax). These aren't official notes, they're my notes, but there's details on how to make forms the built in way here. I'd suggest examining how donate.php and view/donateview.php work together to allow users to send one another money via a form.

To add a column to the database
- Log into phpmyadmin. Visit the 'adopts_users' table. Open the Structure tab. At the bottom, hit 'Go' at the end of 'Add Column'. Call it lastday. Let's just go with it being VARCHAR 20, and NULL is an okay value if its never been filled before.



Alternatively, you can just enter SQL from the third tab:
Code:
ALTER TABLE `adopts_users` ADD `lastday` VARCHAR(20) NULL DEFAULT NULL ;
While we're at it, I suggest checking out this tutorial on how to make an explore system.
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 02-06-2016 at 02:01 AM.
Reply With Quote
  #6  
Old 02-06-2016, 11:41 AM
Ittermat's Avatar
Ittermat Ittermat is offline
The awesomesauce
 
Join Date: Feb 2016
Location: in front of my laptop
Posts: 272
Gender: Female
Credits: 33,959
Ittermat is on a distinguished road
Default

EDIT:My whole post has info...and my page has a different error now... ugh...

I did some more Messing with it...and I came across this now...

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

Im really trying to figure this whole thing out on my own... but I am stumped!

________


Thank you Kyttias! I'll try this out <3

Sorry im such a bother XD I am trying to learn I just dont get it as fast and I get easily confused... so thanks for being patient with me, now and in the future.

EDIT: Okay I managed to get my page to show up-

This is the code Im currently using in Adminrewardsview-

PHP Code:
    <?php
  
class Arewards extends View{

    public function 
index(){
        
$mysidia Registry::get("mysidia");
        
$document $this->document;        
        
$document->setTitle("Adminstrator rewards");
if(
$mysidia->user->status->admin != "yes"){
    
$document->add(new Comment("Sorry! you're not an Administrator!!"));
    
$document->add(new Comment("Thank you for collecting your paycheck!!"));
} else {
    }          
        if (
strtotime($mysidia->user->lastday) < strtotime("-30 days")) {
            
$document->add(new Comment("It has been at least 30 days since your last visit!"FALSE));
            
// Give User Item
              
$amount 50000;
             
$mysidia->user->changecash($amount);  
            
$newitem = new StockItem($item);
            
$newitem->append($qty$mysidia->user->username);  
            
$document->add(new Comment("You've recieved 50,000 beads!"));
            
// Reset Timestamp
            
$now = new DateTime();
            
$today $now->format('Y-m-d');
            
$mysidia->db->update("users", array("lastday" => $today), "username = '{$mysidia->user->username}'");
        } else {
            
$daysleft strtotime($mysidia->user->lastday);
            
$document->add(new Comment("We're sorry, 30 days have not yet passed! Please wait {$daysleft} more days!"FALSE));
        }  
    }
    
}
?>
I cant figure out where I went wrong..

Last edited by Ittermat; 02-06-2016 at 11:22 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


All times are GMT -5. The time now is 01:28 AM.

Currently Active Users: 9842 (0 members and 9842 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