News:

Wondering if this will always be free?  See why free is better.

Main Menu

Stats Item (needs a little help)

Started by Daisuke_aurora, August 18, 2008, 03:00:15 PM

Previous topic - Next topic

Daisuke_aurora

Ok. I run a forun where members can RP using a stat system (the custom profile field mod). Basically, members have a set atk power, def power, etc, displayed by the CP field mod. I recently took the Add to post count item and tweaked it to add to the CP fields, and got this:

Quote<?php
/**********************************************************************************
* SMFShop item                                                                    *
***********************************************************************************
* SMFShop: Shop MOD for Simple Machines Forum                                     *
* =============================================================================== *
* Software Version:           SMFShop 3.0 (Build 12)                              *
* $Date:: 2008-08-18 14:30:00 +1100 (Mon, 18 Aug 2008)                          $ *
* $Id:: IncreaseHP.php 79 2008-08-18 12:30:00Z Daisuke_aurora                   $ *
* Software by:                Daisuke (http://www.daisukesdojo.heliohost.org/)    *
* Copyright 2005-2007 by:     Daisuke (http://www.daisukesdojo.heliohost.org/)    *
* Support, News, Updates at:  http://www.daisukesdojop.heliohost.org/             *
*                                                                                 *
* 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_IncreaseHP extends itemTemplate
{
   function getItemDetails()
   {
      $this->authorName = 'Daisuke';
      $this->authorWeb = 'http://www.daisukesdojo.heliohost.org/';
      $this->authorEmail = '[email protected]';

      $this->name = 'Increase HP by xxx';
      $this->desc = 'Increase your HP by xxx';
      $this->price = 1000;

      $this->require_input = false;
      $this->can_use_item = true;
      $this->addInput_editable = true;
   }
   
   // See 'AddToPostCount.php' for info on how this works
   function getAddInput()
   {
      global $user_info;
      if ($item_info[1] == 0) $item_info[1] = 10;
      return 'Amount to increase HP by: <input type="text" name="info1" value="' . $item_info[1] . '" />';
   }

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

      db_query("
         UPDATE {$db_prefix}themes
         SET value = value + {$item_info[1]}
         WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);
      return 'Successfully increased your HP by ' . $item_info[1] . '!';
   }

}

?>

However, there is one problem: The item cannot tell the difference between the 8 CP fields, so it increases ALL of them by 10, not just one. Can anyone tell me how to make it target only one of these fields?

I assume it would have to look into the Variable column and find the one titled "CP1," but I have no idea how to do that... Any help?

Oldiesmann

Change that WHERE line to WHERE variable='default_options[CP1]' AND ID_MEMBER={$ID_MEMBER}
Michael Eshom
Christian Metal Fans

Daisuke_aurora

You my friend are AWESOME! I've been trying to get help with this for months! (But then again, having no help forced me to nearly figure it out myself.) If you ever need anything, lemme know! Thanks again!

Daisuke_aurora

#3
Wait... Something's wrong. it isn't changing anything at all now...

This is what I have now:

Quote<?php
/**********************************************************************************
* SMFShop item                                                                    *
***********************************************************************************
* SMFShop: Shop MOD for Simple Machines Forum                                     *
* =============================================================================== *
* Software Version:           SMFShop 3.0 (Build 12)                              *
* $Date:: 2008-08-18 14:30:00 +1100 (Mon, 18 Aug 2008)                          $ *
* $Id:: IncreaseHP.php 79 2008-08-18 12:30:00Z Daisuke_aurora                   $ *
* Software by:                Daisuke (http://www.daisukesdojo.heliohost.org/)    *
* Copyright 2005-2007 by:     Daisuke (http://www.daisukesdojo.heliohost.org/)    *
* Support, News, Updates at:  http://www.daisukesdojop.heliohost.org/             *
*                                                                                 *
* 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_IncreaseHP extends itemTemplate
{
   function getItemDetails()
   {
      $this->authorName = 'Daisuke';
      $this->authorWeb = 'http://www.daisukesdojo.heliohost.org/';
      $this->authorEmail = '[email protected]';

      $this->name = 'Increase HP by xxx';
      $this->desc = 'Increase your HP by xxx';
      $this->price = 1000;

      $this->require_input = false;
      $this->can_use_item = true;
      $this->addInput_editable = true;
   }
   
   // See 'AddToPostCount.php' for info on how this works
   function getAddInput()
   {
      global $user_info;
      if ($item_info[1] == 0) $item_info[1] = 10;
      return 'Amount to increase HP by: <input type="text" name="info1" value="' . $item_info[1] . '" />';
   }

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

      db_query("
         UPDATE {$db_prefix}themes
         SET value = value + {$item_info[1]}
         WHERE variable='default_options[CP1]' AND ID_MEMBER={$ID_MEMBER}", __FILE__, __LINE__);
      return 'Successfully increased your HP by ' . $item_info[1] . '!';
   }

}

?>

Advertisement: