Analog Posted March 6, 2010 Posted March 6, 2010 Name: Arson Mod Version: 1.0.0 Game Engine: McCodes V2 Description: This mod allows players to burn down the houses of their opposition. It also allows players to purchase insurance for their house which slows down the burn rate. A rebuild feature is also included to repair the damage from an arson attack. All parts of the code must be used in order for the mod to work correctly. Notes: This mod require the use of 2 items from the game. Preferably the items should be named "Gas Can" and "Matches". You will need to create these items and then set the variables in the configuration settings of arson.php to the item id of those items. Also go through and set the configuration variables to your liking to fit the economy of your game. Any problems, post them here. This is the main file for the arson mod. Create a file with the name arson.php, copy this code and paste it <?php /********************************************************* -- House Arson -- Author TwiztedFake -- [url]http://www.chaotic-worlds.net[/url] -- Version 1.0.0 -- copyright 2010, TwiztedFake and Chaotic-Worlds.net Permission is granted to use and distribute this script without charge. This script can be edited/altered and any edits/alterations are the sole property of the auther of the edits/alterations. The altered script can be sold and distributed so long as a copy of the original script is distributed along with the new script. **********************************************************/ ##################### ## YOUR HEADER CODE## ##################### require "globals.php"; ######################## ## Configuration Settings ## ######################## //Set $ON to turn this feature On/Off, True=On, False=Off $ON = True; // Cash Cost Per Arson Attempt $ArsonCashCost = 1500; // Brave Cost Per Arson Attempt $ArsonBraveCost = 10; //Minimum Burn Time in minutes $MinBurn = 120; //Maximum Burn Time in minutes $MaxBurn = 1440; //Basic Insurance Cost //Can be a flat fee, based on level, or however you would like //based on level would be $InsCost = 250 * $ir['level']; $BasicInsCost = 1500; //Premium Insurance Cost //Can be a flat fee, based on level, or however you would like //based on level would be $InsCost = 250 * $ir['level']; $PremiumInsCost = 2500; //Minimum Hosptial Time $MinHospital = 20; //Maximum Hospital Time $MaxHospital = 120; //Minimum Jail Time $MinJail = 20; //Maximum Jail Time $MaxJail = 120; //Rebuild Cost, this is (cost * will lost) $RebuildCost = 1; //Gas Can Item $Gas = 17; //Matches Item $Matches = 18; //Donators Only? True = yes, False = No $donator = False; ####################### ## The Code Starts Now ## ####################### //Check if feature is open to public if($ir['user_level'] < 2 && !$ON) { print "This feature is not available to the public yet."; $h->endpage(); exit; } //Check if donator only and display error if($donator) { if(!$ir['donatordays']) { print "Sorry, this feature is for donors only."; $h->endpage(); exit; } } //Check hospital and jail status if($ir['hospital'] || $ir['jail']) { print "The arson feature is disabled while in the hosiptal/jail."; $h->endpage(); exit; } //The switch calls the neccesary function for the requested action from the player switch($_GET['action']) { case 'arson': arson(); break; case 'save': save(); break; case 'ins': ins(); break; } //This function does the rebuild after an arson attack function save() { global $h, $db, $userid, $ir, $RebuildCost; $bz = $db->query("SELECT bWILL FROM burn WHERE bUSER = $userid"); if(!$db->num_rows($bz)) { print "Error: please contact staff"; $h->endpage(); exit; } $zz = $db->fetch_row($bz); $cost = ($zz['bWILL'] - $ir['maxwill']) * $RebuildCost; if($ir['money'] < $cost) { print "You don't have enough money to rebuild your house."; $h->endpage(); exit; } $db->query("UPDATE users SET maxwill = {$zz['bWILL']}, money = money - $cost WHERE userid = $userid"); $db->query("DELETE FROM burn WHERE bUSER = $userid"); print "You have rebuilt your house at a cost of $$cost."; $h->endpage(); exit; } //This function starts the arson on a players house function arson() { global $h, $db, $userid, $ir, $ArsonCashCost, $ArsonBraveCost, $MinHospital, $MaxHospital, $MinJail, $MaxJail, $MinBurn, $MaxBurn, $Gas, $Matches; $who = abs((int)$_GET['u']); $q = $db->query("SELECT userid, maxwill FROM users WHERE userid = $who"); //Check for a player if(!$db->num_rows($q)) { print "No player was found with the given ID."; $h->endpage(); exit; } //Check that arsonist has enough cash if($ir['money'] < $ArsonCashCost) { print "You don't have enough cash for supplies."; $h->endpage(); exit; } //Check that arsonist has enough brave if($ir['brave'] < $ArsonBraveCost) { print "Your brave is too low to complete an arson attempt."; $h->endpage(); exit; } $z = $db->fetch_row($q); //Check that player owns a house if($z['maxwill'] <= 100) { print "This player doesn't own a house"; $h->endpage(); exit; } //Check that players house isn't already burnt $bh = $db->query("SELECT bUSER FROM burn WHERE bUSER = $who"); if($db->num_rows($bh)) { print "This players house has already burnt to the ground"; $h->endpage(); exit; } //Check for items (gas can & matches) $inv = $db->query("SELECT iv.*,i.* FROM inventory iv LEFT JOIN items i ON iv.inv_itemid=i.itmid WHERE iv.inv_userid={$userid} AND iv.inv_itemid=$Gas LIMIT 1"); if(!$db->num_rows($inv)) { $inv = $db->query("SELECT * FROM items WHERE itmid=$Gas LIMIT 1"); $need = $db->fetch_row($inv); print "You need [b]{$need['itmname']}[/b] to attempt an arson. "; $h->endpage(); exit; } $inv = $db->query("SELECT iv.*,i.* FROM inventory iv LEFT JOIN items i ON iv.inv_itemid=i.itmid WHERE iv.inv_userid={$userid} AND iv.inv_itemid=$Matches LIMIT 1"); if(!$db->num_rows($inv)) { $inv = $db->query("SELECT * FROM items WHERE itmid=$Matches LIMIT 1"); $need = $db->fetch_row($inv); print "You need [b]{$need['itmname']}[/b] to attempt an arson. "; $h->endpage(); exit; } $chance = rand(1,100); if($chance < 50) { //Succesful outcome, so lets set the fire $length = rand($MinBurn,$MaxBurn); $db->query("INSERT INTO burn VALUES('$who','$length','{$z['maxwill']}')"); $db->query("UPDATE users SET brave = brave - $ArsonBraveCost, money = money - $ArsonCashCost WHERE userid = $userid"); item_remove($userid,$Matches,1); $show = rand(1,2); if($show == 1) { event_add($who,"Someone set your house on fire"); } else { event_add($who,"[url='viewuser.php?u=$userid']{$ir['username']}[/url] set fire to your house."); } print "You sneak past security and set the house on fire."; $h->endpage(); exit; } else { //Failed, so lets give an outcome $db->query("UPDATE users SET brave = brave - $ArsonBraveCost, money = money - $ArsonCashCost WHERE userid = $userid"); $go = rand(1,2); if($go == 1) { $length = rand($MinHospital,$MaxHospital); $text = "Was badly burnt during an arson attempt"; $db->query("UPDATE users SET hospital = $length, hospreason = '$text' WHERE userid = $userid"); item_remove($userid,$Matches,1); print "You manage to sneak past the security but just as you light the match a car drove by. You dropped the match and caught you pants on fire. You have been sent to the hospital for $length minutes."; $h->endpage(); exit; } else { $length = rand($MinJail,$MaxJail); $text = "Busted during an attempted arson"; $db->query("UPDATE users SET jail = $length, jail_reason = '$text' WHERE userid = $userid"); item_remove($userid,$Matches,1); item_remove($userid,$Gas,1); print "Just when you were about to light the match the cops pulled up. You have been thrown in jail for $length minutes."; $h->endpage(); exit; } } } // This function allows player to purchase insurance on their home which slows the burn rate function ins() { global $h, $db, $userid, $BasicInsCost, $PremiumInsCost; if(isset($_POST['type'])) { $type = abs((int)$_POST['type']); $userid = abs((int)$userid); $cost = ($type == 2) ? $PremiumInsCost : $BasicInsCost; //Check that player has enough money if($ir['money'] < $cose) { print "This insurance cost /$$cost. You don't have enough to purchase it."; $h->endpage(); } $db->query("INSERT INTO insurance VALUES('$userid','$type')"); $db->query("UPDATE users SET money = money - $cost WHERE userid = $userid"); print "You have purchased homeowners insurance for /$$cost"; $h->endpage(); exit; } $q = $db->query("SELECT insUSER FROM insurance WHERE insUSER = $userid"); if($db->num_rows($q)) { print "Sorry, you already have insurance."; $h->endpage(); exit; } print <<<EOF Purchase House Insurance <form action='arson.php?action=ins' method='post'> <select name='type' type='dropdown'> <option value='1'>Basic Homeowners Insurance</option> <option value='2'>Premium Homeowners Insurance</option> </select> <input type='submit' value='Buy Insurance' /> </form> EOF; } print "Error: No action requested!"; $h->endpage(); ?> This code needs to be added to a cron that runs every minute #################### # Arson Code Start # #################### //Base Damage $BaseDamage = 3; //Basic Insurance Damage $BasicDamage = 2; //Premium Insurance Damage $PremiumDamage = 1; $q = $db->query("SELECT * FROM burn WHERE bTIME > 0"); while($z = $db->fetch_row($q)) { $x = $db->query("SELECT insTYPE FROM insurance WHERE insUSER = {$z['bUSER']}"); if($db->num_rows($x)) { $y = $db->fetch_row($x); if($y['insTYPE'] == 2) { $lost = $PremiumDamage; } else if($y['insTYPE'] == 1) { $lost = $BasicDamage; } else { $lost = $BaseDamage; } } else { $lost = $BaseDamage; } $db->query("UPDATE users SET maxwill = maxwill - $lost, will = will - $lost WHERE userid = {$z['bUSER']}"); } #################### # Arson Code End # #################### Add this to your viewuser.php or where ever you would like the link to appear. print "[[url='arson.php?action=arson&u={$r[']Arson[/url]] "; This needs to be added to your estate.php file, add it below the line include "globals.php"; #################### # Arson Code Start # #################### $bz = $db->query("SELECT bUSER FROM burn WHERE bUSER = $userid"); if($db->num_rows($bz)) { print "An arsonist has hit your house. [url='arson.php?action=save']Repair It[/url]"; $h->endpage(); exit; } #################### # Arson Code End # #################### You will also need to run this sql on your database -- -- Table structure for table `burn` -- CREATE TABLE IF NOT EXISTS `burn` ( `bUSER` int(7) NOT NULL, `bTIME` int(5) NOT NULL, `bWILL` int(11) NOT NULL, PRIMARY KEY (`bUSER`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Table structure for table `insurance` -- CREATE TABLE IF NOT EXISTS `insurance` ( `insUSER` int(7) NOT NULL, `insTYPE` int(1) NOT NULL, PRIMARY KEY (`insUSER`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Quote
Jordan Palmer Posted March 6, 2010 Posted March 6, 2010 This look's great, loads better then the one which was posted a while ago Great Work Twizted :] I do think this should off been posted in "Free Plug-ins" though :P Quote
Analog Posted March 6, 2010 Author Posted March 6, 2010 Forgot the link to buy insurance... Add this where ever you would like to give players the option to purchase home insurance. I'd recommend it be on the estate page somewhere... print "([url='arson.php?action=ins']Purchase Insurance[/url])"; Quote
Analog Posted March 6, 2010 Author Posted March 6, 2010 This look's great, loads better then the one which was posted a while ago Great Work Twizted :] I do think this should off been posted in "Free Plug-ins" though :P Thanks Pudda... and GRRRR.... didn't realize i was outside of "Free Addons" -- staff move it please, thanks Quote
Renkia Posted March 6, 2010 Posted March 6, 2010 Great work! Personally i think its kind of poo for a game. You could spend loads of money on a house and get it burnt down? =( But anyway peoples opinions. Yet again good job! :thumbsup: Quote
Jordan Palmer Posted March 7, 2010 Posted March 7, 2010 Great work! Personally i think its kind of poo for a game. You could spend loads of money on a house and get it burnt down? =( But anyway peoples opinions. Yet again good job! :thumbsup: May I suggest you read the code :P Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.