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

Offline xfollowthereaperx

Insurance (Still needs work!)
« on: February 20, 2007, 07:09:38 am »
Huge thanks to Basil Beard and TechnoDragon for making this item
The item is still in testing

With this item no one can bash your karma, steal your credits, change your member title,  or rob your bank.

Install the package
If you would like insurance from an item that isn't listed then edit one of theses two into the item.

Add this code to each item you want insurances to block (Single member affects, ie: steal your credits, bash karma)

Code: [Select]
$result = db_query("SELECT insurance from {$db_prefix}members WHERE id_member = ($_POST['target'])", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
if ($row > 0) {
     db_query("UPDATE {$db_prefix}members SET insurance = (insurance - 1) WHERE id_member = ($_POST['target']))", __FILE__, __LINE__);

     return "That user has insurance, and wasn't affected.";
}
else {
//rest of code goes here
}


And as for multiple member affects, (ie: Rob the bank, Karmageddon)

Code: [Select]
$result = db_query("SELECT insurance from {$db_prefix}members WHERE id_member = ($_POST['target'])", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
if ($row > 0) {
     db_query("UPDATE {$db_prefix}members SET insurance = (insurance - 1) WHERE insurance > 0)", __FILE__, __LINE__);

     return "Some users have insurance and weren't affected.";
}
else {
//rest of code goes here
}
« Last Edit: February 22, 2007, 10:26:36 am by xfollowthereaperx »

Offline Basil Beard

Re: Idea: Insurance
« Reply #1 on: February 20, 2007, 12:41:19 pm »
Yes. It would be possible.

Basically, you would want to add a column to the smf_members table called "insurance" or something like that. It would store a 1 if they are insured, and a 0 if not. You would then have to edit the code to all of those items with something like

Code: [Select]
$result = db_query("SELECT insurance from {$db_prefix}members WHERE id_member = ($_POST['target'])", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
if ($row == 1) {
     return "That user has insurance";
}
else {
//rest of code goes here
}

Of course, an item like tha would be rather powerful. so you might want to consider either making it work only a certain amount of the time, or make it die after a certain amount of ti,e.
Arrrrr!

Offline xfollowthereaperx

Re: Idea: Insurance
« Reply #2 on: February 20, 2007, 01:38:50 pm »
Hmm, I know how to add the code to each item I want insurance from but I'm not sure how to code the item. If someone would be nice enough to code it I'd give them a big old hug

Offline Basil Beard

Re: Idea: Insurance
« Reply #3 on: February 20, 2007, 11:32:07 pm »
Code: [Select]
$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!";
}
Arrrrr!

Offline xfollowthereaperx

Re: Idea: Insurance
« Reply #4 on: February 21, 2007, 08:39:51 am »
Is there a tutorial on time expiring items?

Offline xfollowthereaperx

Re: Idea: Insurance
« Reply #5 on: February 21, 2007, 08:51:46 am »
Here is the code, not working though  :buck2:

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)             *
***********************************************************************************
* 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...');

// Your class should always be called item_filename, eg. if your file is 
// myCoolItem.php then the class should be called 'item_myCoolItem'. This 
// class should always extend itemTemplate.
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 'xfollowthereaperx';
// The author's website
$this->authorWeb '';
// And their email address
$this->authorEmail 'xfollowthereaperx@hotmail.com';


// VALUES CHANGEABLE FROM WITHIN ADMIN PANEL:
  // The name of the item
  $this->name 'Insurance';
  // The item's description
  $this->desc 'Buy this item to stop negitive affects from other users';
  // The item's price
  $this->price 1000;
  
//UNCHANGEABLE VALUES:
  // Whether the item requires input or not.
  $this->require_input false;
  // Useable?
  $this->can_use_item true;

// Since this item requires no input, we don't need to have a getUseInput function

$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: Idea: Insurance
« Reply #6 on: February 21, 2007, 02:03:01 pm »
cool item, but the main issue would be figuring out how to set some kind of counter so it expires...

EDIT

Ok, here's an idea, still add the new field to the member table, but istead of doing just a one, have it a number set in the admin panel for items...so anything from say 1 to ten.  then in the query for the items that insurance would protect them, you would have the query look for insurance where it is greater than zero.  if it is, then they are insured, and the the same query would then deduct one from the total, until it reached zero...at which point they would no longer be insured
« Last Edit: February 21, 2007, 02:05:40 pm by TechnoDragon »
Don't tell me to get into shape...I have a shape...It is round!


Offline xfollowthereaperx

Re: Idea: Insurance
« Reply #7 on: February 21, 2007, 03:56:13 pm »
cool item, but the main issue would be figuring out how to set some kind of counter so it expires...

EDIT

Ok, here's an idea, still add the new field to the member table, but istead of doing just a one, have it a number set in the admin panel for items...so anything from say 1 to ten.  then in the query for the items that insurance would protect them, you would have the query look for insurance where it is greater than zero.  if it is, then they are insured, and the the same query would then deduct one from the total, until it reached zero...at which point they would no longer be insured
You could also do that, but I'd much rather have it timed because some of my items are cheaper and if they used to to take someone's insurance it would be very inexpensive.

But I suppose the insurance item is very cheap and very effective in the first place.

Offline xfollowthereaperx

Re: Insurance (Still needs work!)
« Reply #8 on: February 21, 2007, 04:08:18 pm »
Also it would need a script for items like Karmageddon.

Offline TechnoDragon

Re: Insurance (Still needs work!)
« Reply #9 on: February 21, 2007, 09:52:44 pm »
Well here is the conceptual code for the items...

Code: [Select]
$result = db_query("SELECT insurance from {$db_prefix}members WHERE id_member = ($_POST['target'])", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
if ($row > 0) {
     db_query("UPDATE {$db_prefix}members SET insurance = (insurance - 1))", __FILE__, __LINE__);

     return "That user has insurance";
}
else {
//rest of code goes here
}
Don't tell me to get into shape...I have a shape...It is round!


Offline xfollowthereaperx

Re: Insurance (Still needs work!)
« Reply #10 on: February 22, 2007, 04:09:01 am »
Well here is the conceptual code for the items...

Code: [Select]
$result = db_query("SELECT insurance from {$db_prefix}members WHERE id_member = ($_POST['target'])", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
if ($row > 0) {
     db_query("UPDATE {$db_prefix}members SET insurance = (insurance - 1))", __FILE__, __LINE__);

     return "That user has insurance";
}
else {
//rest of code goes here
}

Then I guess if an item effects all members like 'rob the bank' then it would be written like this?

Code: [Select]
$result = db_query("SELECT insurance from {$db_prefix}members WHERE id_member = ($_POST['target'])", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
if ($row > 0) {
     db_query("UPDATE {$db_prefix}members SET insurance = (insurance - 1))", __FILE__, __LINE__);

     return "Some users have insurance and weren't affected.";
}
else {
//rest of code goes here
}
« Last Edit: February 22, 2007, 04:10:57 am by xfollowthereaperx »

Offline TechnoDragon

Re: Insurance (Still needs work!)
« Reply #11 on: February 22, 2007, 06:11:53 am »
Close....

ok, for the specific member the query would look like this....
Code: [Select]
$result = db_query("SELECT insurance from {$db_prefix}members WHERE id_member = ($_POST['target'])", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
if ($row > 0) {
     db_query("UPDATE {$db_prefix}members SET insurance = (insurance - 1) WHERE id_member = ($_POST['target']))", __FILE__, __LINE__);

     return "That user has insurance";
}
else {
//rest of code goes here
}

for items like rob the bank, then you would use this one...
Code: [Select]
$result = db_query("SELECT insurance from {$db_prefix}members WHERE id_member = ($_POST['target'])", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
if ($row > 0) {
     db_query("UPDATE {$db_prefix}members SET insurance = (insurance - 1) WHERE insurance > 0)", __FILE__, __LINE__);

     return "That user has insurance";
}
else {
//rest of code goes here
}

Otherwise you run the risk of setting every members insurance field...even the ones that were zero...those checks keep that from happening
Don't tell me to get into shape...I have a shape...It is round!


Offline xfollowthereaperx

Re: Insurance (Still needs work!)
« Reply #12 on: February 22, 2007, 06:13:47 am »
Close....

ok, for the specific member the query would look like this....
Code: [Select]
$result = db_query("SELECT insurance from {$db_prefix}members WHERE id_member = ($_POST['target'])", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
if ($row > 0) {
     db_query("UPDATE {$db_prefix}members SET insurance = (insurance - 1) WHERE id_member = ($_POST['target']))", __FILE__, __LINE__);

     return "That user has insurance";
}
else {
//rest of code goes here
}

for items like rob the bank, then you would use this one...
Code: [Select]
$result = db_query("SELECT insurance from {$db_prefix}members WHERE id_member = ($_POST['target'])", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
if ($row > 0) {
     db_query("UPDATE {$db_prefix}members SET insurance = (insurance - 1) WHERE insurance > 0)", __FILE__, __LINE__);

     return "That user has insurance";
}
else {
//rest of code goes here
}

Otherwise you run the risk of setting every members insurance field...even the ones that were zero...those checks keep that from happening
Okay, I'll update it


Now we need to work on the item  ::)

Offline xfollowthereaperx

Re: Insurance (Still needs work!)
« Reply #13 on: February 22, 2007, 06:24:19 am »
Also, the code you're giving makes it so that the item you use on someone who has insurance fails and is delete, correct?

Offline TechnoDragon

Re: Insurance (Still needs work!)
« Reply #14 on: February 22, 2007, 06:30:34 am »
well, with a slight modification to the first part, yes you could have the item delete from inventory if the person they use it on has insurance
Don't tell me to get into shape...I have a shape...It is round!