Choose 3 random adopts...

Forum
Last Post
Threads / Messages

SilverDragonTears

I am your Nemesis.
Premium Member
Joined
Jun 1, 2011
Messages
1,113
Points
36
Mysidian Dollar
51,802
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.
 
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:
$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:
 
@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!
 
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:
 
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 :(
 

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