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:
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...
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!