Author Topic: Steal Credits Item  (Read 7784 times)

Offline jdv

Steal Credits Item
« on: March 22, 2007, 10:37:57 am »
Can i get the steal credits 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.

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

Thanks.
John

Offline inkstains

Re: Steal Credits Item
« Reply #1 on: March 23, 2007, 02:43:43 pm »
i think this will work though i haven't tested

Code: [Select]
<?php
/**********************************************************************************
* SMFShop item                                                                    *
***********************************************************************************
* SMFShop: Shop MOD for Simple Machines Forum                                     *
* =============================================================================== *
* Software Version:           SMFShop 3.0 (Build 12)                              *
* $Date:: 2007-01-18 19:26:55 +1100 (Thu, 18 Jan 2007)                          $ *
* $Id:: Steal.php 79 2007-01-18 08:26:55Z daniel15                              $ *
* Software by:                DanSoft Australia (http://www.dansoftaustralia.net/)*
* Copyright 2005-2007 by:     DanSoft Australia (http://www.dansoftaustralia.net/)*
* Support, News, Updates at:  http://www.dansoftaustralia.net/                    *
*                                                                                 *
* Forum software by:          Simple Machines (http://www.simplemachines.org)     *
* Copyright 2006-2007 by:     Simple Machines LLC (http://www.simplemachines.org) *
*           2001-2006 by:     Lewis Media (http://www.lewismedia.com)             *
***********************************************************************************
* This program is free software; you may redistribute it and/or modify it under   *
* the terms of the provided license as published by Simple Machines LLC.          *
*                                                                                 *
* This program is distributed in the hope that it is and will be useful, but      *
* WITHOUT ANY WARRANTIES; without even any implied warranty of MERCHANTABILITY    *
* or FITNESS FOR A PARTICULAR PURPOSE.                                            *
*                                                                                 *
* See the "license.txt" file for details of the Simple Machines license.          *
* The latest version of the license can always be found at                        *
* http://www.simplemachines.org.                                                  *
**********************************************************************************/

if (!defined('SMF'))
die('Hacking attempt...');

