Remove "already leveled creature today" text?

Forum
Last Post
Threads / Messages

tahbikat

Member
Member
Joined
Feb 11, 2014
Messages
408
Points
16
Age
30
Location
Louisiana
Mysidian Dollar
32,360
I'm making simple profile pages for the adoptables on my site using their levelup pages, but the text that pops up when a member has already leveled a creature kind of removes the whole thing.

Basically what I've done is added new comments to the levelup view file, and I want that to display even if a member has clicked the adoptable that day, so is there an easy way to disable the "already leveled creature today" text?

I still want the adopts to only be clicked once per user though.
 
My work around for this was way too hacky in bypassing the 'error' of 'already leveled creature today'. I'm curious as to HoF's answer.

Perhaps you can glean something out of what I've got (though I toned down the message variable to cut out most of my profile stuff that'd be too custom, left in the usual data) -

Note that this is JUST the click function in levelup.php, not the whole file. Don't use it as is, try to understand it. @w@ Good luck!

  Spoiler: hidden 

PHP:
public function click(){
    $mysidia = Registry::get("mysidia");
	$date = new DateTime;
	$ip = secure($_SERVER['REMOTE_ADDR']);

	/*... First check if the system to levelup pets is enabled ...*/
	if($this->settings->system != "enabled") { throw new NoPermissionException("disabled"); }

	/*... Then check if the user has already visited the pet today ...*/
    elseif($this->adopt->hasVoter($mysidia->user, $date)){
	    if($this->adopt->hasNextLevel()){
            $nextLevel = $this->adopt->getNextLevel();
			$requiredClicks = $nextLevel->getRequiredClicks();
        }

	    $gender_lookup = $mysidia->db->select("owned_adoptables", array("gender"), "aid = '{$this->adopt->getAdoptID()}'")->fetchColumn();
		if ($gender_lookup == "m") { $gender = "Male"; $pronoun = "him"; } else { $gender = "Female"; $pronoun = "her"; } 

		if ($mysidia->user->username == $this->adopt->getOwner()){ $manage_btn = "<a class='btn btn-sm btn-info' href='../../yournovu/manage/{$this->adopt->getAdoptID()}'><i class='fa fa-gear'></i> Manage Your Novu</a>"; } else { $manage_btn = ""; }

		if($this->adopt->hasNextLevel()){
		    $level = $this->adopt->getNextLevel();
			$levelupClicks = $this->adopt->getLevelupClicks();
			$toNext = "(LVL ".$level->getLevel()." in ".$levelupClicks." more EXP)"; 
		} 
		else { $toNext = "(MAX)"; }

		if($this->adopt->getTradeStatus() == "fortrade") { $tradestatus = "<b>For Trade</b>"; } 
		else { $tradestatus = "<b>Not For Trade</b>"; }

		$message = "<div class='adopt_profile'>	<h2>{$this->adopt->getName()}</h2>	";
		
		// If you've already seen the pet today:
		if ($this->adopt->hasVoter($mysidia->user, $date)){
			$message .= "<div style='float: right; margin-right: 15%; margin-top: -15px;'><b>Thanks!</b>  You played with this Novu today!</div>";
		}
		// If you haven't seen the pet today:
		if (!$this->adopt->hasVoter($mysidia->user, $date)){
			$message .= "<div style='display: inline;'><span class='button'><i class='fa fa-paw'></i> Play</span></div>";
		}
			$message .= "{$manage_btn}
						<ul>
						<li>Travels With: <a href='/profile/view/{$this->adopt->getOwner()}'>{$this->adopt->getOwner()}</a></li>
						<li>Birthday: {$this->adopt->birthday}</li>
						<li>Species: {$this->adopt->getType()}</li>
						<li>Gender: {$gender}</li>
						<li>LVL: {$this->adopt->getCurrentLevel()} {$toNext}</li>
						<li>Total EXP: {$this->adopt->getTotalClicks()}</li> 
						<li>Trade Status: {$tradestatus}</li> 
						</ul>
						";

		throw new LevelupException($message);
	} 

	/*... But do this if the pet is frozen! ...*/
	elseif($this->adopt->isFrozen() == "yes") { throw new LevelupException("frozen"); }

	/*... This one, if enabled, would prevent users from visiting a pet too much a day ...*/
    # elseif($mysidia->user->getVotes() > $this->settings->number) { throw new LevelupException("number"); }

    /*... If this setting were on in the backend, it would prevent the users from visiting their own pets ...*/
    # elseif($this->settings->owner == "disabled" and $this->adopt->getOwner() == $mysidia->user->username){ throw new LevelupException("owner");}
    
    /*... If the visitor has not seen the pet today, this will be displayed and the pet will level up! ...*/
	else{
	    $newClicks = $this->adopt->getTotalClicks() + 1;
		$this->adopt->setTotalClicks($newClicks, "update");
        $mysidia->db->insert("vote_voters", array("void" => NULL, "date" => $date->format('Y-m-d'), "username" => $mysidia->user->username, "ip" => $ip, "adoptableid" => $mysidia->input->get("aid")));		 
		
		$ago = date('Y-m-d', strtotime('-40 days'));
		$mysidia->db->delete("vote_voters", "date < '{$ago}'");	

		if($this->adopt->hasNextLevel()){
            $nextLevel = $this->adopt->getNextLevel();
			$requiredClicks = $nextLevel->getRequiredClicks();
            if($requiredClicks and $newClicks >= $requiredClicks) { $this->adopt->setCurrentLevel($nextLevel->getLevel(), "update"); }
        }
		
		$reward = $mysidia->user->clickreward($this->settings->reward);
	    $mysidia->user->changecash($reward);			
        $this->setField("adopt", $this->adopt);
        $this->setField("reward", new Integer($reward));			
	}
}


