-BRAIDZ- Posted June 4, 2015 Share Posted June 4, 2015 (edited) So i got bored and wanted to have a go at doing a lottery module i think it turned out all right in the end Lets start with the SQL files CREATE TABLE IF NOT EXISTS `lottery` ( `lotofund` int(30) NOT NULL DEFAULT '0', `tickets` int(30) NOT NULL DEFAULT '0' ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; INSERT INTO `lottery` (`lotofund`, `tickets`) VALUES (0, 0); CREATE TABLE IF NOT EXISTS `lottery_players` ( `user` int(30) NOT NULL DEFAULT '0', `tickets` int(10) NOT NULL DEFAULT '0' ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; CREATE TABLE IF NOT EXISTS `lotowinners` ( `user` int(20) NOT NULL DEFAULT '0', `amountwon` int(50) NOT NULL DEFAULT '0' ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci; CREATE TABLE IF NOT EXISTS `lottery_config` ( `ticketprice` int(30) NOT NULL DEFAULT '0', `maxtickets` int(30) NOT NULL DEFAULT '0', `pagedisable` enum('Yes','No') NOT NULL DEFAULT 'No' ) ENGINE=MyISAM DEFAULT CHARSET=latin1; INSERT INTO `lottery_config` (`ticketprice`, `maxtickets`, `pagedisable`) VALUES (1000, 10, 'No'); ALTER TABLE `grpgusers` ADD `tickets` INT(30) NOT NULL DEFAULT 0; open up classes.php and add this to the user class $this->tickets = $worked['tickets']; You can add this to your style sheet if you have one if not add it into the header.php .infobox { background: #101010; width: 200px; height: auto; border: 1px solid gray; border-radius: 5px; padding: 10px; float: left; text-align: center; } .otherbox { background: #101010; width: 400px; height: auto; border: 1px solid gray; border-radius: 5px; padding: 4px; float: right; text-align: center; } .buysection,.infobox { margin-top: 5px; } .btn { background: #585858; width: auto; height: auto; border: 1px solid black; border-radius: 3px; } .input { background: #202020; color: #FFFFFF; border: 1px solid black; padding: 1px; } Ok now time for the files. lottery.php <?php include(__DIR__.'/header.php'); $res = mysql_query("SELECT * FROM `lottery`"); $row = mysql_fetch_array($res); $checkp = mysql_query("SELECT * FROM `lottery_players` WHERE `user` = ".$user_class->id); $num = mysql_num_rows($checkp); $checkt = mysql_fetch_array($checkp); $config = mysql_query("SELECT * FROM `lottery_config`"); $worked = mysql_fetch_array($config); if($worked['pagedisable'] == 'Yes') { echo Message('Admin has disabled the Lottery Page.'); include_once(__DIR__.'/footer.php'); exit; } $_POST['amount'] = isset($_POST['amount']) && ctype_digit($_POST['amount']) ? abs(intval($_POST['amount'])) : null; if(array_key_exists('buy', $_POST)) { if(empty($_POST['amount'])) { echo Message("You didn't enter a valid amount"); include(__DIR__ . '/footer.php'); exit; } $cost = $worked['ticketprice'] * $_POST['amount']; $usercash = $user_class->money - $cost; $tickets = $user_class->tickets + $_POST['amount']; $loto = $row['lotofund'] + $cost; $ltick = $row['tickets'] + $_POST['amount']; $deficit = $worked['maxtickets'] - $user_class->tickets; $havetick = $checkt['tickets'] + $_POST['amount']; if($tickets > $worked['maxtickets']) { echo Message('The max tickets is '.number_format($worked['maxtickets']).'. This means you can only buy '.number_format($worked['maxtickets'] - $user_class->tickets).' more ticket'.($deficit == 1 ? '' : 's')); include_once(__DIR__.'/footer.php'); exit; } if($_POST['amount'] > $worked['maxtickets']) { echo Message('You can only purchase '.number_format($worked['maxtickets'])); include_once(__DIR__.'/footer.php'); exit; } if($user_class->money < $worked['ticketprice']) { echo Message('You cant afford '.number_format($_POST['amount']).' tickets. It costs $'.number_format($worked['ticketprice'] * $_POST['amount'])); include_once(__DIR__.'/footer.php'); exit; } if($user_class->tickets > $worked['maxtickets']) { echo Message('You have already purchased max tickets which is '.number_format($worked['maxtickets'])); include_once(__DIR__.'/footer.php'); exit; } if($user_class->money >= $worked['ticketprice'] && $_POST['amount'] <= $worked['maxtickets']) { if($num) { echo Message('You have purchase '.$_POST['amount'].' lottery tickets for $'.number_format($cost)); mysql_query("UPDATE `grpgusers` SET `money` = ".$usercash.", `tickets` = ".$tickets." WHERE `id` = ".$user_class->id); mysql_query("UPDATE `lottery` SET `lotofund` = ".$loto.", `tickets` = ".$ltick); mysql_query("UPDATE `lottery_players` SET `tickets` = ".$havetick." WHERE `user` = ".$user_class->id); } else { echo Message('You have purchase '.$_POST['amount'].' lottery tickets for $'.number_format($cost)); mysql_query("UPDATE `grpgusers` SET `money` = ".$usercash.", `tickets` = ".$tickets." WHERE `id` = ".$user_class->id); mysql_query("UPDATE `lottery` SET `lotofund` = ".$loto.", `tickets` = ".$ltick); mysql_query("INSERT INTO `lottery_players` VALUES('$user_class->id',".$_POST['amount'].")"); } } } ?> <tr><td class="contenthead">Lottery</td></tr> <tr><td class="contentcontent"> <div class="infobox"> <span>Welcome to the lottery</span> <span>Each ticket costs $<?php echo number_format($worked['ticketprice']); ?></span> <span>Maximum of <?php echo number_format($worked['maxtickets']); ?> tickets per person</span> </div> <div class="otherbox"> <span>Lottery Fund: $<?php echo number_format($row['lotofund']); ?></span> <span>Tickets Purchased: <?php echo number_format($row['tickets']); ?></span> </div> </td></tr> <tr><td class="contentcontent"> <div class="buysection"> <form method="post"> [buy Tickets] <input type="text" name="amount" value="1" maxlength="2" /> <input type="submit" name="buy" value="Buy Ticket" /> </form> </div> </td></tr> <tr><td class="contenthead">Previous Winners</td></tr> <tr><td class="contentcontent"> <?php $win = mysql_query("SELECT * FROM `lotowinners`"); $check = mysql_num_rows($win); while($row = mysql_fetch_array($win)) { $user = new User($row['user']); if($check == 0) { echo "<div class='infobox'><span>There has been no previous Winners</span></div>"; } else { echo " <table class='infobox'> <tr> <td>".$user->formattedname." - $".number_format($row['amountwon'])."</td> </tr>"; } echo "</table>"; } ?> </td></tr> lottery_config.php <?php include(__DIR__.'/header.php'); $allowed = array(1,2); if($user_class->id != in_array(1,$allowed)) { echo Message('You are not allowed here.'); include_once(__DIR__.'/footer.php'); exit; } $res = mysql_query("SELECT * FROM `lottery_config"); $row = mysql_fetch_array($res); if(isset($_POST['disable'])) { if($row['pagedisable'] == 'No') { echo Message('You have disabled the lottery page'); mysql_query("UPDATE `lottery_config` SET `pagedisable` = 'Yes' WHERE `pagedisable` = 'No'"); } else if($row['pagedisable'] == 'Yes') { echo Message('You have enabled the lottery page.'); mysql_query("UPDATE `lottery_config` SET `pagedisable` = 'No' WHERE `pagedisable` = 'Yes'"); } } $_POST['price'] = isset($_POST['price']) && ctype_digit($_POST['price']) ? abs(intval($_POST['price'])) : null; if(isset($_POST['setprice'])) { if(empty($_POST['price'])) { echo Message('Invalid Price'); include_once(__DIR__.'/footer.php'); exit; } if(!is_numeric($_POST['price'])) { echo Message('Price must be a number.'); include_once(__DIR__.'/footer.php'); exit; } if($_POST['price'] == $row['ticketprice']) { echo Message('It is already set to that nothing has changed.'); include_once(__DIR__.'/footer.php'); } if($_POST['price'] != $row['ticketprice']) { echo Message('You have updated the price to $'.number_format($_POST['price'])); mysql_query("UPDATE `lottery_config` SET `ticketprice` = ".$_POST['price']); } } $_POST['tickets'] = isset($_POST['tickets']) && ctype_digit($_POST['tickets']) ? abs(intval($_POST['tickets'])) : null; if(isset($_POST['settickets'])) { if(empty($_POST['tickets'])) { echo Message('Invalid Price'); include_once(__DIR__.'/footer.php'); exit; } if(!is_numeric($_POST['tickets'])) { echo Message('Tickets must be a number.'); include_once(__DIR__.'/footer.php'); exit; } if($_POST['ticketprice'] == $_POST['tickets']) { echo Message('It is already set to this so nothing has changed.'); include_once(__DIR__.'/footer.php'); } if($_POST['tickets'] != $row['maxtickets']) { echo Message('You have updated the max tickets to '.number_format($_POST['tickets'])); mysql_query("UPDATE `lottery_config` SET `maxtickets` = ".$_POST['tickets']); } } ?> <tr><td class="contenthead">Lottery Panel</td></tr> <tr><td class="contentcontent"> <table width="100%" style="background: #101010" cellpadding="5"> <tr> <td> <span>Disable/Enable Lottery Page<span> <form method="post"> <?php if($row['pagedisable'] == 'No') { echo ' <input type="submit" name="disable" class="btn" value="Disable Page" />'; } if($row['pagedisable'] == 'Yes') { echo ' <input type="submit" name="disable" class="btn" value="Enable Page" />'; } ?> </form> </td> </tr> <tr> <td> <hr> <i>Set Ticket Price</i> <form method="post"> Price: <input type="text" name="price" value="0" class="input" /> <input type="submit" name="setprice" class="btn" value="Set Ticket Price" /> </form> </td> </tr> <tr> <td> <hr> <i>Set Max Tickets per person</i> <form method="post"> Max Tickets: <input type="text" name="tickets" value="0" class="input" /> <input type="submit" name="settickets" class="btn" value="Set Max Tickets" /> </form> </td> </tr> </table> </td></tr> lot_cron.php <?php include('dbcon.php'); include('classes.php'); if(isset($_GET['code']) != 'Your code here') { echo "<span style='color:red'><h2>Error</h2></span>"; exit; } else { $res = mysql_query("SELECT * FROM `lottery_players` ORDER BY RAND() LIMIT 1"); $checkwinner = mysql_num_rows($res); while($row = mysql_fetch_array($res)) { if($checkwinner == 0) { } else { $winner = new User($row['user']); $check = mysql_query("SELECT * FROM `lottery`"); $worked = mysql_fetch_array($check); Send_Event($winner->id, "Congrats you have won the lottery your prize is $".number_format($worked['lotofund'])); mysql_query("UPDATE `grpgusers` SET `money` = `money` + {$worked['lotofund']} WHERE `id` = ".$winner->id); mysql_query("UPDATE `lottery` SET `lotofund` = '0',`tickets` = '0'"); mysql_query("UPDATE `grpgusers` SET `tickets` = '0' WHERE `tickets` > '0'"); mysql_query("INSERT INTO `lotowinners` VALUES('$winner->id',".$worked['lotofund'].")"); mysql_query("TRUNCATE TABLE `lottery_players`"); } } } ?> ok some screenshots [ATTACH=CONFIG]1372[/ATTACH][ATTACH=CONFIG]1373[/ATTACH][ATTACH=CONFIG]1374[/ATTACH] Is this for MCC? Looks pretty good :) Sorry didn't see that it was in Generic RPG section. Wouldn't mind finding one similar to this one for MCcodes/Ravan's Edited June 4, 2015 by -BRAIDZ- Quote Link to comment Share on other sites More sharing options...
AdamHull Posted June 4, 2015 Share Posted June 4, 2015 There is already lotto mods for mccodes which just need converting to the new style the link for the forum post is http://makewebgames.io/showthread.php/44832-Lottery-System?highlight=lottery Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted June 4, 2015 Author Share Posted June 4, 2015 There is already lotto mods for mccodes which just need converting to the new style the link for the forum post is http://makewebgames.io/showthread.php/44832-Lottery-System?highlight=lottery Yes I have already seen that one, I don't like the idea of selecting your own numbers, way too time consuming. And too much confusion, I'd rather a set price for just tickets, so there is one winner a week. If you get what I mean? Sort of like the lottery on torn? Quote Link to comment Share on other sites More sharing options...
AdamHull Posted June 4, 2015 Share Posted June 4, 2015 (edited) So here is a quick conversion off the file Add this to cron_day $res = $db->query("SELECT * FROM `lottery_players` ORDER BY RAND() LIMIT 1"); $checkwinner = $db->num_rows($res); $row = $db->fetch_row($res); if($checkwinner == 0) { echo "There is no winners yet!"; } else { $check = $db->query("SELECT * FROM `lottery`"); $worked =$db->fetch_row($check); event_add($row['user'], "Congrats you have won the lottery your prize is $".number_format($worked['lotofund'])); $db->query("UPDATE `users` SET `money` = `money` + ".$worked['lotofund']." WHERE `userid` = ".$row['user'].""); $db->query("UPDATE `lottery` SET `lotofund` = '0',`tickets` = '0'"); $db->query("UPDATE `users` SET `tickets` = '0' WHERE `tickets` > '0'"); $db->query("INSERT INTO `lotowinners` VALUES({$row['user']},{$worked['lotofund']})"); $db->query("TRUNCATE TABLE `lottery_players`"); } This is the main lottery file lottery.php <?php require("globals.php"); $res = $db->query("SELECT * FROM `lottery`"); $row = $db->fetch_row($res); $checkp = $db->query("SELECT * FROM `lottery_players` WHERE `user` = {$ir['userid']}"); $num = $db->num_rows($checkp); $checkt = $db->fetch_row($checkp); $config = $db->query("SELECT * FROM `lottery_config`"); $worked = $db->fetch_row($config); if($worked['pagedisable'] == 'Yes') { echo 'Admin has disabled the Lottery Page.'; $h->endpage();; } $_POST['amount'] = isset($_POST['amount']) && ctype_digit($_POST['amount']) ? abs(intval($_POST['amount'])) : null; if($_POST['buy']) { if(empty($_POST['amount'])) { echo "You didn't enter a valid amount"; $h->endpage();; } $cost = $worked['ticketprice'] * $_POST['amount']; $usercash = $ir['money'] - $cost; $tickets = $ir['tickets'] + $_POST['amount']; $loto = $row['lotofund'] + $cost; $ltick = $row['tickets'] + $_POST['amount']; $deficit = $worked['maxtickets'] - $ir['tickets']; $havetick = $checkt['tickets'] + $_POST['amount']; if($tickets > $worked['maxtickets']) { echo "The max tickets is ".number_format($worked['maxtickets'])." This means you can only buy ".number_format($worked['maxtickets'] - $ir['tickets'])." more ticket";($deficit == 1 ? '' : 's'); $h->endpage(); } if($_POST['amount'] > $worked['maxtickets']) { echo 'You can only purchase '.number_format($worked['maxtickets']); $h->endpage();; } if($ir['money'] < $worked['ticketprice']) { echo 'You cant afford '.number_format($_POST['amount']).' tickets. It costs $'.number_format($worked['ticketprice'] * $_POST['amount']); $h->endpage();; } if($ir['tickets'] > $worked['maxtickets']) { echo 'You have already purchased max tickets which is '.number_format($worked['maxtickets']); $h->endpage();; } if($ir['money'] >= $worked['ticketprice'] && $_POST['amount'] <= $worked['maxtickets']) { if($num) { echo "You have purchase {$_POST['amount']} lottery tickets for ${number_format($cost)}"; $db->query("UPDATE `users` SET `money` = {$usercash}, `tickets` = {$tickets} WHERE `userid` = ".$userid.""); $db->query("UPDATE `lottery` SET `lotofund` = {$loto}, `tickets` = {$ltick}"); $db->query("UPDATE `lottery_players` SET `tickets` = {$havetick} WHERE `user` = {$ir['userid']}"); } else { echo "You have purchase {$_POST['amount']} lottery tickets for ${number_format($cost)}"; $db->query("UPDATE `users` SET `money` = {$usercash}, `tickets` = {$tickets} WHERE `userid` ={$ir['userid']}"); $db->query("UPDATE `lottery` SET `lotofund` = {$loto}, `tickets` = {$ltick}"); $db->query("INSERT INTO `lottery_players` VALUES('{$ir['userid']}',{$_POST['amount']})"); } } } ?> <table class="table"> <tr><td class="contenthead">Lottery</td></tr> <tr><td class="contentcontent"> <div class="infobox"> <span>Welcome to the lottery</span> <span>Each ticket costs $<?php echo number_format($worked['ticketprice']); ?></span> <span>Maximum of <?php echo number_format($worked['maxtickets']); ?> tickets per person</span> </div> <div class="otherbox"> <span>Lottery Fund: $<?php echo number_format($row['lotofund']); ?></span> <span>Tickets Purchased: <?php echo number_format($row['tickets']); ?></span> </div> </td></tr> <tr><td class="contentcontent"> <div class="buysection"> <form method="post"> [buy Tickets] <input class="lotoinput" type="text" name="amount" value="1" maxlength="2" /> <input type="submit" name="buy" value="Buy Ticket" /> </form> </div> </td></tr> <tr><td class="contenthead">Previous Winners</td></tr> <tr><td class="contentcontent"> <?php $win = $db->query("SELECT * FROM `lotowinners`"); $check = $db->num_rows($win); while($row = $db->fetch_row($win)) { if($check == 0) { echo "<div class='infobox'><span>There has been no previous Winners</span></div>"; } else { echo " <table class='infobox'> <tr> <td>".$row['username']." - $".number_format($row['amountwon'])."</td> </tr>"; } echo "</table>"; } ?> </td></tr> </table> Lottery cofig file lottery_config.php <?php require("globals.php"); if($ir['user_level'] != 2) { exit("You do not have permission to view this page!"); } echo '<h2>Lottery Control Panel</h2>'; echo '<form method="post">'; echo '<h3>Lottery Days</h3>'; echo 'Select how often (days) you want the lottery draw to take place. NOTE: You will need to update the cron job.'; echo "<b>The current setting is: {$set['lottery_days']} days.</b>"; echo '<select name="days"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option></select>'; echo '<h3>Lottery Numbers</h3>'; echo 'Select the amount of numbers you want users to be able to choose from.'; echo "<b>The current setting is: {$set['lottery_numbers']} numbers.</b>"; echo "<input type='text' name='numbers' size='2' maxlength='2' value='{$set['lottery_numbers']}' />"; echo '<h3>Ticket Cost</h3>'; echo 'Select the cost per lottery ticket.'; echo "<b>The current setting is: \${$set['lottery_ticketcost']}.</b>"; echo "$<input type='text' name='cost' value='{$set['lottery_ticketcost']}' />"; echo '<input type="submit" name="update" value="Update" />'; echo '</form>'; if(isset($_POST['update'])) { $days = abs(intval($_POST['days'])); $numbers = abs(intval($_POST['numbers'])); $cost = abs(intval($_POST['cost'])); if ($days > 7) { echo 'The days must be 7 or less!'; } else { if ($numbers < 6 || $numbers > 99) { echo 'The numbers must be greater than 5 and less than 100!'; } else { $db->query("UPDATE settings SET conf_value=$days WHERE conf_name='lottery_days'"); $db->query("UPDATE settings SET conf_value=$numbers WHERE conf_name='lottery_numbers'"); $db->query("UPDATE settings SET conf_value=$cost WHERE conf_name='lottery_ticketcost'"); echo 'Successfully updated!'; }} } $h->endpage(); ?> May be errors in place but it works! lol - - - Updated - - - SQL FILE http://pastebin.com/BrFVEifr Due to forum screwing sql up its in the pastebin link above Edited June 4, 2015 by adamhull Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted June 4, 2015 Share Posted June 4, 2015 So here is a quick conversion off the file Add this to cron_day $res = $db->query("SELECT * FROM `lottery_players` ORDER BY RAND() LIMIT 1"); $checkwinner = $db->num_rows($res); $row = $db->fetch_row($res); if($checkwinner == 0) { echo "There is no winners yet!"; } else { $check = $db->query("SELECT * FROM `lottery`"); $worked =$db->fetch_row($check); event_add($row['user'], "Congrats you have won the lottery your prize is $".number_format($worked['lotofund'])); $db->query("UPDATE `users` SET `money` = `money` + ".$worked['lotofund']." WHERE `userid` = ".$row['user'].""); $db->query("UPDATE `lottery` SET `lotofund` = '0',`tickets` = '0'"); $db->query("UPDATE `users` SET `tickets` = '0' WHERE `tickets` > '0'"); $db->query("INSERT INTO `lotowinners` VALUES({$row['user']},{$worked['lotofund']})"); $db->query("TRUNCATE TABLE `lottery_players`"); } This is the main lottery file lottery.php <?php require("globals.php"); $res = $db->query("SELECT * FROM `lottery`"); $row = $db->fetch_row($res); $checkp = $db->query("SELECT * FROM `lottery_players` WHERE `user` = {$ir['userid']}"); $num = $db->num_rows($checkp); $checkt = $db->fetch_row($checkp); $config = $db->query("SELECT * FROM `lottery_config`"); $worked = $db->fetch_row($config); if($worked['pagedisable'] == 'Yes') { echo 'Admin has disabled the Lottery Page.'; $h->endpage();; } $_POST['amount'] = isset($_POST['amount']) && ctype_digit($_POST['amount']) ? abs(intval($_POST['amount'])) : null; if($_POST['buy']) { if(empty($_POST['amount'])) { echo "You didn't enter a valid amount"; $h->endpage();; } $cost = $worked['ticketprice'] * $_POST['amount']; $usercash = $ir['money'] - $cost; $tickets = $ir['tickets'] + $_POST['amount']; $loto = $row['lotofund'] + $cost; $ltick = $row['tickets'] + $_POST['amount']; $deficit = $worked['maxtickets'] - $ir['tickets']; $havetick = $checkt['tickets'] + $_POST['amount']; if($tickets > $worked['maxtickets']) { echo "The max tickets is ".number_format($worked['maxtickets'])." This means you can only buy ".number_format($worked['maxtickets'] - $ir['tickets'])." more ticket";($deficit == 1 ? '' : 's'); $h->endpage(); } if($_POST['amount'] > $worked['maxtickets']) { echo 'You can only purchase '.number_format($worked['maxtickets']); $h->endpage();; } if($ir['money'] < $worked['ticketprice']) { echo 'You cant afford '.number_format($_POST['amount']).' tickets. It costs $'.number_format($worked['ticketprice'] * $_POST['amount']); $h->endpage();; } if($ir['tickets'] > $worked['maxtickets']) { echo 'You have already purchased max tickets which is '.number_format($worked['maxtickets']); $h->endpage();; } if($ir['money'] >= $worked['ticketprice'] && $_POST['amount'] <= $worked['maxtickets']) { if($num) { echo "You have purchase {$_POST['amount']} lottery tickets for ${number_format($cost)}"; $db->query("UPDATE `users` SET `money` = {$usercash}, `tickets` = {$tickets} WHERE `userid` = ".$userid.""); $db->query("UPDATE `lottery` SET `lotofund` = {$loto}, `tickets` = {$ltick}"); $db->query("UPDATE `lottery_players` SET `tickets` = {$havetick} WHERE `user` = {$ir['userid']}"); } else { echo "You have purchase {$_POST['amount']} lottery tickets for ${number_format($cost)}"; $db->query("UPDATE `users` SET `money` = {$usercash}, `tickets` = {$tickets} WHERE `userid` ={$ir['userid']}"); $db->query("UPDATE `lottery` SET `lotofund` = {$loto}, `tickets` = {$ltick}"); $db->query("INSERT INTO `lottery_players` VALUES('{$ir['userid']}',{$_POST['amount']})"); } } } ?> <table class="table"> <tr><td class="contenthead">Lottery</td></tr> <tr><td class="contentcontent"> <div class="infobox"> <span>Welcome to the lottery</span> <span>Each ticket costs $<?php echo number_format($worked['ticketprice']); ?></span> <span>Maximum of <?php echo number_format($worked['maxtickets']); ?> tickets per person</span> </div> <div class="otherbox"> <span>Lottery Fund: $<?php echo number_format($row['lotofund']); ?></span> <span>Tickets Purchased: <?php echo number_format($row['tickets']); ?></span> </div> </td></tr> <tr><td class="contentcontent"> <div class="buysection"> <form method="post"> [buy Tickets] <input class="lotoinput" type="text" name="amount" value="1" maxlength="2" /> <input type="submit" name="buy" value="Buy Ticket" /> </form> </div> </td></tr> <tr><td class="contenthead">Previous Winners</td></tr> <tr><td class="contentcontent"> <?php $win = $db->query("SELECT * FROM `lotowinners`"); $check = $db->num_rows($win); while($row = $db->fetch_row($win)) { if($check == 0) { echo "<div class='infobox'><span>There has been no previous Winners</span></div>"; } else { echo " <table class='infobox'> <tr> <td>".$row['username']." - $".number_format($row['amountwon'])."</td> </tr>"; } echo "</table>"; } ?> </td></tr> </table> Lottery cofig file lottery_config.php <?php require("globals.php"); if($ir['user_level'] != 2) { exit("You do not have permission to view this page!"); } echo '<h2>Lottery Control Panel</h2>'; echo '<form method="post">'; echo '<h3>Lottery Days</h3>'; echo 'Select how often (days) you want the lottery draw to take place. NOTE: You will need to update the cron job.'; echo "<b>The current setting is: {$set['lottery_days']} days.</b>"; echo '<select name="days"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option></select>'; echo '<h3>Lottery Numbers</h3>'; echo 'Select the amount of numbers you want users to be able to choose from.'; echo "<b>The current setting is: {$set['lottery_numbers']} numbers.</b>"; echo "<input type='text' name='numbers' size='2' maxlength='2' value='{$set['lottery_numbers']}' />"; echo '<h3>Ticket Cost</h3>'; echo 'Select the cost per lottery ticket.'; echo "<b>The current setting is: \${$set['lottery_ticketcost']}.</b>"; echo "$<input type='text' name='cost' value='{$set['lottery_ticketcost']}' />"; echo '<input type="submit" name="update" value="Update" />'; echo '</form>'; if(isset($_POST['update'])) { $days = abs(intval($_POST['days'])); $numbers = abs(intval($_POST['numbers'])); $cost = abs(intval($_POST['cost'])); if ($days > 7) { echo 'The days must be 7 or less!'; } else { if ($numbers < 6 || $numbers > 99) { echo 'The numbers must be greater than 5 and less than 100!'; } else { $db->query("UPDATE settings SET conf_value=$days WHERE conf_name='lottery_days'"); $db->query("UPDATE settings SET conf_value=$numbers WHERE conf_name='lottery_numbers'"); $db->query("UPDATE settings SET conf_value=$cost WHERE conf_name='lottery_ticketcost'"); echo 'Successfully updated!'; }} } $h->endpage(); ?> May be errors in place but it works! lol - - - Updated - - - SQL FILE http://pastebin.com/BrFVEifr Due to forum screwing sql up its in the pastebin link above if($worked['pagedisable'] == 'Yes') { echo 'Admin has disabled the Lottery Page.'; $h->endpage();; } should be if($worked['pagedisable'] == 'Yes') { echo 'Admin has disabled the Lottery Page.'; $h->endpage(); exit; } but other than that looks alright from a quick scan :P Edit: edit alot of echos :D i think i'm going to re code this hehe Quote Link to comment Share on other sites More sharing options...
AdamHull Posted June 4, 2015 Share Posted June 4, 2015 if($worked['pagedisable'] == 'Yes') { echo 'Admin has disabled the Lottery Page.'; $h->endpage();; } should be if($worked['pagedisable'] == 'Yes') { echo 'Admin has disabled the Lottery Page.'; $h->endpage(); exit; } but other than that looks alright from a quick scan :P Edit: edit alot of echos :D i think i'm going to re code this hehe yeh was just a straight conversion the php and html needs to be separated and the how often in the control panel needs removing Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted June 4, 2015 Share Posted June 4, 2015 yeh was just a straight conversion the php and html needs to be separated and the how often in the control panel needs removing I am working on making it work for mccodes but some changes Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted June 5, 2015 Author Share Posted June 5, 2015 So here is a quick conversion off the file Add this to cron_day $res = $db->query("SELECT * FROM `lottery_players` ORDER BY RAND() LIMIT 1"); $checkwinner = $db->num_rows($res); $row = $db->fetch_row($res); if($checkwinner == 0) { echo "There is no winners yet!"; } else { $check = $db->query("SELECT * FROM `lottery`"); $worked =$db->fetch_row($check); event_add($row['user'], "Congrats you have won the lottery your prize is $".number_format($worked['lotofund'])); $db->query("UPDATE `users` SET `money` = `money` + ".$worked['lotofund']." WHERE `userid` = ".$row['user'].""); $db->query("UPDATE `lottery` SET `lotofund` = '0',`tickets` = '0'"); $db->query("UPDATE `users` SET `tickets` = '0' WHERE `tickets` > '0'"); $db->query("INSERT INTO `lotowinners` VALUES({$row['user']},{$worked['lotofund']})"); $db->query("TRUNCATE TABLE `lottery_players`"); } This is the main lottery file lottery.php <?php require("globals.php"); $res = $db->query("SELECT * FROM `lottery`"); $row = $db->fetch_row($res); $checkp = $db->query("SELECT * FROM `lottery_players` WHERE `user` = {$ir['userid']}"); $num = $db->num_rows($checkp); $checkt = $db->fetch_row($checkp); $config = $db->query("SELECT * FROM `lottery_config`"); $worked = $db->fetch_row($config); if($worked['pagedisable'] == 'Yes') { echo 'Admin has disabled the Lottery Page.'; $h->endpage();; } $_POST['amount'] = isset($_POST['amount']) && ctype_digit($_POST['amount']) ? abs(intval($_POST['amount'])) : null; if($_POST['buy']) { if(empty($_POST['amount'])) { echo "You didn't enter a valid amount"; $h->endpage();; } $cost = $worked['ticketprice'] * $_POST['amount']; $usercash = $ir['money'] - $cost; $tickets = $ir['tickets'] + $_POST['amount']; $loto = $row['lotofund'] + $cost; $ltick = $row['tickets'] + $_POST['amount']; $deficit = $worked['maxtickets'] - $ir['tickets']; $havetick = $checkt['tickets'] + $_POST['amount']; if($tickets > $worked['maxtickets']) { echo "The max tickets is ".number_format($worked['maxtickets'])." This means you can only buy ".number_format($worked['maxtickets'] - $ir['tickets'])." more ticket";($deficit == 1 ? '' : 's'); $h->endpage(); } if($_POST['amount'] > $worked['maxtickets']) { echo 'You can only purchase '.number_format($worked['maxtickets']); $h->endpage();; } if($ir['money'] < $worked['ticketprice']) { echo 'You cant afford '.number_format($_POST['amount']).' tickets. It costs $'.number_format($worked['ticketprice'] * $_POST['amount']); $h->endpage();; } if($ir['tickets'] > $worked['maxtickets']) { echo 'You have already purchased max tickets which is '.number_format($worked['maxtickets']); $h->endpage();; } if($ir['money'] >= $worked['ticketprice'] && $_POST['amount'] <= $worked['maxtickets']) { if($num) { echo "You have purchase {$_POST['amount']} lottery tickets for ${number_format($cost)}"; $db->query("UPDATE `users` SET `money` = {$usercash}, `tickets` = {$tickets} WHERE `userid` = ".$userid.""); $db->query("UPDATE `lottery` SET `lotofund` = {$loto}, `tickets` = {$ltick}"); $db->query("UPDATE `lottery_players` SET `tickets` = {$havetick} WHERE `user` = {$ir['userid']}"); } else { echo "You have purchase {$_POST['amount']} lottery tickets for ${number_format($cost)}"; $db->query("UPDATE `users` SET `money` = {$usercash}, `tickets` = {$tickets} WHERE `userid` ={$ir['userid']}"); $db->query("UPDATE `lottery` SET `lotofund` = {$loto}, `tickets` = {$ltick}"); $db->query("INSERT INTO `lottery_players` VALUES('{$ir['userid']}',{$_POST['amount']})"); } } } ?> <table class="table"> <tr><td class="contenthead">Lottery</td></tr> <tr><td class="contentcontent"> <div class="infobox"> <span>Welcome to the lottery</span> <span>Each ticket costs $<?php echo number_format($worked['ticketprice']); ?></span> <span>Maximum of <?php echo number_format($worked['maxtickets']); ?> tickets per person</span> </div> <div class="otherbox"> <span>Lottery Fund: $<?php echo number_format($row['lotofund']); ?></span> <span>Tickets Purchased: <?php echo number_format($row['tickets']); ?></span> </div> </td></tr> <tr><td class="contentcontent"> <div class="buysection"> <form method="post"> [buy Tickets] <input class="lotoinput" type="text" name="amount" value="1" maxlength="2" /> <input type="submit" name="buy" value="Buy Ticket" /> </form> </div> </td></tr> <tr><td class="contenthead">Previous Winners</td></tr> <tr><td class="contentcontent"> <?php $win = $db->query("SELECT * FROM `lotowinners`"); $check = $db->num_rows($win); while($row = $db->fetch_row($win)) { if($check == 0) { echo "<div class='infobox'><span>There has been no previous Winners</span></div>"; } else { echo " <table class='infobox'> <tr> <td>".$row['username']." - $".number_format($row['amountwon'])."</td> </tr>"; } echo "</table>"; } ?> </td></tr> </table> Lottery cofig file lottery_config.php <?php require("globals.php"); if($ir['user_level'] != 2) { exit("You do not have permission to view this page!"); } echo '<h2>Lottery Control Panel</h2>'; echo '<form method="post">'; echo '<h3>Lottery Days</h3>'; echo 'Select how often (days) you want the lottery draw to take place. NOTE: You will need to update the cron job.'; echo "<b>The current setting is: {$set['lottery_days']} days.</b>"; echo '<select name="days"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option></select>'; echo '<h3>Lottery Numbers</h3>'; echo 'Select the amount of numbers you want users to be able to choose from.'; echo "<b>The current setting is: {$set['lottery_numbers']} numbers.</b>"; echo "<input type='text' name='numbers' size='2' maxlength='2' value='{$set['lottery_numbers']}' />"; echo '<h3>Ticket Cost</h3>'; echo 'Select the cost per lottery ticket.'; echo "<b>The current setting is: \${$set['lottery_ticketcost']}.</b>"; echo "$<input type='text' name='cost' value='{$set['lottery_ticketcost']}' />"; echo '<input type="submit" name="update" value="Update" />'; echo '</form>'; if(isset($_POST['update'])) { $days = abs(intval($_POST['days'])); $numbers = abs(intval($_POST['numbers'])); $cost = abs(intval($_POST['cost'])); if ($days > 7) { echo 'The days must be 7 or less!'; } else { if ($numbers < 6 || $numbers > 99) { echo 'The numbers must be greater than 5 and less than 100!'; } else { $db->query("UPDATE settings SET conf_value=$days WHERE conf_name='lottery_days'"); $db->query("UPDATE settings SET conf_value=$numbers WHERE conf_name='lottery_numbers'"); $db->query("UPDATE settings SET conf_value=$cost WHERE conf_name='lottery_ticketcost'"); echo 'Successfully updated!'; }} } $h->endpage(); ?> May be errors in place but it works! lol - - - Updated - - - SQL FILE http://pastebin.com/BrFVEifr Due to forum screwing sql up its in the pastebin link above Is returning Blank page for me. I tried converting it myself, without the brackets Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted June 5, 2015 Author Share Posted June 5, 2015 (edited) I am working on making it work for mccodes but some changes Do you have an ETA on that? Edited June 5, 2015 by -BRAIDZ- Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted June 5, 2015 Share Posted June 5, 2015 Do you have an ETA on that? Not sure today or tomorrow if i have the time but changed things around a little [ATTACH=CONFIG]2086[/ATTACH] Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted June 5, 2015 Author Share Posted June 5, 2015 Not sure today or tomorrow if i have the time but changed things around a little [ATTACH=CONFIG]2086[/ATTACH] Okay mate, and sweet looks good, can't wait for it :) Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted June 5, 2015 Share Posted June 5, 2015 Lottery Mod This was brought over from the GRPG section found here: http://makewebgames.io/showthread.php/44573-Lottery-Mod Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted June 5, 2015 Share Posted June 5, 2015 This was brought over from the GRPG section found here: http://makewebgames.io/showthread.php/44573-Lottery-Mod Thanks mate saves me making a new topic ;) Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted June 5, 2015 Author Share Posted June 5, 2015 Thanks mate saves me making a new topic ;) Can't wait for it to be finished. If you need any help with it let me know (not that good, but know the basics) Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted June 5, 2015 Share Posted June 5, 2015 Thanks mate saves me making a new topic ;) You may want to anyway because the R&iP since this is in production and technically a request Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted June 5, 2015 Share Posted June 5, 2015 You may want to anyway because the R&iP since this is in production and technically a request ok :D Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted June 5, 2015 Share Posted June 5, 2015 Can't wait for it to be finished. If you need any help with it let me know (not that good, but know the basics) got it pretty much covered :) but thanks Main Lottery page - 100% Buy function - 100% Option to set max tickets and price per ticket - 0% Edit & test cron - 0% Previous Winners - 0% Then ill be able to release it i have made some changes to the module * Instead of using the insert / update tickets i have made a simple for statement and made it insert the amount of rows of the max tickets they purchase the more tickets the user buys the more of a chance he has of being selected. * Changed the database structure a little * Cleaned up some code and made it look more like a mccodes module * Optimized the code to only pull the required info Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted June 6, 2015 Author Share Posted June 6, 2015 got it pretty much covered :) but thanks Main Lottery page - 100% Buy function - 100% Option to set max tickets and price per ticket - 0% Edit & test cron - 0% Previous Winners - 0% Then ill be able to release it i have made some changes to the module * Instead of using the insert / update tickets i have made a simple for statement and made it insert the amount of rows of the max tickets they purchase the more tickets the user buys the more of a chance he has of being selected. * Changed the database structure a little * Cleaned up some code and made it look more like a mccodes module * Optimized the code to only pull the required info How much longer till it is released do you reckon? Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted June 6, 2015 Share Posted June 6, 2015 How much longer till it is released do you reckon? http://makewebgames.io/showthread.php/46077-Lottery-Mod Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.