Author Topic: [REQUEST] Change money with aleatory member  (Read 2683 times)

Offline jmordenata

[REQUEST] Change money with aleatory member
« on: April 28, 2007, 08:23:13 pm »
I'd like to have an item to change your money with an aleatory member


Thanks

Offline feeble

Re: [REQUEST] Change money with aleatory member
« Reply #1 on: April 28, 2007, 09:34:41 pm »
you can say random :)

so like steal?

or do you want to change another uses money?

note:to pull random call
db_query("SELECT * FROM {$db_prefix}members ORDER BY RAND() LIMIT 1");
« Last Edit: April 28, 2007, 09:39:36 pm by feeble »

Offline jmordenata

Re: [REQUEST] Change money with aleatory member
« Reply #2 on: April 28, 2007, 09:54:33 pm »
Ok, ssorry, i'm spanish, but I try to have a good english xD.

Well, it's not to steal, it is to change money, if for example daniel15 has 1000 credits and you have 200, if you use the item changes the amount of credits, do you understand?

Offline feeble

Re: [REQUEST] Change money with aleatory member
« Reply #3 on: April 28, 2007, 11:09:20 pm »
try this item here

wasnt sure exactly what you wanted, this will Swap users credits depending on probability. I basically stole the code from Steal item as a quick reference.

so basically, using your example. daniel15 has 1000 credits and you have 200. after using item and its successful, daniel15 has 200 credits and you have 1000

copy and paste the code into Swap.php

   
Traducción española: intentar este artículo aquí el wasnt seguro exactamente qué deseaste, esto intercambiará créditos de los usuarios dependiendo de probabilidad. I robó básicamente el código de roba el artículo como referencia rápida. tan básicamente, usando tu ejemplo. daniel15 tiene 1000 créditos y tienes 200. después de usar el artículo y su acertado, daniel15 tiene 200 créditos y tienes 1000 la copia y pega el código en Swap.php

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_Swap extends itemTemplate
{
function getItemDetails()
{
$this->authorName 'Feeble';
$this->authorWeb 'http://www.leaderless.net/';
$this->authorEmail 'tsaphin@gmail.com';

$this->name 'Swap Credits';
$this->desc 'Swap Credits!';
$this->price 200;

$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 swap, user <b>does NOT need to, and shouldn\'t</b> know the probability! It\'s more fun this way :-)<br />Probability of successful swap: <input type="text" name="info1" value="' $item_info[1]  . '" />%';
}

function getUseInput()
{
global $context$scripturl$settings$txt;
return 'Swap From: <input type="text" name="swapfrom" 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['swapfrom']) || $_POST['swapfrom'] == '') 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['swapfrom'] = strtr($_POST['swapfrom'], array('\\"' => '"'));
preg_match_all('~"([^"]+)"~'$_POST['swapfrom'], $matches);
$userArray array_unique(array_merge($matches[1], explode(','preg_replace('~"([^"]+)"~'''$_POST['swapfrom']))));

// 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}' LIMIT 1"__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);

$row2mysql_fetch_assoc(db_query("
SELECT money
FROM 
{$db_prefix}members
WHERE ID_MEMBER = 
{$ID_MEMBER} LIMIT 1"__FILE____LINE__));

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

return 'Swap successful, although you now have ' $steal_amount '!';
}
else
{return 'Swap unsuccessful please try again';}
}
}

?>

Offline jmordenata

Re: [REQUEST] Change money with aleatory member
« Reply #4 on: April 28, 2007, 11:16:23 pm »
Thanks feeble. You didn't have to traduct it to Spanish :P