Jump to content
MakeWebGames

Raffle Modification


Recommended Posts

Screen Shots -

 

[ATTACH=CONFIG]1472[/ATTACH]

[ATTACH=CONFIG]1473[/ATTACH]

[ATTACH=CONFIG]1474[/ATTACH]

 

SQLs -

 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

 

Call this file raffle.php -

 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

 

Make a daily cron -

 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

 

[ATTACH=CONFIG]1475[/ATTACH]

 

There you go and your done.

1919030955_ScreenShot2014-05-20at14_23_34.png.b57be29e09dc80bef2954bdf239514dc.png

1909859498_ScreenShot2014-05-20at14_24_12.png.63d63d962c418416e12aa69452135630.png

1929907899_ScreenShot2014-05-20at14_24_391.png.9b3107a02691a05ad0f7d0f110ac9c47.png

Raffle.zip

Link to comment
Share on other sites

[MENTION=68736]Raven1992[/MENTION] -

Or just add this bit to your cron_day.php -

 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

To change the prizes to your likings.

Go to your database find the table "settings"

Edit -

payment-one_raffle

payment-two_raffle

payment-three_raffle

However when someone buys a ticket. It gives a bigger reward.

Link to comment
Share on other sites

Nice modification, Well done with it buddy!

After testing though, I noticed that 1 player can come in at more than 1 place.

Example: Congrats, You won the 1st prize! - Congrats, You won the 2nd prize! (In 1 raffle - So you can be the winner and the second place winner so on.)

Just thought I'd point that out ^_^

Other than that, Great mod! :)

Keep up the good work!

Link to comment
Share on other sites

Not bad but you should make this a bit more easily customizable. For example a setting for what the tickets are called. What if I want to call them something other than tickets? Or a setting to set the price of each ticket? And why not allow for the players to have a form to purchase tickets in bulk with a setting for the maximum amount of tickets they can purchase?

Link to comment
Share on other sites

First thing;

RAND() at mysql level is pretty heavy on the resources.

Second thing;

Why can't I win twice? If I buy 2 tickets in the lottery and both win with 3 numbers, I am entitled to both!

Third;

I'd do it at PHP level, since you can manipulate the data and create the winners pretty easily (And you can edit to just 1 prize per person easily too)

 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

That renders $winners[0] as first prize, $winners[1] as second and $winners[2] as third.

Much easier to then issue events and whatnot.

To limit the wins to once per player, add a group by in the clause - simples.

 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

to

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

As always, untested. Any problems, post here and somebody may help.

Link to comment
Share on other sites

First thing;

RAND() at mysql level is pretty heavy on the resources.

Second thing;

Why can't I win twice? If I buy 2 tickets in the lottery and both win with 3 numbers, I am entitled to both!

Third;

I'd do it at PHP level, since you can manipulate the data and create the winners pretty easily (And you can edit to just 1 prize per person easily too)

 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

That renders $winners[0] as first prize, $winners[1] as second and $winners[2] as third.

Much easier to then issue events and whatnot.

To limit the wins to once per player, add a group by in the clause - simples.

 

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

to

You're unable to view this code.

Viewing code within this forum requires registration, you can register here for free.

 

As always, untested. Any problems, post here and somebody may help.

 

What MySQL's RAND is CPU intensive and iterating through potentially millions of records isn't?

Also, wouldn't shuffle give a random order? Theres no reason to then do some sort of awkward split; $first[0], $second[1] and $third[2] is fine. Theres no need to over-complicate things.

Link to comment
Share on other sites

If it's slow then just do it differently....

SELECT MAX(`id`) as `max_id` FROM `lottery`;

Use that to generate three numbers.... (self explanatory) and then just select them IDs.

SELECT * FROM `lottery` WHERE `id` IN (X1, X2, X3);

X1 X2 & X3 of course being the three random ID's. This way no iterations are being done, just two queries with not much going on, just logic.

Link to comment
Share on other sites

What MySQL's RAND is CPU intensive and iterating through potentially millions of records isn't?

Also, wouldn't shuffle give a random order? Theres no reason to then do some sort of awkward split; $first[0], $second[1] and $third[2] is fine. Theres no need to over-complicate things.

You are kind of getting it, I guess.

We all (meaning a few people) know that random factors are not all that random.

Shuffle shuffles the deck of data - then to add more randomness, you select a place in the shuffles array to select from.

 

In theory, this could be done quicker too, but I'm unsure on what resources would be used and you'd have to, in theory, query twice... But this is an option...

Pull all rows in a query and get the count, then just randomly split it somewhere and use LiMiT xx, 3 in the secondary query.

If there was no use in "over complicating" things, half the functions within the manual wouldn't exist as there are simpler methods to most things ;)

Link to comment
Share on other sites

If your point is that random number generators aren't really random then it won't help anything to do it twice (shuffle->random). Keep it simple and use rand(). Most mccode games doesn't have the userbase to make server load a big issue anyway.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...