Author Topic: Karma Bash item  (Read 6970 times)

Offline tazpot

Karma Bash item
« 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:

Code: [Select]
<?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($resultMYSQL_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!";
}
}
?>

« Last Edit: May 09, 2006, 07:42:31 am by tazpot »

Quixjote

  • Guest
Re: Karma Bash item
« Reply #1 on: June 16, 2006, 03:05:36 am »
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?

Offline tazpot

Re: Karma Bash item
« Reply #2 on: June 18, 2006, 11:53:18 pm »
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

Code: [Select]
$this->desc = "Bash 10 points of another members karma";
Code: [Select]
SET karmaBad = karmaBad + 10
Code: [Select]
return "Successfully bashed 10 karma points from {$_POST['bashwho']}!";
Code: [Select]
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

Offline Daniel15

Re: Karma Bash item
« Reply #3 on: June 23, 2006, 10:22:24 pm »
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 :)

Code: [Select]
<?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($resultMYSQL_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!";
    }
}
?>

« Last Edit: June 23, 2006, 10:26:03 pm by daniel15 »

Offline tapirul

Re: Karma Bash item
« Reply #4 on: August 02, 2006, 03:23:01 pm »
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).

Code: [Select]
<?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($resultMYSQL_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, and to prevent boosting own karma.....Any help with that?
Thanks
« Last Edit: August 02, 2006, 03:48:53 pm by tapirul »

Offline War Chief

Re: Karma Bash item
« Reply #5 on: August 22, 2006, 02:14:31 am »
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.

Code: [Select]
<?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($resultMYSQL_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!";
    }
}
?>

Offline chadk

Re: Karma Bash item
« Reply #6 on: September 27, 2006, 03:54:11 am »
What prevents users from using this on themselves?

Offline mike dijital

Re: Karma Bash item
« Reply #7 on: October 17, 2008, 06:54:46 am »
All these versions work fantastic on my 1.1.6