SMF Shop

SMFShop => Items => Topic started by: chadk on September 27, 2006, 03:08:28 am

Title: Rob The Bank - new item
Post by: chadk 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!";
        }
    }
}

?>
Title: Re: Rob The Bank - new item
Post by: chadk 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.
Title: Re: Rob The Bank - new item
Post by: Daniel15 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
Title: Re: Rob The Bank - new item
Post by: chadk on September 30, 2006, 11:00:05 pm
cool.. cool!  Thanks Daniel.
Title: Re: Rob The Bank - new item
Post by: chadk on September 30, 2006, 11:15:13 pm
hmmm nope that didn't work.
Title: Re: Rob The Bank - new item
Post by: Basil Beard 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
Title: Re: Rob The Bank - new item
Post by: Daniel15 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)
Title: Re: Rob The Bank - new item
Post by: chadk 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.
Title: Re: Rob The Bank - new item
Post by: TechnoDragon 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
Title: Re: Rob The Bank - new item
Post by: chadk 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.
Title: Re: Rob The Bank - new item
Post by: dcd119 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..
Title: Re: Rob The Bank - new item
Post by: chadk 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!";
        }
    }
}

?>

Title: Re: Rob The Bank - new item
Post by: a2h on October 06, 2006, 12:12:54 pm
Just edit your first post, makes it more convienien.t.
Title: Re: Rob The Bank - new item
Post by: chadk 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.
Title: Re: Rob The Bank - new item
Post by: Daniel15 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 ;)
Title: Re: Rob The Bank - new item
Post by: tazpot on October 08, 2006, 04:54:30 am
Excellent piece of work chadk i have been looking for something like this for a long. My members are so excited  :D
Title: Re: Rob The Bank - new item
Post by: Albadon on October 08, 2006, 05:50:36 am
Hi there! This is my first post in this forum. I would like to express my total satisfaction about SMFshop. It is a GREAT mod. Excellent work Daniel!

About this item now... I can't get it to work. I get the following whe uploading it:

Code: [Select]
Fatal error: Cannot instantiate non-existent class: item_robbank in /home/examino/public_html/forum/Sources/shop/ShopAdmin.php(174) : eval()'d code on line 1
I succesfully installed Armageddon for instance. Tha sounds a little weird to me. Is it?

Title: Re: Rob The Bank - new item
Post by: chadk on October 08, 2006, 05:54:11 am
Albadon: make sure you save the file as:
RobTheBank.php
Title: Re: Rob The Bank - new item
Post by: Albadon on October 08, 2006, 06:05:51 am
Yeap! That did it! What a full not to see the problem before posting. Anyway, thank you chadk.
Title: Re: Rob The Bank - new item
Post by: Daniel15 on October 08, 2006, 10:48:52 am
Indeed, you must save the item with the correct name, as it gets the class name based on the file name. If you name it 'robbank.php', it will be looking for an item class called item_robbank (like in your error above). However, the class is actually called item_RobTheBank ;)
Title: Re: Rob The Bank - new item
Post by: chadk on October 09, 2006, 09:16:40 am
Now we'll see how excited your members are when the ROB the bank.. muahhahaha Mine haven't even tried since I changed the negative side effects of failure.
Title: Re: Rob The Bank - new item
Post by: tazpot on October 12, 2006, 07:29:03 am
chadk  how would i go about changing the negative side effects so that it empties there inventory but only removes a % of their credits not all of them?
Title: Re: Rob The Bank - new item
Post by: Daniel15 on October 13, 2006, 07:24:08 pm
Quote
chadk  how would i go about changing the negative side effects so that it empties there inventory but only removes a % of their credits not all of them?

Change:

$result = db_query("UPDATE {$db_prefix}members
SET karmaBad = karmaBad + 100,
money = -100, moneyBank = -500
WHERE ID_MEMBER = {$ID_MEMBER}",
__FILE__, __LINE__);


To:

$result = db_query("UPDATE {$db_prefix}members
SET karmaBad = karmaBad + 100,
money = (money * 0.2), moneyBank = -500
WHERE ID_MEMBER = {$ID_MEMBER}",
__FILE__, __LINE__);


Change the 'money = (money * 0.2)' to whatever you want. money = (money * 0.2) means to set the amount of money to 20% of the original amount.
Title: Re: Rob The Bank - new item
Post by: tazpot on October 14, 2006, 04:06:58 am
 O0  Cheers daniel that is perfect. I think the losing all money scared a few people so i will try it at 50%  O0
