SMF Shop
SMFShop => Items => Topic started by: tazpot on April 21, 2006, 05:59:02 am
-
After a look at Basil Beards unofficial item tutorial i have created my first item and would like to share it with you. To use this item copy the code and save it as KarmaBash.php then add it to... smf/sources/shop/items
It is an item to remove 10 karma points of another member. :buck2:
<?php
/**********************************************\
| SMFSHOP (Shop MOD for Simple Machines Forum) |
| (c) 2005 DanSoft Australia |
| http://www.dansoftaustralia.com/ |
\**********************************************/
//File: KarmaBash.php
// Item
//VERSION: 1.1 (Build 4)
//DATE: 10th April 2005
//Author Tazpot
//Helped by Basil Beard
class item_KarmaBash extends itemTemplate {
function getItemDetails() {
$this->name = "Karma Bash";
$this->desc = "Bash 10 points of another members karma";
$this->price = 50;
$this->require_input = true;
$this->can_use_item = true;
}
function getUseInput() {
global $context, $scripturl, $settings, $txt;
return "Karma Bash: <input type='text' name='bashwho' size='50'>
<a href='{$scripturl}?action=findmember;input=bashwho;quote=0;sesc={$context['session_id']}' onclick='return reqWin(this.href, 350, 400);'><img src='{$settings['images_url']}/icons/assist.gif' border='0' alt='{$txt['find_members']}' /> Find Member</a>";
}
function onUse() {
global $db_prefix, $ID_MEMBER, $item_info;
$result = db_query("UPDATE {$db_prefix}members
SET karmaBad = karmaBad + 10
WHERE membername = '{$_POST['bashwho']}'"
,__FILE__, __LINE__);
return "Successfully bashed 10 karma points from {$_POST['bashwho']}!";
$result = db_query("SELECT ID_MEMBER
FROM {$db_prefix}members
WHERE memberName = '{$_POST[‘bashwho’]}'", __FILE__, __LINE__);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$pmfrom = array(
'id' => 1,
'name' => 'Tazpot',
'username' => 'Tazpot'
);
$pmto = array(
'to' => array($row['ID_MEMBER']),
'bcc' => array()
);
sendpm($pmto, 'You have been bashed', "{$user} bashed 10 points off your karma! [i] You do not need to reply to this automated message[/i]", 0, $pmfrom);
return "You have bashed {$_POST['bashwho']} for 10 points off their karma!";
}
}
?>
-
Hey, I like the mod. I have a rather wacky community of users myself who seem to delight in bashing others... Anyway, I was curious if you have a version of this that would allow the administrators to set the actual value (currently -10) of the bash from the admin panel, w/o having to go in and change code manually?
-
Sorry i don't but all you have to do to change the amount is edit a few bit's in the code.......
change the 10 to whatever you want in each of the following and then upload the edited page
$this->desc = "Bash 10 points of another members karma";
SET karmaBad = karmaBad + 10
return "Successfully bashed 10 karma points from {$_POST['bashwho']}!";
sendpm($pmto, 'You have been bashed', "{$user} bashed 10 points off your karma! [i] You do not need to reply to this automated message[/i]", 0, $pmfrom);
return "You have bashed {$_POST['bashwho']} for 10 points off their karma!";
and all should be fine. (always save the origional just in case)
Hope this helps
-
Here you go, a version that prompts you for a value when you add it to the shop. It's not tested by me, but should work. I've also tried to fix the tabbing in the file :)
<?php
/**********************************************\
| SMFSHOP (Shop MOD for Simple Machines Forum) |
| (c) 2005 DanSoft Australia |
| http://www.dansoftaustralia.com/ |
\**********************************************/
//File: KarmaBash.php
// Item
//VERSION: 1.1 (Build 4)
//DATE: 10th April 2005
//Author Tazpot
//Helped by Basil Beard
// Slightly modified by Daniel15
class item_KarmaBash extends itemTemplate {
function getItemDetails() {
$this->name = "Karma Bash";
$this->desc = "Bash xx points of another members karma";
$this->price = 50;
$this->require_input = true;
$this->can_use_item = true;
}
function getAddInput() {
return "Amount to reduce karma by: <input type='text' name='info1' value='100'>";
}
function getUseInput() {
global $context, $scripturl, $settings, $txt;
return "Karma Bash: <input type='text' name='bashwho' size='50'>
<a href='{$scripturl}?action=findmember;input=bashwho;quote=0;sesc={$context['session_id']}' onclick='return reqWin(this.href, 350, 400);'><img src='{$settings['images_url']}/icons/assist.gif' border='0' alt='{$txt['find_members']}' /> Find Member</a>";
}
function onUse() {
global $db_prefix, $ID_MEMBER, $item_info;
$result = db_query("UPDATE {$db_prefix}members
SET karmaBad = karmaBad + {$item_info[1]}
WHERE membername = '{$_POST['bashwho']}'"
,__FILE__, __LINE__);
return "Successfully bashed {$item_info[1]} karma points from {$_POST['bashwho']}!";
$result = db_query("SELECT ID_MEMBER
FROM {$db_prefix}members
WHERE memberName = '{$_POST['bashwho']}'", __FILE__, __LINE__);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$pmfrom = array(
'id' => 1,
'name' => 'Tazpot',
'username' => 'Tazpot'
);
$pmto = array(
'to' => array($row['ID_MEMBER']),
'bcc' => array()
);
sendpm($pmto, 'You have been bashed', "{$user} bashed {$item_info[1]} points off your karma! [i] You do not need to reply to this automated message[/i]", 0, $pmfrom);
return "You have bashed {$_POST['bashwho']} for {$item_info[1]} points off their karma!";
}
}
?>
-
well, why only bashing? We can boost karma points as well
I did some minor modifications to tazpot/daniel15's files and I creeated "KarmaBoost"; I tested, it works (I have no expertise whatsoever in scripting, I just did it intuitively).
<?php
/**********************************************\
| SMFSHOP (Shop MOD for Simple Machines Forum) |
| (c) 2005 DanSoft Australia |
| http://www.dansoftaustralia.com/ |
\**********************************************/
//File: KarmaBoost.php
// Item
//VERSION: 1.1 (Build 4)
//DATE: 1st August 2006
//Author Tazpot
//Helped by Basil Beard
// Slightly modified by Daniel15
// Further modified by Tapirul
class item_KarmaBoost extends itemTemplate {
function getItemDetails() {
$this->name = "Karma Boost";
$this->desc = "Boost xx points for another members karma";
$this->price = 50;
$this->require_input = true;
$this->can_use_item = true;
}
function getAddInput() {
return "Amount to increase karma by: <input type='text' name='info1' value='100'>";
}
function getUseInput() {
global $context, $scripturl, $settings, $txt;
return "Karma Boost: <input type='text' name='boostwho' size='50'>
<a href='{$scripturl}?action=findmember;input=boostwho;quote=0;sesc={$context['session_id']}' onclick='return reqWin(this.href, 350, 400);'><img src='{$settings['images_url']}/icons/assist.gif' border='0' alt='{$txt['find_members']}' /> Find Member</a>";
}
function onUse() {
global $db_prefix, $ID_MEMBER, $item_info;
$result = db_query("UPDATE {$db_prefix}members
SET karmaGood = karmaGood + {$item_info[1]}
WHERE membername = '{$_POST['boostwho']}'"
,__FILE__, __LINE__);
return "Successfully boosted {$item_info[1]} karma points for {$_POST['boostwho']}!";
$result = db_query("SELECT ID_MEMBER
FROM {$db_prefix}members
WHERE memberName = '{$_POST['boostwho']}'", __FILE__, __LINE__);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$pmfrom = array(
'id' => 1,
'name' => 'tazpot',
'username' => 'tazpot'
);
$pmto = array(
'to' => array($row['ID_MEMBER']),
'bcc' => array()
);
sendpm($pmto, 'You have been boosted', "{$user} boosted {$item_info[1]} points for your karma! [i] You do not need to reply to this automated message[/i]", 0, $pmfrom);
return "You have boosted {$_POST['boostwho']} for {$item_info[1]} points for their karma!";
}
}
?>
Now, the only things would be to record the points bashed/boosted to KarmaLog (from Karma Description Mod (http://mods.simplemachines.org/index.php?mod=192), and to prevent boosting own karma.....Any help with that?
Thanks
-
Hi, I'm new to all this coding malarky but I had a go on an adaptation of this script whereby you can take a random amount of karma. You can set (the maximum and minimum) when you make the item in the shop.
<?php
/**********************************************\
| SMFSHOP (Shop MOD for Simple Machines Forum) |
| (c) 2005 DanSoft Australia |
| http://www.dansoftaustralia.com/ |
\**********************************************/
//File: KarmaBash2.php
// Item
//VERSION: 1.1 (Build 4)
//DATE: 10th April 2005
//Author Tazpot
//Helped by Basil Beard
// Slightly modified by Daniel15 and War Chief
class item_KarmaBash2 extends itemTemplate {
function getItemDetails() {
$this->name = "Karma Bash 2";
$this->desc = "Bash xx points of another members karma";
$this->price = 50;
$this->require_input = true;
$this->can_use_item = true;
}
function getAddInput() {
return "Minimum karma removed: <input type='text' name='info1' value='1'><br>
Maximum karma removed: <input type='text' name='info2' value='10'>";
}
function getUseInput() {
global $context, $scripturl, $settings, $txt;
return "Karma Bash: <input type='text' name='bashwho' size='50'>
<a href='{$scripturl}?action=findmember;input=bashwho;quote=0;sesc={$context['session_id']}' onclick='return reqWin(this.href, 350, 400);'><img src='{$settings['images_url']}/icons/assist.gif' border='0' alt='{$txt['find_members']}' /> Find Member</a>";
}
function onUse() {
global $db_prefix, $ID_MEMBER, $item_info;
$amount = mt_rand($item_info[1], $item_info[2]);
$result = db_query("UPDATE {$db_prefix}members
SET karmaBad = karmaBad + {$amount}
WHERE membername = '{$_POST['bashwho']}'"
,__FILE__, __LINE__);
return "Successfully bashed {$amount} karma points from {$_POST['bashwho']}!";
$result = db_query("SELECT ID_MEMBER
FROM {$db_prefix}members
WHERE memberName = '{$_POST['bashwho']}'", __FILE__, __LINE__);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$pmfrom = array(
'id' => 1,
'name' => 'Tazpot',
'username' => 'Tazpot'
);
$pmto = array(
'to' => array($row['ID_MEMBER']),
'bcc' => array()
);
sendpm($pmto, 'You have been bashed', "{$user} bashed {$amount} points off your karma! [i] You do not need to reply to this automated message[/i]", 0, $pmfrom);
return "You have bashed {$_POST['bashwho']} for {$amount} points off their karma!";
}
}
?>
-
What prevents users from using this on themselves?
-
All these versions work fantastic on my 1.1.6