Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Questions and Supports (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=18)
-   -   Active pet widget? (http://www.mysidiaadoptables.com/forum/showthread.php?t=5064)

Ittermat 03-05-2016 04:02 PM

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.

Kyttias 03-05-2016 05:18 PM

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:

public function getFavPetSB(){
        return 
$this->FavPetSB;
    }

protected function 
setFavPetSB(){
        
$mysidia Registry::get("mysidia");

        
$userfavpet $mysidia->db->select("users_profile", array("favpet"), "username = '{$mysidia->user->username}'")->fetchColumn(); 
        if (
$this->userfavpet == "0"){
            
$this->FavPetSB = new Paragraph
            
$this->FavPetSB->add(new Comment("<b>No Favorite Pet Set</b>"));
        }
        else{
            
$adopt = new OwnedAdoptable($userfavpet);
            
$this->FavPetSB = new Paragraph
            
$this->FavPetSB->add(new Comment("<b>Favorite Pet!</b> <br/>
                <a href='/myadopts/manage/
{$userfavpet}'><img src='{$adopt->getImage()}'></a>
                "
));
        }

        
$this->setDivision($this->FavPetSB);
    } 

Using "$adopt = new OwnedAdoptable($userfavpet);" you can also pull up data like {$adopt->getName()} and {$adopt->getCurrentLevel()} - these are functions found in classes/class_ownedadoptable.php, but you should also be able to use {$adopt->type} (which is not a function) to pull raw data from the database from the 'type' column - this holds the species.

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:

Ittermat 03-05-2016 05:31 PM

thank you! I'll mess with it and get back to you after I eat dinner!! ^^

Ittermat 03-05-2016 05:53 PM

Yup Got him in the sidebar! Whats next? ^___^

Corsair 03-06-2016 11:23 AM

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.

Ittermat 03-06-2016 11:47 AM

Of course not! Lol ^^

Ittermat 03-07-2016 05:38 PM

Also another question- what if I wanted that pet to randomly find items or money- or have "fake" Status effects happen to it?

Kyttias 03-07-2016 06:49 PM

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.)

Ittermat 03-07-2016 07:33 PM

no its fine! get some rest! Help me when you can ^^ thank you!! <3

Kyttias 03-08-2016 11:19 AM

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:

$status_chance mt_rand(1100);  
if (
$status_chance <= 1){ # One percent chance the pet will obtain a status effect.
    /* We would apply a status effect here...*/
} else { # Ninety-nine percent chance the pet will not get a status effect. Will something else happen?
    
$something_chance mt_rand(1100); 
    if (
$something_chance <= 25){ # Twenty-five percent chance something will happen.
        
$gift_chance mt_rand(1100); 
        if (
$gift_chance <= 5){ # Five percent chance the user will receive a gift from their pet.
            
$item_chance mt_rand(1100);
            if (
$item_chance <= 50){ # Fifty percent chance the gift from their pet will be an item.
                /* The pet has found an item for you! */ 
            
} else { # Fifty percent chance the gift from their pet will be money.
                /* The pet has found some money for you! */
            
}
        } else { 
# Twenty percent chance the pet will talk but have no gift.
            /* No gift will be given but a neat species-specific phrase can still be said! */
        
}
    } else { 
# Seventy-five percent chance nothing will happen whatsoever.
        /* Nothing will happen with the pet at all. */
    
}


Basically, just a tower of if-else statements so far, using PHP's built in mt_rand() function - we're feeding it the numbers 1 and 100 so it'll choose a random number between the two, just like rolling (if possible) a 100-sided dice. It's the easiest way to fudge in percents.

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.


All times are GMT -5. The time now is 10:11 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.