Cronwerks MCCode/MCCodes Forums

Please login or register.

Login with username, password and session length

News:

After purchasing with us the download link will be delivered to your forum message box.


This forum is now closed and has moved to a new location! Click here to find out why.

AuthorTopic: Xmas Presents for your Users  (Read 615 times)

JoshuaDams

  • Active Member
  • **
  • Reputation Power: 129
  • JoshuaDams is working their way up.JoshuaDams is working their way up.JoshuaDams is working their way up.
  • Offline Offline
  • Posts: 240
    • MSN Messenger - immortalthug4ever@hotmail.com
    • View Profile
    • WWW
Xmas Presents for your Users
« on: November 17, 2009, 01:11:51 AM »
Ok so this is fairly basic, but gives your users xmas presents.

The first 2 Presents opened give random money and points, but have a small chance 1 out of 10, in going to the hospital or jail.

The other 3 presents select a random item from your items and give to the user.

They can only open Each present one time.

ALTER TABLE users ADD xmas tinyint(3) default '0'

Code: [Select]
<?php

//***************************\\
//***************************\\
//*****Made*By*ImmortalThug*****\\
//******November*17,*2009******\\
//***Please*Do*Not*Remove*This ***\\
//***************************\\
//***************************\\


include_once (DIRNAME(__FILE__) . '/globals.php');
if(
$ir['xmas'] > 4)
{
echo 
"You have already opened your presents from Santa";
        
$h->endpage();
}
echo 
"<h4>Merry Christmas, Open your presents from Santa.</h4>";




switch(
$_GET['option'])
{


   case 
'xmas_1':
   
xmas_1();
   break;

   case 
'xmas_2':
   
xmas_2();
   break;

   case 
'xmas_3':
   
xmas_3();
   break;
  
   case 
'xmas_4':
   
xmas_4();
   break;

   case 
'xmas_5':
   
xmas_5();
   break; 

   default:
   
index();
   break;
}

function 
index()
{
   global 
$ir;
   echo 
sprintf("<p>Merry Christmas %s Santa has left you 5 presents to open under your christmas tree.</p>"htmlspecialchars($ir['username']));;
   echo 
"<a href='?option=xmas_1'>First Present</a><br />";
  echo 
"<a href='?option=xmas_2'>Second Present</a><br />";
   echo 
"<a href='?option=xmas_3'>Third Present</a><br />";
   echo 
"<a href='?option=xmas_4'>Fourth Present</a><br />";
 echo 
"<a href='?option=xmas_5'>Last Present</a><br />";

}
function 
xmas_1()
{
   global 
$db$ir$userid$h;
if(
$ir['xmas'] !=0)
{
echo 
"Sorry, you have already opened this present from santa.";
$h->endpage();
}


$cr=abs(@intval(rand(1,10)));
if(
$cr == 2)
{
      echo 
"Santa gave you just what you always wanted!  An elite computer for your household.  Unfortunately when you plug it in, the computer short circuits and gives you one heck of a jolt! <br />
The ambulance is called and you must spend some time in the hospital"
;
$db->query(sprintf("UPDATE users SET hp = %d, hospital =%d, hospreason = '%s', xmas=%d WHERE (userid=%u)",1,5,'Electricuted from faulty merchandise',1,$ir['userid']));
$h->endpage();
}
else
{
$xm=$db->query("SELECT * FROM items WHERE itmbuyable=1 ORDER BY rand() LIMIT 1");
$r=$db->fetch_row($xm);
$xmasitem=$r['itmid'];
$name=$r['itmname'];
$userid=$ir['userid'];
echo 
"Merry Xmas, You have received a $name from Santa Claus<a href='xmas.php'>Back to Christmas Tree</a>";
$db->query(sprintf("INSERT INTO inventory VALUES ('', %u, %u, %d)",$xmasitem,$userid,1));
$db->query(sprintf("UPDATE users SET xmas=%d WHERE userid=%u",1,$ir['userid']));

}
}