There are numerous reasons you can't use this as-is, mostly because some of it's been modified in ways unique to my site. I've change a few core page urls, so this part, for example -

if ($mysidia->user->username == $this->adopt->getOwner()){ $manage_btn = "<a class='btn btn-sm btn-info' href='../../yournovu/manage/{$this->adopt->getAdoptID()}'><i class='fa fa-gear'></i> Manage Your Novu</a>"; } else { $manage_btn = ""; }

- has things linking to a yournovu/manage/ page, because my adoptables are called Novu, rather than whatever the original url for that link should be. I forgot. @w@ Stuff like that is different. I also don't know if the system originally kept track of pet birthdays, so that may break, etc.

And, all in all, I DON'T recommend what I've done to get the profile page to work. (I also added in some Javascript elsewhere that deletes the error title itself but that's not included.)

And why don't I like my solution? Because it's still using what was there -

throw new LevelupException($message);

- and I just changed the $message. It's still an Exception being thrown and I'd love to rewrite the entire thing and avoid using exceptions but I don't know how. It's expecting an error to be thrown if things are just so, and I'm just making it look like there wasn't an error.

.

.

.

Basically, HoF, I think what we want (for future releases) are profile pages for our pets that are the same no matter what - whether you've visited the pet or not, whether it's yours or not, and whether it's frozen or not. Rather than change the entire page, just add in a small memo to the pet's profile that says "Thanks for visiting this pet", a link back to the management page if it's your pet, and/or a notification that the pet didn't gain experience because the owner has it frozen.
 
Last edited:
I'm very curious about this as well as I've been trying to do this for a bit now (but 96% fail with understanding PHP).
 
Thank you Kyttias! I'm definitely going to see if I can incorporate any of this into my own site's code! :)
 
