1
SMFShop Announcements / Re: Captain Basilbeard's Unoffical Item Creation Guide(Part 2 is out)
« on: May 11, 2006, 07:30:20 am »
Part one may not have worked because of a typo. There should be a single quote ( ' ) before to.
Try this:
Chris
Try this:
Code: [Select]
<?php
/**********************************************\
| SMFSHOP (Shop MOD for Simple Machines Forum) |
| (c) 2005 DanSoft Australia |
| http://www.dansoftaustralia.com/ |
\**********************************************/
//File: MagicDie.php
// Magic Die
//VERSION: 1.0
//DATE: 16th April 2006
//AUTHOR: Basilbeard
global $sourcedir;
require_once($sourcedir . '/Subs-Post.php');
class item_MagicDie extends itemTemplate {
function getItemDetails() {
$this->name = "Magic Die";
$this->desc = "Why risk your own points when you can gamble with someone elses?";
$this->price = 20;
$this->require_input = true;
$this->can_use_item = true;
}
function getAddInput() {
return "Max amount to give: <input type='text' name='info1' value='100'><br>
Max amount to take: <input type='text' name='info2' value='-100'>";
}
function getUseInput() {
global $context, $scripturl, $settings, $txt;
return "Choose a target for your die: <input type='text' name='dicetarget' size='50'>
<a href='{$scripturl}?action=findmember;input=dicetarget;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("SELECT memberName
FROM {$db_prefix}members
WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$user = $row['memberName'];
if ($user == $_POST['dicetarget']) {
return "Use some random money instead. Use the die on someone else";
die();
}
else {
$amount = mt_rand($item_info[2], $item_info[1]);
$result = db_query("UPDATE {$db_prefix}members
SET money = money + {$ammount}
WHERE memberName = '{$_POST['dicetarget']}'", __FILE__, __LINE__);
$result = db_query("SELECT ID_MEMBER
FROM {$db_prefix}members
WHERE memberName = '{$_POST['dicetarget']}'", __FILE__, __LINE__);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$pmfrom = array(
'id' => 1,
'name' => 'Basilbeard',
'username' => 'Basilbeard'
);
$pmto = array(
'to' => array($row['ID_MEMBER']),
'bcc' => array()
);
sendpm($pmto, 'Care for a game of chance?', "{$user} uses a Magic Die on you. You check your inventory, and find that your point total has been changed by ".formatMoney($amount)."! [i] You do not need to reply to this automated message[/i]", 0, $pmfrom);
return "You use your Magic Die on {$_POST['dicetarget']}. It spins around for a few minutes, before landing on {$amount} and thus changing their point count by {$amount} points!";;
}
}
}
?>
Chris