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)
-   -   Choose 3 random adopts... (http://www.mysidiaadoptables.com/forum/showthread.php?t=5063)

SilverDragonTears 03-04-2016 10:26 PM

Choose 3 random adopts...
 
I want to choose 3 random adopts at a time and show them in a single row. I had this on my old site but can't quite figure it out with this new coding.

Kyttias 03-05-2016 10:14 AM

I made a mod that allows for a more customizable index page (rather than using the AdminCP), and it will allow you to use PHP. In the mod I also included example code for displaying five random pets. Check it out!

The exact code snippet for the random pets is this:
PHP Code:

$document->add(new Comment("<div class='row'><h4>Random 5 Pets</h4>"FALSE));
        
$stat_rand5 $mysidia->db->select("owned_adoptables", array("aid"), "1 ORDER BY RAND() DESC LIMIT 5");        
        while(
$aid $stat_rand5->fetchColumn()){
            
$adopt = new OwnedAdoptable($aid);    
            
$document->add(new Comment("
                <div style='display: inline-table; text-align: center;'>
                <a href='levelup/click/
{$adopt->getAdoptID()}'><img src='{$adopt->getImage()}'></a></br>
                  <a href='levelup/click/
{$adopt->getAdoptID()}'><b>{$adopt->getName()}</b></a> the <small><b>LVL.</b> {$adopt->getCurrentLevel()}</small> {$adopt->getType()}</div>
              "
FALSE));
        }
        
$document->add(new Comment("</div>"FALSE)); 

If you want three instead of five, all you have to do is edit "1 ORDER BY RAND() DESC LIMIT 5" to "1 ORDER BY RAND() DESC LIMIT 3". :meow:

SilverDragonTears 03-05-2016 01:05 PM

I meant on the adopt a (dragon) page.

tahbikat 03-05-2016 02:39 PM

@Kyttias I think she means something similar to Dragon Cave, where 3 random eggs are shown on the adopts page and if a user clicks it before another user they get the egg.


@Birdie I don't think there's a mod here for that yet but good luck!

Kyttias 03-05-2016 03:20 PM

Oh... hmmm! That's done on Pokéfarm, too...

So let's see... three eggs, when one is taken three things should be done:
  • See if that egg is still available (by checking against timestamp), if true, continue.
  • Store a 'claimed' timestamp when the egg is successfully picked up.
  • Reshuffle the eggs (include the two unclaimed and add a random third).

The three random eggs are shuffled server-side and stored in the database. When the page loads, it'll access the database and pull up the shuffled set of eggs with the most recent 'creation' timestamp. The data will also be stored with a 'claimed' timestamp, which will be filled moments before a new row is created upon a new shuffle.

Two other things to consider:

We don't want to store an infinite number of shuffled egg sets in the database, so to save on database space will will also look for the row with the oldest 'claimed' timestamp and remove it while creating a new one.

We also don't necessary want eggs to stagnate. Considerations will have to be made about that. Ordinarily we'd want the two eggs that weren't claimed to stay there for the next refresh... but what if we want to force these eggs to change? I think a good time to do this would be test how long it's been since that egg set was created. If it took more than an hour for one of the three to be claimed, randomize all three eggs going into the next draw.

Is this all heading in the right direction? :meow:

SilverDragonTears 03-05-2016 08:42 PM

I was using a very old script from Mys/ my site was well established and I already had the code for this. But I don't know how to read this newer stuff and I taught myself php so I'm not that great with reading new code or understanding it :(


All times are GMT -5. The time now is 04:18 AM.

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