Nevermind, I got it working! For anyone who, like me, is not super code savvy but trying to get the image to display in the levelup.php file I used this (I'm sure I could have done something more effective but this works perfectly fine so *shrug*!):
PHP:
<img src='{$this->adopt->getImage()}'/>
 
Last edited:
Installed it onto my site but haven't had a chance to change much. Super late right now. Gonna fiddle with it more tomorrow! Thanks so much Kyttias! And thanks Abronsyth for the image code. c:
 
Basically, the error is still being thrown. You could use a bit of jQuery to cover it up (just add it alongside the rest - it's in script element tags, so it won't be seen like ordinary html - I included it after the last </div> I'm using on my pet's profiles before even closing the message variable). Of course, this'll only work if you have jQuery as part of your theme's template (Bootstrap theme definitely does):
Code:
<script>$(\"h2:contains('An error has occurred.')\").remove();</script>
The code literally removes any h2 element that contains the words "An error has occurred." - gotta love jQuery. The quotes are backslashed as they need to be going into the $message variable. Can't have quotes inside other quotes inside other quotes without the system getting confused, so, backslashes. Yay. -_- (It originally took me a while to figure out.)

And, incidentally, you can change your error message text site-wide from lang/lang_global.php -- so if you happen to change it there, be sure to update the snippet I just provided to reflect that.

(** And yeah, Abronsyth, I forgot to include a pet image -- my pet images are rendered with some custom code, so I took my bit out but couldn't remember the original -- thanks for providing that snippet of code!!)
 
Last edited:
Thanks so much Kyttias! I'm having trouble with removing the error part. I think the jquery isn't being enabled maybe. How exactly do I enable jquery on my site?

I've tried adding this to my theme's header.tpl but it's not working:
HTML:
<script src="{$home}/jquery/jquery-1.11.3.min.js"></script>

I've made a jquery folder with the jquery library in it, so that's why I was using that. ^
I've also tried the hosted links from google and microsoft but they're not working either. :c
 
Weird, but, check that the jQuery library is being loaded with your pages. This really is as simple as linking it and using it. Is the link you added to your header shower up when a page loads/you sure you added it to the right theme? The file does seem to exist in that location on the live version of your site, but a link to it does not appear when I load a page - but maybe you're testing elsewhere.

But, perhaps more to the point, your page titles seem to be in h1 not in h2. Change the code I gave you so it knows to check an h1 tag instead.
 
Oh GAWD that was probably the problem. They were h2 and not h1.

I removed the jquery link because i noticed my pages loaded slow after it was added... Like really slow. But that's probably why you didn't see the link anymore.
Ahh, thanks! I'll see if it works now. But if it's still slow I think I'll just change the error message instead... Unless there's a way to make it not cause pages to be loaded so slow? Lol

Thanks again, you're amazing! <3
 
Is there a way to make it so that the pet's "profile" is shown when the pet is frozen? I've tried several things but to no avail as of yet.
 
I did some thinking on this today. You can find this line in levelup.php and comment it out (just make it so this whole elseif clause doesn't fire) -
PHP:
elseif($this->adopt->isFrozen() == "yes") { throw new LevelupException("frozen"); }
to
PHP:
// elseif($this->adopt->isFrozen() == "yes") { throw new LevelupException("frozen"); }
Or, hey, delete it if you're feeling safe with that, whatever.

Instead, we're going to pop on back up to where we checked if the pet had been visited today or not. This line opens up this clause:
PHP:
elseif($this->adopt->hasVoter($mysidia->user, $date)){

We're going to modify it so it also fires when the pet is frozen. This is probably the most important part. Make it this:
PHP:
elseif($this->adopt->hasVoter($mysidia->user, $date) || ($this->adopt->isFrozen() == "yes")){

Inside this, we can nest another if statement that can show a message that will say that the pet is frozen/locked:
PHP:
if (!$this->adopt->hasVoter($mysidia->user, $date)){
	$message .= "<b>This pet is frozen!</b>";
}

Setting a variable with 'dot equals' (.=) adds to the existing variable, appends to it - I think the technical term is that it concatenates to the existing variable.

Okay, so, ACTUALLY, if you used the code I gave originally without modifying it much, you'll see that I already did included something to happen if you're somehow on the page but hadn't visited the pet - the word 'Play' instead of the thankyou message. (To be honest I want to eventually create a feature so pet's aren't automatically counted as being clicked/visited as soon as the page loads, but wait until a button is pressed, so that's why it's there - well that doesn't work like that, and I haven't invented such a thing yet.) Regardless, here's that bit of code how I gave it in the original post:
PHP:
// If you haven't seen the pet today:
if (!$this->adopt->hasVoter($mysidia->user, $date)){
        $message .= "<div style='display: inline;'><span class='button'><i class='fa fa-paw'></i> Play</span></div>";
}

So go ahead and modify/use that. It'll show when you visit the page but the pet is frozen. Rest assured, pets will be treated as if they've already been seen for the day, and won't add on a new click.
 
Last edited:
Aha! Excellent, thank you Kyttias! I wasn't too far off but I see now where I was going wrong.
 
Does anyone have the code to make this simple profile page ? I've tried fixing up the code here for levelup and not having too much success.

This is the last thing I need for my sites, a basic working public pet profile page :)

Can anyone help on what to change/take out to make it work ?

I just get white pages no matter what I do ...
 
I have the profiles for my pets set up:
  Spoiler: Image 
Test_zps0xbltl0x.png

But would it be possible to have the same show up on the view_levelup file? I've tried tinkering but it does not want to work, and I think I lack the understanding to know 100% where I've gone wrong... for now, I've added a link under all the text that refreshes the page to take you to their 'profile'.
  Spoiler: Image 
Test_zps9nppe22f.png


Test_zpsnoxthfrh.png


Thank you ^_^


EDIT: I made some changes to my levelup view file! It now looks the same as my levelup so it's almost like the same page... I'm pretty happy I did it myself XD Took a while to realise I had to do {$adopt->whatever} and not {$this->adopt-whatever}... XD

  Spoiler: Images 
When you first click them to level them up. As a guest the reward bit won't show (tested and it works!)
re3wr_zpstszhxgwq.png


After you've clicked that day. And also, when they're frozen it will show this but their name will have a snowflake next to it and the words will say you can't play with them.
wtetr_zps3f1g3ddh.png



What happens when they're frozen:
re3wr_zpsnkqzrjju.png
 
Last edited:
I don't understand how to make the public profile. I have it working if you've already played with the pet but where is the code for the actual public profile?
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

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

Latest Threads

Latest Posts

Top