Author Topic: Insurance (Still needs work!)  (Read 57344 times)

Offline xfollowthereaperx

Re: Insurance (Still needs work!)
« Reply #15 on: February 22, 2007, 06:44:15 am »
Here is what I've got to far for the whole item, I'm probably missing something very simple  :uglystupid2:

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:: Insurance.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)             *
**********************************************************************************/

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

// Your class should always be called item_filename
class item_Insurance extends itemTemplate
{

// When this function is called, you should set all the item's
// variables (see inside this example)
function getItemDetails()
{

// The author of the item
$this->authorName 'xfollowthereaperx5';
// The author's website
$this->authorWeb '';
// And their email address
$this->authorEmail 'xfollowtehreaperx@hotmail.com';


// VALUES CHANGEABLE FROM WITHIN ADMIN PANEL:
  // The name of the item
  $this->name 'Insurance';
  // The item's description
  $this->desc 'Prevents negitive affects from occuring to you, one time use.';
  // The item's price
  $this->price 500;
  
//UNCHANGEABLE VALUES:
  // Whether the item requires input or not. In this case, we don't need
  // any input
  $this->require_input false;
  // Since this is a rock (you can't use it), we set this to false
  $this->can_use_item true;


// Since this item requires no input, we don't need to have a getUseInput function
// here (see the testitem2.php file if you want to make an item that needs input)

// Also, since this is a rock, you don't need an onUse function (since it doesn't get used)
$result db_query(SELECT insurance FROM {$db_prefix}members WHERE ID_MEMBER = {$ID_MEMBER}", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
if (
$row['insurance'] == 1) {
     return "
you are already insured";}
else {
     
$result = db_query(UPDATE {$db_prefix}members SET insurance = 1 WHERE ID_MEMBER = {$ID_MEMBER}"__FILE____LINE__);
     return 
"You are now insured!";}

?>


Offline TechnoDragon

Re: Insurance (Still needs work!)
« Reply #16 on: February 22, 2007, 06:52:06 am »
ok, well for the items that you want insurance to protect from here's an example...

This is from the steal.php item...

here is the original onuse function:
Code: [Select]
    function onUse() {
        global $db_prefix, $ID_MEMBER, $item_info, $sourcedir, $user_info;

// Check some inputs
if (!isset($_POST['stealfrom']) || $_POST['stealfrom'] == '') die("ERROR: Please enter a username to steal from!");
       
        // Get a random number between 0 and 100
        $try = mt_rand(0, 100);

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

            // Get stealee's money count
            $result = db_query("SELECT money
                                FROM {$db_prefix}members
                                WHERE memberName = '{$_POST['stealfrom']}'", __FILE__, __LINE__);

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

            $row = mysql_fetch_array($result, MYSQL_ASSOC);



            // 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 = '{$_POST['stealfrom']}'
                                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 {
require_once($sourcedir . '/Subs-Post.php');
$topicOptions['board'] = 127; //SHOP history forum  Mine is #98  You need to create this then use it's ID number
$topicOptions['id']=0; //NEW topic
$msgOptions['subject'] = "I am a Thief {$user_info['username']}"; //Subject
$msgOptions['body'] = "{$user_info['username']} just used a sticky hand and stole {$steal_amount} from ".$_POST['stealfrom']; //Message area
  $msgOptions['icon'] = 'exclamation';
$posterOptions['id']=$ID_MEMBER; //Current user's ID
createPost(&$msgOptions, &$topicOptions, &$posterOptions); //create the post using the SMF posting function
                return "Successfully stole $steal_amount from {$_POST['stealfrom']}! It's their fault they don't have their money in the bank!";
            }
        } else {
            // If reducing Karma doesn't work, replace
            // 'karmaBad = karmaBad + 10' with 'karmaGood = karmaGood - 10'
            $result = db_query("UPDATE {$db_prefix}members
                               SET karmaBad = karmaBad + 10
                               WHERE ID_MEMBER = {$ID_MEMBER}",
                               __FILE__, __LINE__);
           return "Steal <b>unsuccessful!</b> You Karma is now reduced by 10!";
        }
    }
}

and here is how the new function looks with the insurance check added in...

Code: [Select]
    function onUse() {
        global $db_prefix, $ID_MEMBER, $item_info, $sourcedir, $user_info;

// Check some inputs
if (!isset($_POST['stealfrom']) || $_POST['stealfrom'] == '') die("ERROR: Please enter a username to steal from!");
       
        // Get a random number between 0 and 100
        $try = mt_rand(0, 100);

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

            // Get stealee's money count
            $result = db_query("SELECT money, insurance
                                FROM {$db_prefix}members
                                WHERE memberName = '{$_POST['stealfrom']}'", __FILE__, __LINE__);

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

            $row = mysql_fetch_array($result, MYSQL_ASSOC);

if ($row['insurance'] > 0) {
      db_query("UPDATE {$db_prefix}members SET insurance = (insurance - 1) WHERE insurance > 0 AND memberName = '{$_POST['stealfrom']}'", __FILE__, __LINE__);

      return "That user has insurance";
}
else {
            // 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 = '{$_POST['stealfrom']}'
                                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 {
require_once($sourcedir . '/Subs-Post.php');
$topicOptions['board'] = 127; //SHOP history forum  Mine is #98  You need to create this then use it's ID number
$topicOptions['id']=0; //NEW topic
$msgOptions['subject'] = "I am a Thief {$user_info['username']}"; //Subject
$msgOptions['body'] = "{$user_info['username']} just used a sticky hand and stole {$steal_amount} from ".$_POST['stealfrom']; //Message area
  $msgOptions['icon'] = 'exclamation';
$posterOptions['id']=$ID_MEMBER; //Current user's ID
createPost(&$msgOptions, &$topicOptions, &$posterOptions); //create the post using the SMF posting function
                return "Successfully stole $steal_amount from {$_POST['stealfrom']}! It's their fault they don't have their money in the bank!";
}
        }
else {
            // If reducing Karma doesn't work, replace
            // 'karmaBad = karmaBad + 10' with 'karmaGood = karmaGood - 10'
            $result = db_query("UPDATE {$db_prefix}members
                               SET karmaBad = karmaBad + 10
                               WHERE ID_MEMBER = {$ID_MEMBER}",
                               __FILE__, __LINE__);
           return "Steal <b>unsuccessful!</b> You Karma is now reduced by 10!";
        }
    }
}


I will work on the actual item itself here shortly...you have a good start though!
Don't tell me to get into shape...I have a shape...It is round!


Offline xfollowthereaperx

Re: Insurance (Still needs work!)
« Reply #17 on: February 22, 2007, 06:54:43 am »
Hmm, this is very confusing for someone like me :p

I'll hopefully have new versions for each item (with insurance coding in them) available. Once you finish the actuall item that is.


Thanks a lot for the help
« Last Edit: February 22, 2007, 07:14:47 am by xfollowthereaperx »

Offline TechnoDragon

Re: Insurance (Still needs work!)
« Reply #18 on: February 22, 2007, 07:00:00 am »
ok, here's the completed item:

Code: [Select]
<?php
/**********************************************\
| SMFSHOP (Shop MOD for Simple Machines Forum) |
|         (c) 2006 DanSoft Australia           |
|      http://www.dansoftaustralia.net/        |
\**********************************************/

//File: Insurance.php

class item_Insurance extends itemTemplate {
    function 
getItemDetails() {
$this->authorName "TechnoDragon";
$this->authorWeb "http://dragontalk.net";
$this->authorEmail "admin@dragontalk.net";

        
$this->name "Item Protection";
        
$this->desc "Protect yourself from bad items.";
        
$this->price 100;

        
$this->require_input false;
        
$this->can_use_item true;
    }
    
    
// See 'AddToPostCount.php' for info on how this works
    
function getAddInput() {
        return 
"Number of times to protect from bad items: <input type='text' name='info1' value='5' />";
    }

    function 
getUseInput() {
        return 
"";
    }

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

        
$result db_query("UPDATE {$db_prefix}members
                            SET insurance = insurance + 
{$item_info[1]}
                            WHERE ID_MEMBER = 
{$ID_MEMBER}",
                            
__FILE____LINE__);
        return 
"You are now protected from bad items for {$item_info[1]} times!";
    }

}

?>


Just make sure to call it Insurance.php (notice the case of the letters)
Don't tell me to get into shape...I have a shape...It is round!


Offline xfollowthereaperx

Re: Insurance (Still needs work!)
« Reply #19 on: February 22, 2007, 07:27:09 am »
Okay, when I go to use the insurance item it tells me that I need to upgrade my database

Where can I do that?


It says my database is 1.1 and my SMF is 1.1.2

Quote
Unknown column 'insurance' in 'field list'
File: /hosted/subs/ulmb.com/p/o/powerspike/public_html/forums/Sources/shop/items/Insurance.php
Line: 39

Note: It appears that your database may require an upgrade. Your forum's files are currently at version SMF 1.1.2, while your database is at version 1.1. The above error might possibly go away if you execute the latest version of upgrade.php.
« Last Edit: February 22, 2007, 07:35:25 am by xfollowthereaperx »

Offline xfollowthereaperx

Re: Insurance (Still needs work!)
« Reply #20 on: February 22, 2007, 09:38:34 am »
How do I add the insurance thing to my database?

I'm really confused about this part, I found smf_members, but thats it, once I go into that thing it doesn't show anything like "add database item" or whatever. What would be the inputs as well.

Offline TechnoDragon

Re: Insurance (Still needs work!)
« Reply #21 on: February 22, 2007, 10:23:20 am »
ok, give me a few and I will make up a package so you can install the item through the smf package manager...
Don't tell me to get into shape...I have a shape...It is round!


Offline xfollowthereaperx

Re: Insurance (Still needs work!)
« Reply #22 on: February 22, 2007, 10:24:03 am »
ok, give me a few and I will make up a package so you can install the item through the smf package manager...
Wow, thanks so much   :smitten:

Offline TechnoDragon

Re: Insurance (Still needs work!)
« Reply #23 on: February 22, 2007, 10:36:11 am »
ok, you can download an installable package HERE

This will do everything for you so all you'll have to do is add the item to your shop through the admin panel!
Don't tell me to get into shape...I have a shape...It is round!


Offline xfollowthereaperx

Re: Insurance (Still needs work!)
« Reply #24 on: February 22, 2007, 10:37:02 am »
Thanks a billion

Offline xfollowthereaperx

Re: Insurance (Still needs work!)
« Reply #25 on: February 22, 2007, 10:43:53 am »
Didn't work  :'(

Quote
Fatal error: require() [function.require]: Failed opening required '/hosted/subs/ulmb.com/p/o/powerspike/public_html/forums/Packages/temp/avtr_install.php' (include_path='.:') in /hosted/subs/ulmb.com/p/o/powerspike/public_html/forums/Sources/Packages.php on line 552

Offline TechnoDragon

Re: Insurance (Still needs work!)
« Reply #26 on: February 22, 2007, 11:09:25 am »
hold on...apparently i missed an edit...give me a sec
Don't tell me to get into shape...I have a shape...It is round!


Offline TechnoDragon

Re: Insurance (Still needs work!)
« Reply #27 on: February 22, 2007, 11:10:57 am »
ok, redownload and try again
Don't tell me to get into shape...I have a shape...It is round!


Offline xfollowthereaperx

Re: Insurance (Still needs work!)
« Reply #28 on: February 22, 2007, 11:22:59 am »
Quote
Error: The installer was unable to add a needed setting to the {db_prefix}members table. You may have to do this yourself.

I'm sure, if I try hard enough, that I can add that part.  :coolsmiley:

Thanks a lot

Offline TechnoDragon

Re: Insurance (Still needs work!)
« Reply #29 on: February 22, 2007, 11:25:27 am »
that would be the insurance field...
Don't tell me to get into shape...I have a shape...It is round!