Author Topic: Rob The Bank - new item  (Read 24754 times)

Offline chadk

Rob The Bank - new item
« on: September 27, 2006, 03:08:28 am »
This is a fun one.
I'd asked for the feature but didn't see if happening so I wrote it for all to enjoy. ;)

Attempt to rob the bank.
Success = you get between 20% and 80% of the banks total money, all users loose that percentage, you loose 10 karma.
Failure = you loose 100 karma, you loose all your credits.

I have mine set to 1000 credits to purchase and 20% chance to win, users on my site have lots of credits because I've backpaid everyone for past posts.

Code: [Select]
<?php
/**********************************************\
| SMFSHOP (Shop MOD for Simple Machines Forum) |
|         (c) 2005 DanSoft Australia           |
|      http://www.dansoftaustralia.com/        |
\**********************************************/

//File: RobTheBank.php
//      % chance to steal from all members in the bank
// on success, awards robber between 20 and 80% of the sum of all bank accounts
// and reduces bank accounts accordingly and gives 10 negative karma.
// On failure, gives -100 karma and sets money and bank money to 0 for robber.

//VERSION: 1.0 (Build 1)
//DATE: Sep 26th, 2006
// $Id: RobTheBank.php chadk $

class item_RobTheBank extends itemTemplate {
    function 
getItemDetails() {
    
$this->authorName "Chad";
$this->authorWeb "http://www.aviary.info/";
$this->authorEmail "generalchad@gmail.com";
        
$this->name "Rob the bank!";
        
$this->desc "You can try to ROB THE BANK!  This gives you a CHANCE to steal a portion of the money from EVERYONES bank account!  Note: Karma is NOT BLIND!  Even if you rob the bank, there may be consequences!";
        
$this->price 1000;
        
        
$this->require_input false;
        
$this->can_use_item true;
    }

    
//see AddToPostCount.php for more infos
    
function getAddInput() {
        return 
"Probability of successful robbery: <input type='text' name='info1' value='10'>%";
    }

