Jump to content
MakeWebGames

Lottery


TheMasterGeneral

Recommended Posts

What's up dude. I've made a small lottery mod. Haven't really tested it, but should work as is. If it doesn't, reply here.

Yes, there's probably many lottery mods, but I threw this together in 5 minutes for my game. If it works for you, great. If not, I'm sorry. No need to flame me for making another lottery mod. :( </3

Things to note, however:

  • There is a few values you can adjust completely. (I've left comments where you can)
  • This is FREE.

 

Trivia:

  • This originally was going to be a scratch-ticket mod.

 

Swag that comes along with this:

  • One File
  • One SQL
  • A hug1. :)

 

SQL:

You're unable to view this code.

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

 

 

Call this lottery.php

You're unable to view this code.

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

 

 

If you have any questions, comments, concerns or otherwise feedback, please feel free to leave a reply!

1=Redeemable for only five minutes after this post.

Link to comment
Share on other sites

It's a good mod but would inflat a game in my opinion, maybe try letting users to play once a day and let a cron run to choose a random winner because a user could keep playing and playing with a limit

Yeah I agree with this.

Another idea is to create your own odds:

 

You're unable to view this code.

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

That should work, and allows you to change the odds of winning. I believe there is a 1 in 10 chance with my code, you can make it better or worse.

Link to comment
Share on other sites

@AMTheMasterGeneral The chances of winning make it difficult for players to see any benefit from playing. If you consider that slot machines often have payout percentages set to 95%, so a player playing 100 times at a cost of $10 per game would have in their pocket at the end of the day 95% * 100 * $10 or $950. This suggests to the players that they may win more whereas your payout would appear to be 1%. Not very enticing.

 

... i think you should put some more rands in ...
Why? How many do you need to determine if somebody has won or not?

 

... let a cron run to choose a random winner because a user could keep playing and playing ...
No need, at only a 1% payout, they will quickly run out of money. From a full featured lottery I might initially agree, though again I see no need for crons. There are plenty of ways to avoid their use.

 

... Another idea is to create your own odds ...
He did and in a lot more elegant method than any array.

mt_rand(1, 2) is 1 50% of the time

mt_rand(1, 3) is 1 33.333% of the time

mt_rand(1, 4) is 1 25% of the time

etc etc

or:

mt_rand(1, 100) is less than 100 99% of the time

mt_rand(1, 100) is less than 99 98% of the time

mt_rand(1, 100) is less than 98 97% of the time

etc etc.

it's a lot more manageable from the point of view of supporting code to use the simplest expression possible, in this case it could be argued that storing the upper bound in a configuration file / settings table would suffice rather having to edit an array of 1's and 0's every time.

 

jm2c

Link to comment
Share on other sites

rand() uses the system's own random number generator tools which are not always ideal, mt_rand() uses a decent algorithm that in general produces better randomness. mt_rand() is also reportedly faster, though I've never found the need to generate sufficient random numbers individually to warrant speed testing it.

As an analogy, I'd compare rand() to an old dice that has been the family for a while, it has become slightly worn, has a couple of rough edges, and throws a 6 slightly more than 16.6% of the time. mt_rand() on the other hand is a nice shiny new dice straight from the manufacturer and has been thoroughly tested with a micrometer by a casino pit boss. Not entirely accurate, but sufficient for MWG purposes.

Link to comment
Share on other sites

[MENTION=70654]Jax[/MENTION] , I love how you take someone's legitimate answers and tear them shreds.. Do you consider the reasoning behind it, or do you just go by what makes more sense according to the PHP handbook? Yes my answer is basically the same as mt_rand(0,50); but when you create an array, shuffle it, and use a random function to select a certain value of an area, you are somewhat controlling the odds but keeping the randomness to it.

It works a hell of a lot better for slot machines, admittedly.

 

Not entirely accurate, but sufficient for MWG purposes.

I sort of meant what I said before about loving how you tear people's answers to shreds, because clearly you have a great knowledge of php, but after this I've lost some respect. I read that and to me it seems like your saying MWG isn't good enough to know the differences between one php function and another? As if the people on here are juniors and below the need/ability to understand why someone might use rand(); rather than mt_rand(); or vice versa.

 

From the php manual :

Many random number generators of older libcs have dubious or unknown characteristics and are slow. By default, PHP uses the libc random number generator with the rand() function. The mt_rand() function is a drop-in replacement for this. It uses a random number generator with known characteristics using the » Mersenne Twister, which will produce random numbers four times faster than what the average libc rand() provides.

Link to comment
Share on other sites

[MENTION=70654]Jax[/MENTION] thank you for the input. I've switched the random variables around. I just set it, in my personal game, to mt_rand(1,20); Which gives 5% chance to win, rather than 1%

I might adjust it if I see fit, however, I think its fine right now.

[MENTION=70283]Samurai Legend[/MENTION], thanks dude. :D

[MENTION=69823]jcvenom[/MENTION] , It really wouldn't inflate the game, imo. It really only adds 100K cash to the economy, the rest is just transferred from many players, into one, if they win. However, there is a configuration area at the top of the code, you could probably use that to adjust it to your economy.

Link to comment
Share on other sites

  • 4 weeks later...
  • 1 month later...

Just a suggestion for game owners.

If you're looking for something extra to give your donators then you can quite easily use the lottery both for standard users and donators. But you can give your donators a higher chance of winning

This can be done within the same file, but I havent done that, didnt think about it until now...

Anyway, simply create a second file called donlottery.php, copy the original lottery code into it and change the one reference that reads lottery.php to donlottery.php

Then you can alter the random chance ratio and even price etc

You will also need to place this at the top of donlottery.php

You're unable to view this code.

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

Link to comment
Share on other sites

Yeah I agree with this.

Another idea is to create your own odds:

 

You're unable to view this code.

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

That should work, and allows you to change the odds of winning. I believe there is a 1 in 10 chance with my code, you can make it better or worse.

Minor update recommendation. Create a blank array and stick a for() loop in there to populate it.

Saves time (and your keyboard!)

Untested

You're unable to view this code.

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

^ would be a 3 in 23 chance of winning

Edited by Magictallguy
Changed "^ would be a 3 in 20 chance of winning" to "^ would be a 3 in 23 chance of winning"
Link to comment
Share on other sites

Aye, that's right.. I was just testing you ... [insert shifty side-glance here]

lol when it comes to maths your testing the wrong person ;) currently studying maths and further maths for A-Level with a side of physics aha. My brain is practically maths lol

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