Giving users things (timed)

Forum
Last Post
Threads / Messages

Ittermat

The awesomesauce
Member
Joined
Feb 2, 2016
Messages
305
Points
18
Location
in front of my laptop
Mysidian Dollar
21,305
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:
 <?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");
$reward= 1;

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. ^^
 
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:
<?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:
<?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.
 
Last edited:
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:
"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:
$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.

help2_by_kyttias-d9qonsg.gif


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.
 
Last edited:
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:
    <?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:

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,119
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top