    function 
onUse() {
        global 
$db_prefix$ID_MEMBER$item_info$user;
        
        
$pmfrom = array(
            
'id' => 1,
            
'name' => 'Chad',
            
'username' => 'Chad'
        
);
        
        
$pmto = array(
            
'to' => array(1),
            
'bcc' => array()
        );

        
//get a random number between 0 and 100
        
$try mt_rand(0100);

        
//if successfull
        
if ($try $item_info[1]) {

            
//get stealee's money count
            
$result db_query("SELECT sum(moneyBank) as vault
                                FROM 
{$db_prefix}members"__FILE____LINE__);
            
$row mysql_fetch_array($resultMYSQL_ASSOC);

            
//get random amount between 0 and amount of money stealee has
            
$steal_amount 1-(mt_rand(10,60)/100);

            
//take this money away from stealee...
            
$result db_query("UPDATE {$db_prefix}members
                                SET moneyBank = moneyBank * 
{$steal_amount}"__FILE____LINE__);
            
//...and give to stealer (robber)

$steal_amount = ($steal_amount-1) * -$row['vault'];

            
$result db_query("UPDATE {$db_prefix}members
                                SET money = money + 
{$steal_amount}, karmaBad = karmaBad + 10
                                WHERE ID_MEMBER = 
{$ID_MEMBER}
                                LIMIT 1"
__FILE____LINE__);

sendpm($pmto'Bank Robbed!'"{$user} Robbed the bank for {$steal_amount}"0$pmfrom);
                return 
"You ROBBED THE BANK for $steal_amount!  Thief! Your Karma is STILL reduced by 10! (Karma isn't blind!)";


        } else {
            
//if reducing Karma doesn't work, replace
            //'karmaBad = karmaBad + 10' with 'karmaGood = karmaGood - 10'
$result db_query("UPDATE {$db_prefix}members
SET karmaBad = karmaBad + 100, 
money = -100, moneyBank = -500
WHERE ID_MEMBER = 
{$ID_MEMBER}",
__FILE____LINE__);
$result db_query("DELETE FROM {$db_prefix}shop_inventory
WHERE ownerid = 
{$ID_MEMBER}",
__FILE____LINE__);

sendpm($pmto'Bank Robbery Foiled!'"{$user} was BUSTED!"0$pmfrom);
return 
"Steal <b>unsuccessful!</b> You Karma is now reduced by 100!";
        }
    }
}

?>
« Last Edit: October 22, 2006, 06:27:26 am by chadk »

Offline chadk

Re: Rob The Bank - new item
« Reply #1 on: September 28, 2006, 02:15:32 am »
Maybe someone could update my second version to PM the admin with the user's NAME.  Currently it doesn't send anything because $user isn't populated.

Offline Daniel15

Re: Rob The Bank - new item
« Reply #2 on: September 30, 2006, 02:55:05 pm »
Quote
Currently it doesn't send anything because $user isn't populated.
Putting global $user; at the top of the function should solve that ;)
But I haven't tested it either... :P

Offline chadk

Re: Rob The Bank - new item
« Reply #3 on: September 30, 2006, 11:00:05 pm »
cool.. cool!  Thanks Daniel.

Offline chadk

Re: Rob The Bank - new item
« Reply #4 on: September 30, 2006, 11:15:13 pm »
hmmm nope that didn't work.

Offline Basil Beard

Re: Rob The Bank - new item
« Reply #5 on: October 01, 2006, 12:14:14 am »
$user is just like any other global variable.

You want <?php
global $user;

Daniel forgot the space. =P
Arrrrr!

Offline Daniel15

Re: Rob The Bank - new item
« Reply #6 on: October 01, 2006, 12:57:33 pm »
Bah, the formatting went all wrong...
It was just meant to be
global $user;
NOT
<?phpglobal $user;

I typed it in correctly, but the [ php ] BBCode seems to like randomly adding <?php to the start of it... (strange [ php ] BBcode bug, I suppose)

Offline chadk

Re: Rob The Bank - new item
« Reply #7 on: October 01, 2006, 10:42:07 pm »
Oh I understood what he meant.  I tried putting global $user; at the top and that didn't work so I tried putting it inside the onuse function (at the end of the other globals) and that didn't work either. :(    I'll look at one of the mods that does use sendPM with success and see how they did it.

Offline TechnoDragon

Re: Rob The Bank - new item
« Reply #8 on: October 02, 2006, 12:31:04 am »
if that is the case...there is a post around here that added the send item to another user before it was integrated with the shop...that could be a good place to start looking for your info
Don't tell me to get into shape...I have a shape...It is round!


Offline chadk

Re: Rob The Bank - new item
« Reply #9 on: October 03, 2006, 05:55:40 am »
Yep, I'll grab it out of that one.  I'm waiting to see how compatible my shop will be (if at all) with the Shop/RPG mod being done.

Offline dcd119

Re: Rob The Bank - new item
« Reply #10 on: October 03, 2006, 07:27:09 am »
yah I added this to my forum... pissed alot of people off...lol

its not real they keep getting told..

Offline chadk

Re: Rob The Bank - new item
« Reply #11 on: October 04, 2006, 11:33:21 am »
hahaha yah tonight someone succeeded in robbing the bank.  He bought 5 of them and used them trying.  I had it set to 10%.  but, becuse he robbed it, I changed the code a bit.  If you fail, it will now take all your money and then some, give you 100 neg karma and take away all your items.  This will prevent people from stockpiling ROB THE BANK items and trying all night long, even though it's HELLA expensive to buy one.  Here's my updated code (still the PM isn't quite right):
Code: [Select]
<?php
/**********************************************\
| SMFSHOP (Shop MOD for Simple Machines Forum) |
|         (c) 2005 DanSoft Australia           |
|      http://www.dansoftaustralia.com/        |
\**********************************************/

//File: RobTheBank.php
//      % chance to steal from all members in the bank
// on success, awards robber between 20 and 80% of the sum of all bank accounts
// and reduces bank accounts accordingly and gives 10 negative karma.
// On failure, gives -100 karma and sets money and bank money to 0 for robber.

//VERSION: 1.0 (Build 1)
//DATE: Sep 26th, 2006
// $Id: RobTheBank.php chadk $

class item_RobTheBank extends itemTemplate {
    function 
getItemDetails() {
        
$this->name "Rob the bank!";
        
$this->desc "You can try to ROB THE BANK!  This gives you a CHANCE to steal a portion of the money from EVERYONES bank account!  Note: Karma is NOT BLIND!  Even if you rob the bank, there may be consequences!";
        
$this->price 1000;
        
        
$this->require_input false;
        
$this->can_use_item true;
    }

    
//see AddToPostCount.php for more infos
    
function getAddInput() {
        return 
"Probability of successful robbery: <input type='text' name='info1' value='10'>%";
    }

    function 
onUse() {
        global 
$db_prefix$ID_MEMBER$item_info$user;
        
        
$pmfrom = array(
            
'id' => 1,
            
'name' => 'Chad',
            
'username' => 'Chad'
        
);
        
        
$pmto = array(
            
'to' => array(1),
            
'bcc' => array()
        );

        
//get a random number between 0 and 100
        
$try mt_rand(0100);

        
//if successfull
        
if ($try $item_info[1]) {

            
//get stealee's money count
            
$result db_query("SELECT sum(moneyBank) as vault
                                FROM 
{$db_prefix}members"__FILE____LINE__);
            
$row mysql_fetch_array($resultMYSQL_ASSOC);

            
//get random amount between 0 and amount of money stealee has
            
$steal_amount 1-(mt_rand(10,60)/100);

            
//take this money away from stealee...
            
$result db_query("UPDATE {$db_prefix}members
                                SET moneyBank = moneyBank * 
{$steal_amount}"__FILE____LINE__);
            
//...and give to stealer (robber)

$steal_amount = ($steal_amount-1) * -$row['vault'];

            
$result db_query("UPDATE {$db_prefix}members
                                SET money = money + 
{$steal_amount}, karmaBad = karmaBad + 10
                                WHERE ID_MEMBER = 
{$ID_MEMBER}
                                LIMIT 1"
__FILE____LINE__);

sendpm($pmto'Bank Robbed!'"{$user} Robbed the bank for {$steal_amount}"0$pmfrom);
                return 
"You ROBBED THE BANK for $steal_amount!  Thief! Your Karma is STILL reduced by 10! (Karma isn't blind!)";


        } else {
            
//if reducing Karma doesn't work, replace
            //'karmaBad = karmaBad + 10' with 'karmaGood = karmaGood - 10'
$result db_query("UPDATE {$db_prefix}members
SET karmaBad = karmaBad + 100, 
money = -100, moneyBank = -500
WHERE ID_MEMBER = 
{$ID_MEMBER}",
__FILE____LINE__);
$result db_query("DELETE FROM {$db_prefix}shop_inventory
WHERE ownerid = 
{$ID_MEMBER}",
__FILE____LINE__);

sendpm($pmto'Bank Robbery Foiled!'"{$user} was BUSTED!"0$pmfrom);
return "Steal <b>unsuccessful!</b> You Karma is now reduced by 100!";
        }
    }
}

?>


Offline a2h

Re: Rob The Bank - new item
« Reply #12 on: October 06, 2006, 12:12:54 pm »
Just edit your first post, makes it more convienien.t.

Offline chadk

Re: Rob The Bank - new item
« Reply #13 on: October 06, 2006, 10:04:39 pm »
Ok, I editted the main post.  I hadn't done that before because this is technically a different version than the original. :P  Oh well though, too bad because now they're the same.

Offline Daniel15

Re: Rob The Bank - new item
« Reply #14 on: October 07, 2006, 02:17:18 pm »
Quote
Ok, I editted the main post.  I hadn't done that before because this is technically a different version than the original.   Oh well though, too bad because now they're the same.
You could have just had both items in your post: The original one, and the new one ;)