Getting Dinos raffle mod to work on its own

Forum
Last Post
Threads / Messages

Ittermat

The awesomesauce
Member
Joined
Feb 2, 2016
Messages
304
Points
18
Location
in front of my laptop
Mysidian Dollar
21,294
Okay so! Im gonna say straight up im not a coder- BUT I've at least figured this out in my own way- and maybe someone who knows more than me can help us find a better way- but if you all want a FOR NOW Solution to the raffle starting and ending by itself- here you go.

I spent 3 days figuring this out-

To start with- This is the raffle mod Im talking about - https://forums.mysidiaadoptables.com/index.php?threads/raffle-mod.3715/

And Im using Dinos Crons for this- https://dinoscripts.wordpress.com/mods/using-cron-jobs/

So lets get into it yea?? (MAKE SURE TO BACKUP YOUR FILES FIRST! ALWAYS)

First you want to add two things to the adopts_users Database- rafflewin and rafflestart- they should look like this-


unknown.png
unknown.png


Then we go to our Actual raffleview page-

The highlighted areas are what you add in and where- (I'll add the code to copy paste below each pic and I removed the input->post for the buttons I just figured a visual would help also)

unknown.png

PHP:
 //This part picks a winner from the database
if ($mysidia->user->rafflewin == 1) {
//This checks if any tickets have been bought.
if($ticketcheck < 1){
$document->add(new Comment("<font color='red'>Last raffle had no entries! A winner was not chosen.</font>"));
  $mysidia->db->update("users", array("rafflewin" => (3)));
 $document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />"));
}
else{
$winner = $mysidia->db->select("raffle_tickets", array("owner"), "1 ORDER BY RAND() DESC LIMIT 1")->fetchColumn();
$winnermoneycheck = $mysidia->db->select("users", array("money"), "username = '$winner'")->fetchColumn();
$mysidia->db->update("users", array("money" => ($winnermoneycheck + $pool)), "username = '$winner'");
$document->add(new Comment( "<font color='green'>{$winner} won {$pool} CURRENCY from the raffle!</font>"));

$mysidia->db->query("TRUNCATE TABLE adopts_raffle_tickets");
$mysidia->db->query("TRUNCATE TABLE adopts_raffle");
$pm = new PrivateMessage(); // Send the winner a pm
    $pm->setsender('SYSTEM');
    $pm->setrecipient($winner);
   $pm->setmessage("Raffle prize", "You won the raffle! Congratulations! {$pool} CURRENCY has been added to your account.");
   $pm->post();
   $document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />"));
   $mysidia->db->update("users", array("rafflestart" => (2)));
   $mysidia->db->update("users", array("rafflewin" => (3)));
 
return TRUE;

Then the next part same page-

unknown.png


PHP:
//This starts a new raffle. For good measure, it deletes the previous raffle before making a new one.
if ($mysidia->user->rafflestart == 2) {
$mysidia->db->query("TRUNCATE TABLE adopts_raffle_tickets");
$mysidia->db->query("TRUNCATE TABLE adopts_raffle");
$mysidia->db->insert("raffle", array("pool" => 0));
$document->add(new Comment( "A new raffle has been started."));

$mysidia->db->update("users", array("rafflestart" => (3)));
$mysidia->db->update("users", array("rafflewin" => (3)));
$document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />"));
return TRUE;
}
 
           
       //This part adds the number of tickets the user buys to the database
       if ($mysidia->user->rafflestart == 3) {
if($mysidia->input->post("buy")){
$chosenOption = $mysidia->input->post("myList");
    if($chosenOption == "5"){
        if($moneyvalidate < 25){
               $document->add(new Comment("You cannot afford this!"));
               $document->add(new Comment("<meta http-equiv='refresh' content='1;url=raffle' />"));
               return TRUE;
               }
What this does- just so you understand whats happening here- The cron job (which we're gonna add here in a second,) Is changing the value of raffle win to 1. once it does that- it changes the two other values- Rafflewin to 3 and rafflestart to 2- once raffle start is 2 the raffle starts- setting itself to 3 and raffle win also to 3- so they wont run again until the cron sets rafflewin to 1 again-

and then setting rafflestart to 3 also lets you buy the tickets. Its kinda convoluted and confusing- I know- but it works.

Alright now to do the cron part.


Go into Your cpanel and go down to cron jobs-

and go into common settings- set a new cron to this- with this command- You can choose the common settings for once weekly in the dropdown) Changing yoursite to well your url of course!

curl https://(yoursite).mysidiahost.com/cron/week



unknown.png


Next we go to the public_Html ->cron file

And add in public function week (code to copy is below image)

unknown.png



Code:
              public function week(){
        $mysidia = Registry::get("mysidia");
        $mysidia = Registry::get("mysidia");
        $mysidia->db->update("users", array("rafflewin" => '1',));

    }


And there you have it! You can start it by going back into the DB and setting the rafflewin to 1 and then letting the page refresh a few times and it should work!

If it doesnt I dunno if I can help XD But it works for me!

Heres to winning big onsite currency for your users!
 
Last edited:

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,267
Messages
33,048
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top