![]() |
Active pet widget?
EDIT: heres the post with the working code-
How would I make a thing to display on my side bar that shows your active/spotlight pet? And maybe make them say random things? So for a picture example- and we'll say this pets name is...Marian? ----------------------------- http://atrocity.mysidiahost.com/picu...b9045b182f.png Marian says: "Lets go exploring!" _____________________________ But that there would be a list of different things you can make them say? So it would choose from a random assortment of Phrases Or sometimes nothing at all? Possibly depending on the pet species if possible? So one species would have a different List of things they could say. But if thats too hard its fine XD Same list is okay. I was just wondering if this was possible. and if so how it would be done. |
To make a favpet display inthe sidebar, first in the AdminCP you'll create a module (surprisingly not a widget):
http://fc03.deviantart.net/fs71/f/20...as-d8dr0j8.png Then in classes/class_sidebar.php you'll need to add these functions: PHP Code:
But I'll get back to that. Let me know if you can at least get the pet into the sidebar and then I'll be back later help you set up a switch statement to display random phrases for pets to say. :meow: |
thank you! I'll mess with it and get back to you after I eat dinner!! ^^
|
Yup Got him in the sidebar! Whats next? ^___^
|
Ittermat do you mind if I use this too? I was going to screw around with the code to try to make a active pet too.
|
Of course not! Lol ^^
|
Also another question- what if I wanted that pet to randomly find items or money- or have "fake" Status effects happen to it?
|
That can be done, too. :pleased: Sounds quite fun, really! (I had work today so I'm super tired. I should be be able to get to this tomorrow, though.)
|
no its fine! get some rest! Help me when you can ^^ thank you!! <3
|
We're going to set it up like this: 1% of the time the pet may get a status effect. Of the 99% of the time that the pet does not come away with a status effect, 75% of the remaining time - nothing will happen at all. Of the other 25% of the time, 5% of the time it will either be because it found some money or an item (about 50% toward either). The remaining 20% of the time it will say a random phrase based on its species. Below is commented but empty code just to get the odds of each event happening right:
PHP Code:
More soon! I've got to go look up some of the code I've used to give items and such again. 1) Is it alright if items and money are automatically collected, even without the user clicking or doing anything? It becomes much more complicated otherwise. 2) Inevitably if you wanted to, say, make it so your active pet can find an abandoned egg 1/500th of the time (about 0.2% chance of happening) but require that the user also be paying attention and clicking that message, remind me - I should be able to think this one through, given enough time. Let me know if this is something you want. 3) These percents should all be easy to modify. Let me know if you have questions and I can help tweak the code. If you change an mt_rand(1,100) to mt_rand(1,200) you will literally make something twice as hard to get and this will be relevant as soon as you want things to happen less than 1% of the time. One percent of that (1,200) would be 0.5% instead of (1,100)'s obvious 1%. 4) The fake status... placeholders for potentially real ones later? Is there a list of random events (nice ones are better than mean ones) you'd be interested in? Such as the pet suddenly gaining experience (as if clicked) or an entire level (if it's not frozen)? More complicated things (that existing item functions can't do) I might be interested in helping out with later, once everything else is done. For now, status effects will be the last on the list of things I'll do, and we'll fill it in with a message of "a status effect would have happened here" so long as we're testing. There are also some ideas I have that would be optional status effects that would require the user to click to accept and have it explained that the changes are somewhat permanent but entirely optional - such as the pet's gender or species changing, or the species' alternate appearance activated. Most of the time the user would be enthusiastically agreeing to this change but what if they really like their pet exactly how it is? We wouldn't want to force something, no matter how cool we think it is. |
Yes automatically getting the items and money is fine! Also no need to worry about 2 right now..maybe later? And 3 ill mess with lol. As for status effects is it possible to give me bases for what different things can be done? Id like the effects to do things to them, and if possible have the pet say something like if they gain am item or lose money or something? But im unsure what i want the status effects to say lol..ill think more on it and use what you gave me when i get home from work ^_^
Also thank you again you are amazing! _______ EDIT EDIT: Heres some ideas for status effects.. if you give me the base coding to use I can modify from there for these. (like have it set the effects- but allow me to change what it says and add more of them to it you know?) Status effects: -Looks like ( Petname) found a some food! They've gained some exp! (Gains Clicks) - (petname) Ate some garbage! Gross! -Oh no! (Petname) has been cursed! (Clicks reset for day) -They grow up so fast dont they? Lets fix that! (petname) is now a baby again! (reverts to baby stage) -(petname) Won a fight! They gained a level! (gains one level) -The love fairy came by and waved her wand! (petname) can now breed again! (enables breeding again) -A mad scientist is loose! (Petname) no longer has species barriers when being bred! (Enables cross species breeding) ----- Edit: Where do I put this code in at btw? |
Well when debugging your site, I find that it has a very serious glitch resulted from this Active Pet Module. For a newly registered user, they do not own any adoptable yet, and therefore do not have favorite pet. However, the script assumes that this new user has favorite pet, and try to fetch the adoptable ID 0 instead(favorite pet ID defaults to 0 if it does not exist). This leads to an uncaught exception 'adoptable ID does not exist', and will prevent any newly registered users from browsing your site.
To fix this, you need to take care of the scenario in which the user has no favorite pet(ID = 0). In this case, you will either just not fetch adoptable at all, or catch exception using a try...catch block. The choice is up to you. Edit: Strangely the solution Kyttias offered seems to have taken care of nonexistent favorite pet ID already, but when I dont have a favorite pet I still receive errors. Did you copy/paste her code exactly? Or something else is wrong? |
I copy pasted..the first code she put up- but i havent done anything with her second one since Im not sure exactly where to put it.
|
The code (with all the percent discussion) isn't done yet/doesn't do anything yet. It'll go inside the setFavPetSB() we made, inside the else half of the if statement, all this inside class_sidebar.php.
:happyc: Sorry, I've had along day and don't think I can work on this tonight - good news is that I don't have work again until at least Sunday so I'll have a few days to think on all of this. edit - @HoF, I vaguely remember this issue but I'm not sure how it was resolved. =/ |
no its fine kyttias! I know you have a life... Im sorry to be so bothersome..Im seriously bad at this coding thing...I am trying to learn though honest...its just not clicking or sticking..
|
I tried to fix the error- but couldnt so for now I just removed the active pet widget until we can figure out how to fix that problem XD
|
Did we ever figure out how to fix this?
I even made an adoptable to put in its place-when one has no favorite pet http://i63.tinypic.com/1zc0c50.jpg The Adoptable id (in adopt_Adoptables table) is 30 if that helps any? |
Actually the above won't work because if the user doesn't own pet 30 it might cause errors.
Send me the code we put in classes/class_sidebar.php - I'd like to make some changes to it. PHP Code:
If you're afraid of editting the code, I can do it. |
all of the coding you gave me is on the first page.. 0.o....I havent done anything to it..
Also im not sure how I would edit it... XD |
If you haven't done anything to it then you should be able to just replace it.
|
so just put the code you put up there in my sidebar file?
|
We created setFavPetSB() before, just replace the old setFavPetSB() we made with the new setFavPetSB() above, yeah.
|
When I do that I get this error..
Catchable fatal error: Argument 1 passed to Sidebar::setDivision() must be an instance of GUIComponent, null given, called in /home/atrocity/public_html/classes/class_sidebar.php on line 235 and defined in /home/atrocity/public_html/classes/class_sidebar.php on line 62 this is what my line 62-68 looks like Code:
protected function setDivision(GUIComponent $module){ Code:
$this->setDivision($this->FavPetSB); |
I'm gonna need the whole file.
|
okay jas...
Mind you I dont have the code you gave me in this- because it causes an error... so its omitted..I was gonna add it again once we figured out how to fix it. ![]() |
PHP Code:
This has added the chance for the pet to say random phrases, find money, and items - so do look it over! You'll want to change the item names to actual items you have right away that way no errors are thrown when it tries to add an item that doesn't exist. :wutno: The message that pet says will show up in a div with a class of "speechbubble" so if you want to add some css for that in your stylesheet, go for it. |
Thank you so much kyttias!! I'll test it out <3 and get back with you!
|
It still gives me this error if I have no favorite pet..
Fatal error: Call to a member function getFavpetID() on null in /home/atrocity/public_html/classes/class_sidebar.php on line 91 It apparently still does it even when I DO have a favorite pet |
Oh! Sorry, line 82 is wrong!
Instead of: PHP Code:
PHP Code:
|
okay now when I dont have a fave pet I get this
Catchable fatal error: Argument 1 passed to Sidebar::setDivision() must be an instance of GUIComponent, null given, called in /home/atrocity/public_html/classes/class_sidebar.php on line 278 and defined in /home/atrocity/public_html/classes/class_sidebar.php on line 62 and when I do have a fave pet I get this- Catchable fatal error: Method OwnedAdoptable::__toString() must return a string value in /home/atrocity/public_html/classes/class_sidebar.php on line 96 |
Ok you've made some major changes to the code because those line numbers don't correlate to anything. =/ You'll have to send me the entire code with your changes for me to fix a basic syntax error, probably. (You have to be really carefully about making sure closing brackets and quotes are never ever broken or interrupted in any way.)
I've tested it now on my site and it IS working. http://orig09.deviantart.net/166e/f/...as-d9w06wl.gif and http://orig11.deviantart.net/60b0/f/...as-d9w085i.png I did make a couple tiny edits just now (just to fix the div surrounding the text, it would break when a message was not there and double up accidentally, and so I fixed both) - but should have nothing to do with whether or not you have a pet. |
I just added in the items, the actual pet breeds and some more stuff for them to say 0.o
Code:
<?php |
Change line 85 to this:
PHP Code:
PHP Code:
Also! Two other things. I'd also change line 95 to: PHP Code:
And at 271, we should close the message like this now: PHP Code:
|
No need to apologize Kyttias!! Im more than anything grateful for all the work and help you're giving me!!
It showed up but I went to go to my account to change out my favorite pet to see if it worked without one- and It gave me this error...? Fatal error: Cannot access protected property OwnedAdoptable::$type in /home/atrocity/public_html/classes/class_sidebar.php on line 144 Should I change it to Public? or something? ah that seems to have worked! (The extra two you added XD) THANK YOU KYTTIAS!! YOU ARE AMAZING <3 |
Yeah. I wasn't quite sure how to access it by default. So in classes/class_ownedadoptable.php see if $type is in the list of variables at the top, if it is, change it, or else add it.
PHP Code:
|
Its working now! no errors to be found currently! THANKS!
I will let you know if something comes up though <3 |
Great! I made the changes to post #26 so it should be relatively safe for anyone else who comes across this thread to use without too much trouble.
|
Im not sure if this is because of The active pet mod? But now I cant login? It gives me these... (I couldnt highlight all of the top one...) It says my login was successful but then It puts me back to the login screen...? To login again.
/class_cookies.php on line 85 Warning: Cannot modify header information - headers already sent by (output started at /home/atrocity/public_html/classes/class_sidebar.php:1) in /home/atrocity/public_html/classes/class_cookies.php on line 88 Warning: Cannot modify header information - headers already sent by (output started at /home/atrocity/public_html/classes/class_sidebar.php:1) in /home/atrocity/public_html/classes/class_cookies.php on line 90 Warning: Cannot modify header information - headers already sent by (output started at /home/atrocity/public_html/classes/class_sidebar.php:1) in /home/atrocity/public_html/classes/class_cookies.php on line 92 |
You can try to send me the file again but it really shouldn't be related (necessarily). I mean, I can log in and out just fine with my version. :hmmm:
Header errors can be caused by a file attempting to render anything not code. Check for blank space at the beginning and end of the file and remove any that you find. But this is caused by cookies, so it thinks? In which case I'm really not sure. |
Heres my file- It works amazing when im logged in... but when im not and I try to log in it wont let me... same thing with logging out- I cant do either. 0.o
I have no idea if anyone else has this issue. Code:
<?php |
All times are GMT -5. The time now is 05:04 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.