SMF Support > SMF 2.0.x Support
Add New Profile Fields without Custom Profile Fields
Arantor:
Copy the code so there's two lots of code and just change the second one.
Blues Light:
Sorry, I've taken time off from this and have come back to it. Copy the whole lot or a specific bit? I've gotten it to increase 2 fields, but it increases them by 1 defined amount. I'd rather be able to set it so an item could increase 2 or 3 profile fields with individually set amounts.
Arantor:
Well, if one lot of code updates one value, two lots of the code can do two different values - if on the second time you change the field it's pointing to, instead of cust_health...
Blues Light:
Here's what I've come up with. I still can't create a field for a second value, although if I set the value for cust_health to be, say, 100, then it will apply to cust_attack as well.
--- Code: ---<?php
/**********************************************************************************
* SMFShop item - Takes additional fields when adding to admin panel *
***********************************************************************************
* SMFShop: Shop MOD for Simple Machines Forum *
* =============================================================================== *
* Software Version: SMFShop 3.1 (Build 14) *
* Software by: DanSoft Australia (http://www.dansoftaustralia.net/)*
* Copyright 2009 by: vbgamer45 (http://www.smfhacks.com) *
* 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_AddToHealthandAttack extends itemTemplate
{
function getItemDetails()
{
$this->authorName = 'Daniel15';
$this->authorWeb = 'http://www.dansoftaustralia.net/';
$this->authorEmail = 'dansoft@dansoftaustralia.net';
$this->name = 'Add 25 to Health and 15 to Attack';
$this->desc = 'Increase your total Health by 25 and your total Attack by 15!';
$this->price = 150;
$this->require_input = false;
$this->can_use_item = true;
$this->addInput_editable = true;
}
// This is the best bit of this item. When you add the item into the admin panel, you
// can set additional variables (up to 4). Make sure to call them info1, info2, info3
// and info4.
function getAddInput()
{
global $item_info;
if ($item_info[1] == 0) $item_info[1] = 10;
return 'Amount to change Health by: <input type="text" name="info1" value="' . $item_info[1] . '" />';
}
// The additional parameters (see 'getAddInput' above) are in the $item_info array.
// Make sure to make it global (like shown here) otherwise you won't be able to access
// its contents. THE ARRAY IS 1-BASED (1 IS THE FIRST ITEM) NOT 0-BASED!
function onUse()
{
global $smcFunc, $context, $item_info;
$request = $smcFunc['db_query']('', '
SELECT value
FROM {db_prefix}themes
WHERE id_member = {int:id}
AND variable = {string:var}',
array(
'id' => $context['user']['id'],
'var' => 'cust_health',
)
);
if ($smcFunc['db_num_rows']($request) == 0)
{
// There's no value for this user! Insert a default of 50 or something...
$smcFunc['db_insert']('replace',
'{db_prefix}themes',
array('id_member' => 'int', 'id_theme' => 'int', 'variable' => 'string', 'value' => 'string'),
array($context['user']['id'], 1, 'cust_health', 50),
array('id_member', 'id_theme', 'variable')
);
}
else
{
list($value) = $smcFunc['db_fetch_row']($request);
$value += $item_info[1];
$smcFunc['db_query']('', '
UPDATE {db_prefix}themes
SET value = {string:value}
WHERE id_member = {int:id}
AND variable = {string:var}',
array(
'value' => $value,
'id' => $context['user']['id'],
'var' => 'cust_health',
)
);
}
}
}
{
// This is the best bit of this item. When you add the item into the admin panel, you
// can set additional variables (up to 4). Make sure to call them info1, info2, info3
// and info4.
function getAddInput()
{
global $item_info;
if ($item_info[2] == 0) $item_info[2] = 10;
return 'Amount to change Attack by: <input type="text" name="info2" value="' . $item_info[2] . '" />';
}
// The additional parameters (see 'getAddInput' above) are in the $item_info array.
// Make sure to make it global (like shown here) otherwise you won't be able to access
// its contents. THE ARRAY IS 1-BASED (1 IS THE FIRST ITEM) NOT 0-BASED!
function onUse()
{
global $smcFunc, $context, $item_info;
$request = $smcFunc['db_query']('', '
SELECT value
FROM {db_prefix}themes
WHERE id_member = {int:id}
AND variable = {string:var}',
array(
'id' => $context['user']['id'],
'var' => 'cust_attack',
)
);
if ($smcFunc['db_num_rows']($request) == 0)
{
// There's no value for this user! Insert a default of 50 or something...
$smcFunc['db_insert']('replace',
'{db_prefix}themes',
array('id_member' => 'int', 'id_theme' => 'int', 'variable' => 'string', 'value' => 'string'),
array($context['user']['id'], 2, 'cust_attack', 50),
array('id_member', 'id_theme', 'variable')
);
}
else
{
list($value) = $smcFunc['db_fetch_row']($request);
$value += $item_info[2];
$smcFunc['db_query']('', '
UPDATE {db_prefix}themes
SET value = {string:value}
WHERE id_member = {int:id}
AND variable = {string:var}',
array(
'value' => $value,
'id' => $context['user']['id'],
'var' => 'cust_attack',
)
);
}
}
}
?>
--- End code ---
Arantor:
Well, you've duplicated more of the code than I expected - I only meant for you to duplicate the smaller part, basically the bit I wrote.
But you have an item, part of that item's details is the value it updates - you're using that same value both times (it's the $item_info part) - how exactly do you expect to use two different values when it only has one to start with?
Navigation
[0] Message Index
[*] Previous page
Go to full version