class 
item_Steal extends itemTemplate
{
function getItemDetails()
{
$this->authorName 'Daniel15';
$this->authorWeb 'http://www.dansoftaustralia.net/';
$this->authorEmail 'dansoft@dansoftaustralia.net';

$this->name 'Steal Credits';
$this->desc 'Try to steal credits from another member!';
$this->price 50;

$this->require_input true;
$this->can_use_item true;
}

function getAddInput()
{
global $item_info;
if ($item_info[1] == 0$item_info[1] = 100;
return 'For steal, user <b>does NOT need to, and shouldn\'t</b> know the probability! It\'s more fun this way :-)<br />Probability of successful steal: <input type="text" name="info1" value="' $item_info[1]  . '" />%';
}

function getUseInput()
{
global $context$scripturl$settings$txt;
return 'Steal From: <input type="text" name="stealfrom" id="membername" size="50" />
<a href="' 
$scripturl '?action=findmember;input=membername;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><br />';
}

function onUse()
{
global $db_prefix$ID_MEMBER$item_info;

// Check some inputs
if (!isset($_POST['stealfrom']) || $_POST['stealfrom'] == '') die('ERROR: Please enter a username to steal from!');

// This code from PersonalMessage.php5. It trims the " characters off the membername posted, 
// and then puts all names into an array
$_POST['stealfrom'] = strtr($_POST['stealfrom'], array('\\"' => '"'));
preg_match_all('~"([^"]+)"~'$_POST['stealfrom'], $matches);
$userArray array_unique(array_merge($matches[1], explode(','preg_replace('~"([^"]+)"~'''$_POST['stealfrom']))));

// We only want the first memberName found
$user $userArray[0];

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

// If successful
if ($try $item_info[1])
{

// Get stealee's (person we're stealing from) money count
$result db_query("
SELECT money
FROM 
{$db_prefix}members
WHERE memberName = '
{$user}'"__FILE____LINE__);

// If user doesn't exist
if (mysql_num_rows($result) == 0)
die('ERROR: The specified user doesn\'t exist!');

$row mysql_fetch_assoc($result);

// Get random amount between 0 and amount of money stealee has
$steal_amount mt_rand(0$row['money']);

// Take this money away from stealee...
$result db_query("
UPDATE 
{$db_prefix}members
SET money = money - 
{$steal_amount}
WHERE memberName = '
{$user}'
LIMIT 1"
__FILE____LINE__);
//...and give to stealer (robber)
$result db_query("
UPDATE 
{$db_prefix}members
SET money = money + 
{$steal_amount}
WHERE ID_MEMBER = 
{$ID_MEMBER}
LIMIT 1"
__FILE____LINE__);

if ($steal_amount 50)
return 'Steal successful, although you only stole ' $steal_amount '!';
else
return 'Successfully stole ' $steal_amount ' from ' $user '! It\'s their fault they don\'t have their money in the bank!';
}
}
}

?>


Offline jdv

Re: Steal Credits Item
« Reply #2 on: March 23, 2007, 08:31:34 pm »
It works like i want when successful. And unsuccesfful. However; when unsuccessful its blank. Can we make it at least say "Sorry you were unsuccessful, try again."

by the way, thank you inkstains.

Offline inkstains

Re: Steal Credits Item
« Reply #3 on: March 23, 2007, 09:12:23 pm »
no prob

this should work but again i haven't tested yet

Code: [Select]
<?php
/**********************************************************************************
* SMFShop item                                                                    *
***********************************************************************************
* SMFShop: Shop MOD for Simple Machines Forum                                     *
* =============================================================================== *
* Software Version:           SMFShop 3.0 (Build 12)                              *
* $Date:: 2007-01-18 19:26:55 +1100 (Thu, 18 Jan 2007)                          $ *
* $Id:: Steal.php 79 2007-01-18 08:26:55Z daniel15                              $ *
* Software by:                DanSoft Australia (http://www.dansoftaustralia.net/)*
* Copyright 2005-2007 by:     DanSoft Australia (http://www.dansoftaustralia.net/)*
* Support, News, Updates at:  http://www.dansoftaustralia.net/                    *
*                                                                                 *
* Forum software by:          Simple Machines (http://www.simplemachines.org)     *
* Copyright 2006-2007 by:     Simple Machines LLC (http://www.simplemachines.org) *
*           2001-2006 by:     Lewis Media (http://www.lewismedia.com)             *
***********************************************************************************
* This program is free software; you may redistribute it and/or modify it under   *
* the terms of the provided license as published by Simple Machines LLC.          *
*                                                                                 *
* This program is distributed in the hope that it is and will be useful, but      *
* WITHOUT ANY WARRANTIES; without even any implied warranty of MERCHANTABILITY    *
* or FITNESS FOR A PARTICULAR PURPOSE.                                            *
*                                                                                 *
* See the "license.txt" file for details of the Simple Machines license.          *
* The latest version of the license can always be found at                        *
* http://www.simplemachines.org.                                                  *
**********************************************************************************/

if (!defined('SMF'))
die('Hacking attempt...');

class 
item_Steal extends itemTemplate
{
function getItemDetails()
{
$this->authorName 'Daniel15';
$this->authorWeb 'http://www.dansoftaustralia.net/';
$this->authorEmail 'dansoft@dansoftaustralia.net';

$this->name 'Steal Credits';
$this->desc 'Try to steal credits from another member!';
$this->price 50;

$this->require_input true;
$this->can_use_item true;
}

function getAddInput()
{
global $item_info;
if ($item_info[1] == 0$item_info[1] = 100;
return 'For steal, user <b>does NOT need to, and shouldn\'t</b> know the probability! It\'s more fun this way :-)<br />Probability of successful steal: <input type="text" name="info1" value="' $item_info[1]  . '" />%';
}

function getUseInput()
{
global $context$scripturl$settings$txt;
return 'Steal From: <input type="text" name="stealfrom" id="membername" size="50" />
<a href="' 
$scripturl '?action=findmember;input=membername;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><br />';
}

function onUse()
{
global $db_prefix$ID_MEMBER$item_info;

// Check some inputs
if (!isset($_POST['stealfrom']) || $_POST['stealfrom'] == '') die('ERROR: Please enter a username to steal from!');

// This code from PersonalMessage.php5. It trims the " characters off the membername posted, 
// and then puts all names into an array
$_POST['stealfrom'] = strtr($_POST['stealfrom'], array('\\"' => '"'));
preg_match_all('~"([^"]+)"~'$_POST['stealfrom'], $matches);
$userArray array_unique(array_merge($matches[1], explode(','preg_replace('~"([^"]+)"~'''$_POST['stealfrom']))));

// We only want the first memberName found
$user $userArray[0];

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

// If successful
if ($try $item_info[1])
{

// Get stealee's (person we're stealing from) money count
$result db_query("
SELECT money
FROM 
{$db_prefix}members
WHERE memberName = '
{$user}'"__FILE____LINE__);

// If user doesn't exist
if (mysql_num_rows($result) == 0)
die('ERROR: The specified user doesn\'t exist!');

$row mysql_fetch_assoc($result);

// Get random amount between 0 and amount of money stealee has
$steal_amount mt_rand(0$row['money']);

// Take this money away from stealee...
$result db_query("
UPDATE 
{$db_prefix}members
SET money = money - 
{$steal_amount}
WHERE memberName = '
{$user}'
LIMIT 1"
__FILE____LINE__);
//...and give to stealer (robber)
$result db_query("
UPDATE 
{$db_prefix}members
SET money = money + 
{$steal_amount}
WHERE ID_MEMBER = 
{$ID_MEMBER}
LIMIT 1"
__FILE____LINE__);

if ($steal_amount 50)
return 'Steal successful, although you only stole ' $steal_amount '!';
else
return 'Successfully stole ' $steal_amount ' from ' $user '! It\'s their fault they don\'t have their money in the bank!';
}
else
{return 'Steal unsuccessful please try again';}
}
}

?>

Offline jdv

Re: Steal Credits Item
« Reply #4 on: March 23, 2007, 10:37:21 pm »
appears to be working good.

Offline inkstains

Re: Steal Credits Item
« Reply #5 on: March 25, 2007, 12:09:25 am »

Offline ibexy

Re: Steal Credits Item
« Reply #6 on: July 04, 2007, 07:22:30 pm »
Is it possible to make this option send a pm to the person who was robbed and another to the admin. Please.

Offline AgentTofu

Re: Steal Credits Item
« Reply #7 on: August 06, 2007, 04:04:33 pm »
Getting a major bug error when some steals from someone with low credits. If the steal is successful, and gives more credits than the victim user actually has, then the victim user is given 4294967295 credits!

Any help?

Offline feildmaster

Re: Steal Credits Item
« Reply #8 on: August 07, 2007, 12:40:05 am »
I dunno, it shouldn't do that, seeing as the random is 0 - total money user has.

Offline AgentTofu

Re: Steal Credits Item
« Reply #9 on: August 07, 2007, 01:33:12 pm »
Yes, it is happening over and over now.

Is there any specific points in the Steal.php I should be looking for? Or other php files?

Offline inkstains

Re: Steal Credits Item
« Reply #10 on: August 08, 2007, 10:38:32 am »
Yes, it is happening over and over now.

Is there any specific points in the Steal.php I should be looking for? Or other php files?

like fieldmaster said that shouldn't be happening. got a link to your site?