SMF Shop
SMFShop => Items => Topic started 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.
<?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(0, 100);
//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($result, MYSQL_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) * -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!";
}
}
}
?>
-
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.
-
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
-
cool.. cool! Thanks Daniel.
-
hmmm nope that didn't work.
-
$user is just like any other global variable.
You want <?php
global $user;
Daniel forgot the space. =P
-
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)
-
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.
-
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
-
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.
-
yah I added this to my forum... pissed alot of people off...lol
its not real they keep getting told..
-
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):
<?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(0, 100);
//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($result, MYSQL_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) * -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!";
}
}
}
?>
-
Just edit your first post, makes it more convienien.t.
-
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.
-
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 ;)
-
Excellent piece of work chadk i have been looking for something like this for a long. My members are so excited :D
-
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:
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?
-
Albadon: make sure you save the file as:
RobTheBank.php
-
Yeap! That did it! What a full not to see the problem before posting. Anyway, thank you chadk.
-
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 ;)
-
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.
-
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?
-
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.
-
O0 Cheers daniel that is perfect. I think the losing all money scared a few people so i will try it at 50% O0
-
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!
-
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:
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?
-
This one should go in /Sources/shop ?
I can't find it in the drop-down menu for the shop items
-
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/
-
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
-
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:
$pmfrom = array(
'id' => 1,
'name' => 'Chad',
'username' => 'Chad'
);
To:
$pmfrom = array(
'id' => $ID_MEMBER,
'name' => $user_info['name'],
'username' => $user_info['username']
);
And Change this:
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:
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!)";
;)
-
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
-
can someone update this so that the PM goes to the user who actually robbed the bank?
thankyou
-
how do i add this in to the shop
-
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?
-
I keep getting syntax errors...
Using SMF 2 RC3.
-
The item needs to be updated to SMF 2.0 RC3
-
How would I go about doing that? Is there a guide somewhere, or does it just involve changing a few things, or what?