Jump to content
MakeWebGames

KiX

Members
  • Posts

    144
  • Joined

  • Last visited

Everything posted by KiX

  1. Re: Donator and Non-Donator Lottery [V2] The reason I am making them as items, is so other players can sell them in the market or whatever. Hence the itemuse.   When u use them it automatically inserts a line in the lottery table. Did you modify anything in the code besides the credits/crystals ?
  2. Re: Donator and Non-Donator Lottery [V2] OH MAN!!! YOU ARE RIGHT! I forgot to add the item creating section. My bad.. Here it is staff_items.php find   <option value='crimexp'>Crime XP</option>   and paste underneath <option value='lottery'>Lottery</option>   *note you will have to do this under each effect. There are 3 by default next find this line   "crimexp" => "Crime XP");   and replace with   "crimexp" => "Crime XP", "lottery" => "Lottery");   now for the itemuse.php *Remember that in my table I am using items 115 & 116. Your items will most likely have a different id number find where it says $r=$db->fetch_row($i);   and paste underneath   if($r['inv_itemid']==115) { $db->query("INSERT INTO lottery VALUES('',$userid,'1')"); $db->query("UPDATE `users` SET lottery = 1 WHERE userid={$userid}"); print "{$r['itmname']} used successfully!"; item_remove($userid, $r['inv_itemid'], 1); die; } if($r['inv_itemid']==116) { $db->query("INSERT INTO lottery VALUES('',$userid,'0')"); $db->query("UPDATE `users` SET lottery = 2 WHERE userid={$userid}"); print "{$r['itmname']} used successfully!"; item_remove($userid, $r['inv_itemid'], 1); die; } }   and hopefully I have not forgotten anything else. hehe
  3. Re: Donator and Non-Donator Lottery [V2]   LOL :) well. The way I made the mod was to create 2 items. I called them Donator Lottery Ticket & Lottery Tickets So, when you buy a lottery ticket it will send you the item yo your inventory. In order for it to be available for the monthly cron, u need to use the item. Now regarding the draw it self, at the end of the month it randomly selects 1 ticket and will send the credits (crystals) to the winners.
  4. Re: Donator and Non-Donator Lottery [V2]   well it depends on your host. On my host it is pretty simple, All I do is follow a gui, but if u need to do it unix. It would be like this 0 3 * * 1 <----- Every monday at 3 am in the morning for example,
  5. Re: Donator and Non-Donator Lottery [V2] hehe :) Well there was a lot to soak in my post :)
  6. Re: Donator and Non-Donator Lottery [V2] For the non-donators it is all in the code I posted above. The donators lottery is only if they purchase the tickets through paypal, whereas for the people that do not want to use RL money, they can buy them with credits (crystals) in the explore.php
  7. Re: Donator and Non-Donator Lottery [V2] LOL I knew I forgot something. The CRON! I have created it monthly, but you can change it to anything you prefer. create a file cron_monthly.php   <?php include "config.php"; global $_CONFIG; //if($_GET['code'] != $_CONFIG['code']) { die(""); } define("MONO_ON", 1); require "class/class_db_{$_CONFIG['driver']}.php"; $db=new database; $db->configure($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database'], $_CONFIG['persistent']); $db->connect(); $c=$db->connection_id; /* Lottery for Donators*/ $lotd_sql = $db->query("SELECT * FROM lottery WHERE lot_DON=1 ORDER BY rand() LIMIT 1"); $lotd_row = $db->fetch_row($lotd_sql); $lotd=$db->query("SELECT * FROM lottery WHERE lot_DON=1"); $lotdcnt = $db->num_rows($lotd); $jackpotd = ($lotdcnt*100)+10000; $creditd = $db->query("UPDATE `users` SET `credits` = `credits` + $jackpotd WHERE `userid` = {$lotd_row['lotPLAYER']}"); $lotd_event1 = $db->query("INSERT INTO `events` VALUES('', {$lotd_row['lotPLAYER']}, unix_timestamp(), 0, 'Congratulations! You won this months lottery. You were credited with $jackpotd credits')"); $lotd_event2 = $db->query("UPDATE `users` SET new_events=new_events+1 WHERE userid={$lotd_row['lotPLAYER']}"); /* Lottery for non-Donators*/ $lot_sql = $db->query("SELECT * FROM lottery WHERE lot_DON=0 ORDER BY rand() LIMIT 1"); $lot_row = $db->fetch_row($lot_sql); $lot=$db->query("SELECT * FROM lottery WHERE lot_DON=0"); $lotcnt = $db->num_rows($lot); $jackpot = ($lotcnt*5)+100; $credit = $db->query("UPDATE `users` SET `credits` = `credits` + $jackpot WHERE `userid` = {$lot_row['lotPLAYER']}"); $lot_event1 = $db->query("INSERT INTO `events` VALUES('', {$lot_row['lotPLAYER']}, unix_timestamp(), 0, 'Congratulations! You won this months lottery. You were credited with $jackpot credits')"); $lot_event2 = $db->query("UPDATE `users` SET new_events=new_events+1 WHERE userid={$lot_row['lotPLAYER']}"); $db->query("UPDATE `users` SET `lottery` = 0"); $db->query("TRUNCATE TABLE `lottery`");   You are probably wondering why I have not used the event_add function.....well for some reason that i could not figure out yet, the function does not work to well in crons.. So I have put them directly. Anyways sorry for forgetting it b4. :)
  8. Well I was thinking that it was my time to contribute my first mod to the site. I have seen marvelous additions by people like illusions and I would like to try to learn from them. Something similar has been done already, but this version has a bit of a tweak. The first thing you need to do is create 2 items - Lottery Ticket for Donators - Lottery Ticker for non-Donators You can call them whatever you want of course. The reason I chose to put them as item is so the user can decide when to use the purchased lottery ticket. Right so lets give a go shall we. BTW, in my game, Underground Evolution, we do not use crystals, I have called them credits. So, you will need to change this in the code so it will work. I hope you like it, so enjoy it. Lottery for Donators create a file called lottery.php (This is for your donations)   <?php include "globals.php"; $lot=$db->query("SELECT * FROM lottery WHERE lot_DON=1"); $lotcnt=mysql_num_rows($lot); $jackpot=($lotcnt*100)+10000; print <<<EOF <h3>Lottery Tickets</h3> Buy a lottery ticket today! Per each lottery ticket bought we will add 100 credits to the jackpot. The jackpot starts at 10000 credits Each end of the month, the jackpot will be raffled between all the Lottery Ticket owners. Soooo, GOOD LUCK!!! [b]JACKPOT AT THE MOMENT: $jackpot Credits TICKETS SOLD: {$lotcnt} [/b] Draw ends: Last day of the month. [b]Buy One:[/b] (\$1)</p> <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="{$set['paypal']}"> <input type="hidden" name="item_name" value="{$domain}|LO|1|{$userid}"> <input type="hidden" name="amount" value="1.00"> <input type="hidden" name="no_shipping" value="1"> <input type="hidden" name="return" value="http://{$domain}/lotterydone.php?action=done&quantity=one"> <input type="hidden" name="cancel_return" value="http://{$domain}/lotterydone.php?action=cancel"> <input type="hidden" name="notify_url" value="http://{$domain}/ipn_lot.php"> <input type="hidden" name="cn" value="Your Player ID"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="tax" value="0"> <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> </form> [b]Buy Five:[/b] (\$4.50)</p> <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="{$set['paypal']}"> <input type="hidden" name="item_name" value="{$domain}|LO|5|{$userid}"> <input type="hidden" name="amount" value="4.50"> <input type="hidden" name="no_shipping" value="1"> <input type="hidden" name="return" value="http://{$domain}/lotterydone.php?action=done&quantity=five"> <input type="hidden" name="cancel_return" value="http://{$domain}/lotterydone.php?action=cancel"> <input type="hidden" name="notify_url" value="http://{$domain}/ipn_lot.php"> <input type="hidden" name="cn" value="Your Player ID"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="tax" value="0"> <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> </form> EOF; $h->endpage(); ?>   create a file called ipn_lot.php   <? include "config.php"; global $_CONFIG; define("MONO_ON", 1); require "class/class_db_{$_CONFIG['driver']}.php"; $db=new database; $db->configure($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database'], $_CONFIG['persistent']); $db->connect(); $c=$db->connection_id; require 'global_func.php'; $set=array(); $settq=$db->query("SELECT * FROM settings"); while($r=$db->fetch_row($settq)) { $set[$r['conf_name']]=$r['conf_value']; } // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // post back to PayPal system to validate $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30); // assign posted variables to local variables $item_name = $_POST['item_name']; $item_number = $_POST['item_number']; $payment_status = $_POST['payment_status']; $payment_amount = $_POST['mc_gross']; $payment_currency = $_POST['mc_currency']; $txn_id = $_POST['txn_id']; $receiver_email = $_POST['receiver_email']; $payer_email = $_POST['payer_email']; if (!$fp) { // HTTP ERROR } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { // check the payment_status is Completed if($payment_status != "Completed") { fclose ($fp);die(""); } if(mysql_num_rows($db->query("SELECT * FROM dps_accepted WHERE dpTXN='{$txn_id}'", $c)) > 0) { fclose ($fp);die(""); } if(mysql_num_rows($db->query("SELECT * FROM lottery_accepted WHERE dpTXN='{$txn_id}'", $c)) > 0) { fclose ($fp);die(""); } // check that txn_id has not been previously processed // check that receiver_email is your Primary PayPal email if($receiver_email != $set['paypal']) { fclose ($fp);die(""); } // check that payment_amount/payment_currency are correct if($payment_currency != "USD") { fclose ($fp);die(""); } // parse for pack $packr=explode('|',$item_name); if(str_replace("www.","",$packr[0]) != str_replace("www.","",$_SERVER['HTTP_HOST'])) { fclose($fp); die(""); } if($packr[1] != "LO") { fclose($fp);die(""); } $pack=$packr[2]; if( $pack != 1 and $pack != 5) { fclose($fp);die(""); } if(($pack == 1) && $payment_amount != "1.00") { fclose ($fp);die(""); } if($pack == 5 && $payment_amount != "4.50") { fclose ($fp);die(""); } // grab IDs $buyer=$packr[3]; $for=$buyer; // all seems to be in order, credit it. if($pack==1) { $db->query("INSERT INTO inventory VALUES('', '115', $for, '1')"); } else if($pack==5) { $db->query("INSERT INTO inventory VALUES('', '115', $for, '5')"); } // process payment event_add($for, "Your \${$payment_amount} worth of Lottery Tickets ($pack) has been successfully credited.", $c); $db->query("INSERT INTO lottery_accepted VALUES('', {$buyer}, {$for}, '$pack', unix_timestamp(), '$txn_id')", $c); } else if (strcmp ($res, "INVALID") == 0) { fwrite($f,"Invalid?"); } } fclose ($fp); } ?>   *Note on this last file, if you see in the "INSERT INTO inventory" on the last line. You need to modify '115' to the id of the item Lottery Donator.   create a flie called lotterydone.php <?php include "globals.php"; if($_GET['action'] == "cancel") { print "You have cancelled your donation. Please donate later..."; } else if($_GET['action'] == "done") { if(!$_GET['tx']) { die ("Get a life."); } print "Thank you for your payment to {$set['game_name']}. Your transaction has been completed, and a receipt for your purchase has been emailed to you. You may log into your account at [url='http://www.paypal.com']www.paypal.com[/url] to view details of this transaction. Your lottery ticket(s) should be credited within a few minutes, if not, contact an admin for assistance. "; print " [b]IMPORTANT: [/b]<ul>Once you receive your Lottery Ticket, you will need to use it so it will generate your Unique Lottery Ticket ID. If you do not use it, then you will NOT participate in the next monthly draw.[/list]</p>"; } $h->endpage(); ?>   create a file called lotterytick.php   <?php include "globals.php"; $lotd=$db->query("SELECT lot_ID FROM lottery WHERE lotPLAYER={$ir['userid']} AND lot_DON=1"); $lotdcnt=mysql_num_rows($lotd); $lot=$db->query("SELECT lot_ID FROM lottery WHERE lotPLAYER={$ir['userid']} AND lot_DON=0"); $lotcnt=mysql_num_rows($lot); print " <table style='text-align: left; margin-left: auto; margin-right: auto;' border='0' cellpadding='2' cellspacing='2'> <tr> <td style='width: 600px;'> <hr style='width: 100%; height: 2px;'> <h3 style='text-align: center;'>DONATOR LOTTERY TICKETS</h3> <hr style='width: 100%; height: 2px;'></td> <td style='width: 605px;'> <hr style='width: 100%; height: 2px;'> <h3 style='text-align: center;'>NORMAL LOTTERY TICKETS</h3> <hr style='width: 100%; height: 2px;'></td> </tr> <tr> <td style='text-align: center;'> Lottery Tickets Purchased: $lotdcnt <u>Ticket Numbers</u> </td> <td style='text-align: center;'> Lottery Tickets Purchased: $lotcnt <u>Ticket Numbers</u> </td> </tr> <tr> <td valign='top' style='text-align: center;'> "; $lotdcount=1; while($lotdshow=$db->fetch_row($lotd)) { print " [b]Ticket Number # $lotdcount:[/b] "; $lotdcount=$lotdcount+1; print " {$lotdshow['lot_ID']} "; } print"</td><td valign='top' style='text-align: center;'>"; $lotcount=1; while($lotshow1=$db->fetch_row($lot)) { print " [b]Ticket Number # $lotcount:[/b] "; $lotcount=$lotcount+1; print " {$lotshow1['lot_ID']} "; } print' </td></tr></table>'; $h->endpage(); ?>   create a file called buylottery.php   <?php include "globals.php"; $lot=$db->query("SELECT * FROM lottery WHERE lot_DON=0"); $lotcnt=mysql_num_rows($lot); $jackpot = ($lotcnt*5)+100; print "<br/ > Buy a lottery ticket today! Per each lottery ticket bought we will add 5 credit to the jackpot. The jackpot starts at 100 credits Each end of the month, the jackpot will be raffled between all the Lottery Ticket owners. Soooo, GOOD LUCK!!! [b]JACKPOT AT THE MOMENT: $jackpot Credits TICKETS SOLD: {$lotcnt} [/b] Draw ends: Last day of the month. Cost per ticket: 1 credit "; switch($_GET['action']) { default: index(); break; case "lottobuy": lottobuy(); break; } function index() { global $db, $ir,$c,$userid,$h; print "<h3>Lottery Tickets</h3> [b]Buy a Lottery Ticket[/b] <form action='buylottery.php?action=lottobuy' method='post'> Amount: <input type='text' name='lottobuy' value='{$ir['lotterycap']}' /> <input type='submit' value='Buy Ticket' /></form></td> </tr> </table>"; } function lottobuy() { global $db,$ir,$c,$userid,$h; $_POST['lottobuy']=abs((int) $_POST['lottobuy']); if($_POST['lottobuy'] > $ir['lotterycap']) { print "You can only but 10 tickets per day. You have {$ir['lotterycap']} left for today."; } elseif ($_POST['lottobuy'] > $ir['credits']) { print "You do not have enough credits for the transaction. You only have {$ir['credits']} left."; } else { $gain=$_POST['lottobuy']; $ir['credits']-=$gain; $db->query("UPDATE users SET credits=credits-$gain, lotterycap=lotterycap-$gain, lottery=1 WHERE userid=$userid"); $still= $ir['lotterycap']-$gain; print "You have bought $gain lottery Tickets. [b]You can still buy $still tickets(s) today.[/b] [url='explore.php']> Back[/url]"; $db->query("INSERT INTO inventory VALUES('', '116', $userid, $gain)"); } } $h->endpage(); ?>   *Note on this last file, if you see in the "INSERT INTO inventory" on the last line. You need to modify '116' to the id of the item Lottery Non Donator.   SQL Stuff create a table called lottery   CREATE TABLE IF NOT EXISTS `lottery` ( `lot_ID` int(11) NOT NULL auto_increment, `lotPLAYER` varchar(255) NOT NULL, `lot_DON` int(1) NOT NULL default '0', PRIMARY KEY (`lot_ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;   create a table called lottery_accepted   CREATE TABLE IF NOT EXISTS `lottery_accepted` ( `dpID` int(11) NOT NULL auto_increment, `dpBUYER` int(11) NOT NULL default '0', `dpFOR` int(11) NOT NULL default '0', `dpAMNT` varchar(255) NOT NULL default '', `dpTIME` int(11) NOT NULL default '0', `dpTXN` varchar(255) NOT NULL default '', PRIMARY KEY (`dpID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;   Add 2 entries in your table USERS ALTER TABLE `users` ADD `lottery` VARCHAR( 1 ) NOT NULL DEFAULT '0'; ALTER TABLE `users` ADD `lotterycap` VARCHAR( 2 ) NOT NULL DEFAULT '10'; Finally add to your explore.php the option to buy lottery tickets for your Non-Donatos find in explore.php where it says [url='street.php']Search the Streets[/url]   and add below it [url='buylottery.php']Lottery[/url]   Hmm I think that is it...I do not think I have forgotten anything. I hope you enjoy it as much as I did making it. Cheers!
×
×
  • Create New...