Title: Re: Rob The Bank - new item
Post by: Albadon on October 15, 2006, 11:21:11 pm
Now we'll see how excited your members are when the ROB the bank.. muahhahaha Mine haven't even tried since I changed the negative side effects of failure.

LOL. I guess they are gonna kill me! LOL!
Title: Re: Rob The Bank - new item
Post by: tazpot on November 12, 2006, 08:44:45 pm
When someone robs the bank i get a PM telling me the bank was robbed and by how much but it is missing the name of who commited the crime?

here is the send PM code:
Code: [Select]
sendpm($pmto, 'Bank Robbed!', "{$user} Robbed the bank for {$steal_amount}", 0, $pmfrom);
                return "You FLEECED THE BANK for $steal_amount bags of wool!  Thief! Your Karma is STILL reduced by 10! (Karma isn't blind!)";

have i done something is there another reason?
Title: Re: Rob The Bank - new item
Post by: Edwin on December 11, 2006, 03:46:42 am
This one should go in /Sources/shop ?

I can't find it in the drop-down menu for the shop items
Title: Re: Rob The Bank - new item
Post by: feeble on December 11, 2006, 10:33:32 am
This one should go in /Sources/shop ?

I can't find it in the drop-down menu for the shop items

you need to copy the code in the first post and paste it in a file called RobTheBank.php (either create a txt file and change it to php or use dream weaver(or equivalent)
then upload that file to
/Sources/shop/items/
Title: Re: Rob The Bank - new item
Post by: jdv on March 22, 2007, 10:41:38 am
Can i get the rob the bank item coded where it has no effect on karma whether your successful or not. I want to keep karma out of it. You either steal money or you you dont. Also where you dont lose all your money just because you were unsuccessful. Its either you successful or not. Succesfful you rob the bank, your not succesfful, nothing happens.

I have tried and tried, but it keeps giving/taking karma. I want the item but without the karma being added/taken. Takes the money.

Thanks.
John
Title: Re: Rob The Bank - new item
Post by: MuNiX on March 29, 2007, 02:19:49 am
When someone robs the bank i get a PM telling me the bank was robbed and by how much but it is missing the name of who commited the crime?
Change:
global $user;   
To: 
global $user_info;

Change:
Code: [Select]
        $pmfrom = array(
            'id' => 1,
            'name' => 'Chad',
            'username' => 'Chad'
        );
To:
Code: [Select]
$pmfrom = array(
            'id' => $ID_MEMBER,
            'name' => $user_info['name'],
            'username' => $user_info['username']
        );

And Change this:
Code: [Select]
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!)";
To:
Code: [Select]
sendpm($pmto, 'Bank Robbed!', "{$user_info['name']} 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!)";

 ;)
Title: Re: Rob The Bank - new item
Post by: perplexed on April 19, 2007, 11:22:48 am
I did the above changes but I still cant get the name to show in the PMs.  I could only see one global $user in the file, but when I changed that, the PM said 'Array was BUSTED'  lol

Also it took all my money in pocket and bank and all my inventory and 100 karma.

I really need to change this so its not so severe, can you tell me the details of what to edit please?  :D

thanks
Title: Re: Rob The Bank - new item
Post by: Alundra on October 04, 2007, 11:47:54 am
can someone update this so that the PM goes to the user who actually robbed the bank?

thankyou
Title: Re: Rob The Bank - new item
Post by: MasterDKR on March 15, 2008, 09:35:22 am
how do i add this in to the shop
Title: Re: Rob The Bank - new item
Post by: City Builder on May 19, 2008, 02:59:41 am
Aha, so that's why all my stuff disappeared then.  I tried this on my own site to see what would happen, and get -100 karma and all the items that I had, (including our collectibles collections) disappeared from my inventory.

Guess I better read the whole thread before I try any more of these items.  Actually I'd like to get this without the removing all the item from the users inventory as we have some things that should not be removed from the inventory.  Any chance of getting that version?
Title: Re: Rob The Bank - new item
Post by: cjb204 on May 05, 2010, 05:34:16 am
I keep getting syntax errors...

Using SMF 2 RC3.
Title: Re: Rob The Bank - new item
Post by: vbgamer45 on May 06, 2010, 06:00:44 pm
The item needs to be updated to SMF 2.0 RC3
Title: Re: Rob The Bank - new item
Post by: cjb204 on May 07, 2010, 03:05:39 am
How would I go about doing that? Is there a guide somewhere, or does it just involve changing a few things, or what?