function 
xmas_2()
{
  global 
$db$ir$userid,$h;
if(
$ir['xmas'] !=1)
{
echo 
"You must open your presents in order! You missed the first one!";
$h->endpage();
}

$jail=abs(@intval(rand(1,10)));
if(
$jail=7)// If Random Number is 7--User is Jailed
{
echo 
"After opening your 2nd package from Santa you are interrupted by a Knock on the front door.  As you approach the front door you are taken back when the it is kicked in and agents swarm your house. <br />
Turns out the presents Santa gave you were hot merchandise and you have to pay the time.  You're hauled off to jail."
;
$db->query(sprintf("UPDATE users SET jail = %u, jail_reason = '%s', xmas=%d WHERE (userid=%u)",5,'Holding stolen merchandise',2,$ir['userid']));
$h->endpage();
}

else
{
$money mt_rand(1001000);
   
$crystals mt_rand(1050); 
   echo 
sprintf("Instead of gifts this year you find %u money %u crystals in a small envelope.  Merry Xmas!""\$"number_format($money), number_format($crystals));
   
$db->query(sprintf("UPDATE users SET money = money + %u, crystals = crystals + %u, xmas = %d WHERE userid = %d"$money$crystals2$userid));
   
}
}

function 
xmas_3()
{
global 
$db$ir$userid$h;



if(
$ir['xmas'] !=2)
{
echo 
"You must open your presents in order.  You missed the first 2!";
$h->endpage();
}
else
{
$xm=$db->query("SELECT * FROM items WHERE itmbuyable=1 ORDER BY rand() LIMIT 1");
$r=$db->fetch_row($xm);
$xmasitem=$r['itmid'];
$userid=$ir['userid'];
$item=$r['itmname'];
echo 
"Merry Xmas, You have received a $item from Santa Claus<a href='xmas.php'>Back to Christmas Tree</a>";
$db->query(sprintf("INSERT INTO inventory VALUES ('', %u, %u, %d)",$xmasitem,$userid,1));
$db->query(sprintf("UPDATE users SET xmas=%d WHERE userid=%u"3,$ir['userid']));
}
}
function 
xmas_4()
{
global 
$db$ir$userid,$h;
if(
$ir['xmas'] != 3)
{
echo 
"You must open your presents in order! You missed the first 3!";
$h->endpage();
}
else
{
$xm=$db->query("SELECT * FROM items WHERE itmbuyable=1 ORDER BY rand() LIMIT 1");
$r=$db->fetch_row($xm);
$xmasitem=$r['itmid'];
$userid=$ir['userid'];
$item=$r['itmname'];
echo 
"Merry Christmas, Santa Claus has given you a $item for christmas.  Happy Holidays!";
$db->query(sprintf("INSERT INTO inventory VALUES ('', %u, %u, %d)",$xmasitem,$userid,1));
$db->query(sprintf("UPDATE users SET xmas=%d WHERE userid=%u"4,$ir['userid']));

}
}

function 
xmas_5()
{
global 
$db$ir$userid,$h;
if(
$ir['xmas'] != 4)
{
echo 
"You must open your presents in order! You missed the first 4!";
$h->endpage();
}
else
{
$xm=$db->query("SELECT * FROM items WHERE itmbuyable=1 ORDER BY rand() LIMIT 1");
$r=$db->fetch_row($xm);
$xmasitem=$r['itmid'];
$userid=$ir['userid'];
$item=$r['itmname'];
echo 
"Merry Christmas, To celebrate the New Year Santa Claus has given you an $item.  Happy Holidays!";
$db->query(sprintf("INSERT INTO inventory VALUES ('', %u, %u, %d)",$xmasitem,$userid,1));
$db->query(sprintf("UPDATE users SET xmas=%d WHERE userid=%u"5,$ir['userid']));
}
}
$h->endpage();
?>

IF you want your users to be able to open presents daily add this into your day cron

$db->query("UPDATE users SET xmas=0");

JoshuaDams

  • Active Member
  • **
  • Reputation Power: 129
  • JoshuaDams is working their way up.JoshuaDams is working their way up.JoshuaDams is working their way up.
  • Offline Offline
  • Posts: 240
    • MSN Messenger - immortalthug4ever@hotmail.com
    • View Profile
    • WWW
Re: Xmas Presents for your Users
« Reply #1 on: November 17, 2009, 06:07:24 AM »
Well hell I can't edit.

Users may want to add

exit;
 

under all $h->endpage(); to avoid double footers.

all but the last endpage.
 


This forum is now closed and has moved to a new location! Click here to find out why.