Hi when on ce i made a thug system ... it was an epic fail with many many bugs, Today i decided to remake it, code it better and remove a few things.
This is the core system made for version 1 and 2 the script will detect your mccode version and run for that version so none of this converting to v1 or v2 :D(if some 1 can they verify it will work on v1 as its only tested on v2 (dont see why it shouldent tho)). I will be making add-ons for this in the next few days so that it can play a bigger role in your game and to fit your specific game.
the free mods for this are located here http://cddesigns.org/thug.php
well here is the sql you have to run[mysql]
CREATE TABLE `thugs` (
`userid` INT NOT NULL ,
`tID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`tName` VARCHAR( 255 ) NOT NULL ,
`tLevel` INT NOT NULL ,
`tHealth` INT( 3 ) NOT NULL ,
`tStr` INT NOT NULL ,
`tDef` INT NOT NULL ,
`tPrice` INT NOT NULL
ALTER TABLE `thugs`
CHANGE `userid` `userid` INT( 11 ) NOT NULL ,
CHANGE `tID` `tID` INT( 11 ) NOT NULL AUTO_INCREMENT ,
CHANGE `tName` `tName` VARCHAR( 255 ) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL ,
CHANGE `tLevel` `tLevel` INT( 11 ) NOT NULL DEFAULT '1',
CHANGE `tHealth` `tHealth` INT( 3 ) NOT NULL DEFAULT '100',
CHANGE `tStr` `tStr` INT( 11 ) NOT NULL DEFAULT '1',
CHANGE `tDef` `tDef` INT( 11 ) NOT NULL DEFAULT '1',
CHANGE `tPrice` `tPrice` INT( 11 ) NOT NULL DEFAULT '100',
CHANGE `tExp` `tExp` INT( 11 ) NOT NULL DEFAULT '0',
Here is thugs.php
<?php
///////////////////////////////////////////////////////////////////
// Thug Core System - McCodes V1/2 //
// Made By Christopher day (AKA Dayo) December 2009 //
// Support is limited for the Core system ONLY!!! //
// Support is located at cddesigns.org/support //
// Relesed under the GNU licence //
// This is the remake please email me any bugs //
// Enjoy this FREE mod Thanks, Dayo //
///////////////////////////////////////////////////////////////////
include 'tglobals.php';
/////////////
// HOME //
/////////////
function home() {
global $ir, $h, $tSettings;
echo '<p>Welcome to your thug overveiw. Here you can organise your thugs, buy equipment, train stats and hire more.</p><h1>Your Thugs</h1>Click on your thug to edit it - <a href="thugs.php?action=hire">Hire a thug($'.number_format($tSettings['ThugPrice']).')</a></p>';
echo '<table width="480" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><strong>Thug</strong></td>
<td><strong>Level</strong></td>
<td><strong>Strengh</strong></td>
<td><strong>Defence</strong></td>
<td><strong>Health</strong></td>
<td><strong>Pay</strong></td>
</tr>';
$sql="SELECT `tID`, `tName`, `tLevel`, `tHealth`, `tStr`, `tDef`, `tPrice` FROM `thugs` WHERE `userid`='".$ir['userid']."'";
$qry=mysql_query($sql);
while ($t=mysql_fetch_array($qry)) {
echo ' <tr>
<td><a href="thugs.php?action=thug&id='.$t['tID'].'">'.htmlspecialchars($t['tName']).'</a></td>
<td>'.$t['tLevel'].'</td>
<td>'.$t['tStr'].'</td>
<td>'.$t['tDef'].'</td>
<td>'.$t['tHealth'].'%</td>
<td>$'.number_format($t['tPrice']).'</td>
</tr>';
}
echo '</table>';
}
///////////
// Thugs //
///////////
function thug() {
global $ir, $h, $tSettings;
$id=abs(@intval($_GET['id']));
$sql="SELECT `userid`, `tID`, `tName`, `tLevel`, `tHealth`, `tStr`, `tDef`, `tPrice`, `tExp`, `tEnergy`, `tActions` FROM `thugs` WHERE `tID`='".$id."'";
$qry=mysql_query($sql);
$t=mysql_fetch_array($qry);
if($t['userid']!=$ir['userid']){echo 'This is not your thug!'; $h->endpage();exit;}
echo '<h1>'.htmlspecialchars($t['tName']).' - <a href="thugs.php">Back</a></h1>
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100"><strong>Name:</strong></td>
<td width="120">'.htmlspecialchars($t['tName']).'</td>
<td width="180">[<a href="thugs.php?action=edit&option=name">Change</a>]</td>
</tr>
<tr>
<td><strong>Level:</strong></td>
<td>'.$t['tLevel'].'</td>
<td>['.$t['tExp'].'%]</td>
</tr>
<tr>
<td><strong>Strengh:</strong></td>
<td>'.$t['tStr'].'</td>
<td>[<a href="thugs.php?action=train&option=str&id='.$t['tID'].'">Train</a>] - [Energy: '.$t['tEnergy'].']</td>
</tr>
<tr>
<td><strong>Defence:</strong></td>
<td>'.$t['tDef'].'</td>
<td>[<a href="thugs.php?action=train&option=def&id='.$t['tID'].'">Train</a>] - [Energy: '.$t['tEnergy'].']</td>
</tr>
<tr>
<td><strong>Health:</strong></td>
<td>'.$t['tHealth'].'%</td>
<td>';
if ($t['tHealth'] != 100) {
echo '[<a href="thugs.php?action=heal&id='.$t['tID'].'">Heal ($'.number_format(($t['tLevel']*(100-$t['tHealth'])*100)).')</a>]';
}
echo '</td>
</tr>
<tr>
<td><strong>Cost:</strong></td>
<td>$'.$t['tPrice'].'</td>
<td></td>
</tr>';
$a=explode('-', $t['tActions']);
$income = ($tSettings['Actions'][1]['Income']*$a[0])+($tSettings['Actions'][2]['Income']*$a[1])+($tSettings['Actions'][3]['Income']*$a[2])+($tSettings['Actions'][4]['Income']*$a[3])+($tSettings['Actions'][5]['Income']*$a[4]);
echo ' <tr>
<td><strong>Income:</strong></td>
<td>$'.number_format($income).'</td>
<td>[<a href="thugs.php?action=actions&id='.$t['tID'].'">Upgrade</a>]- [<a href="thugs.php?action=claim&id='.$t['tID'].'">Collect</a>]</td>
</tr>
</table>';
}
////////////
// Train //
////////////
function train() {
global $ir, $h, $tSettings;
$id=abs(@intval($_GET['id']));
$alowedoptions = array('str', 'def', 'Str', 'Def');
$option = $_GET['option'];
if (!in_array($option, $alowedoptions)) {echo 'You can only train strengh or defence. <a href="thugs.php?action=thug&id='.$id.'">Back</a>';$h->endpage();exit;}
$sql="SELECT `tID`, `tName`, `tStr`, `tDef`, `tEnergy` FROM `thugs` WHERE `userid`='".$ir['userid']."' AND `tID`='".$id."'";
$qry=mysql_query($sql);
$t=mysql_fetch_array($qry);
if ($t['tEnergy'] < 1) {
echo 'Your thug dosent have energy. <a href="thugs.php?action=thug&id='.$id.'">Back</a>';$h->endpage(); exit;
}
if ($option == 'str') {
mysql_query("UPDATE `thugs` SET `tStr`=`tStr`+'1', `tEnergy`=`tEnergy`-'1' WHERE `tID`='".$t['tID']."'");
echo htmlspecialchars($t['tName'])." Gained one Strengh Point. <a href='thugs.php?action=thug&id=".$id."'>Back</a>";
} else {
mysql_query("UPDATE `thugs` SET `tDef`=`tDef`+'1', `tEnergy`=`tEnergy`-'1' WHERE `tID`='".$t['tID']."'");
echo htmlspecialchars($t['tName'])." Gained one Defence Point. <a href='thugs.php?action=thug&id=".$id."'>Back</a>";
}
}
/////////////
// Heal //
/////////////
function heal() {
global $ir, $h, $tSettings;
$id=abs(@intval($_GET['id']));
$sql="SELECT `tID`, `tName`, `tLevel`, `tHealth` FROM `thugs` WHERE `userid`='".$ir['userid']."' AND `tID`='".$id."'";
$qry=mysql_query($sql);
$t=mysql_fetch_array($qry);
$price = ($t['tLevel']*(100-$t['tHealth'])*100);
if ($price > $ir['money']) { echo 'You dont have enough money to do this. <a href="thugs.php?action=thug&id='.$id.'">Back</a>'; $h->endpage();exit;}
mysql_query("UPDATE `thugs` SET `tHealth`='100' WHERE `tID`='".$t['tID']."'");
mysql_query("UPDATE `users` SET `money`=`money`-'".$price."' WHERE `userid`='".$ir['userid']."'");
echo htmlspecialchars($t['tName']).' was healed for $'.number_format($price).'. <a href="thugs.php?action=thug&id='.$id.'">Back</a>';
}
////////////
// Hire //
////////////
function hire() {
global $ir, $h, $tSettings;
if ($ir['money'] < $tSettings['ThugPrice']){ echo 'You Dont Have enough money for a thug. <a href="thugs.php">Back</a>';$h->endpage();exit;}
$qry=mysql_query("SELECT `tID` FROM `thugs` WHERE `userid`='".$ir['userid']."'");
if(mysql_num_rows($qry)>=$tSettings['MaxThugs']){ echo 'You already have '.$tSettings['MaxThugs'].' thugs. <a href="thugs.php">Back</a>';$h->endpage();exit; }
if ($_POST['name']) {
$name=mysql_real_escape_string($_POST['name']);
mysql_query("INSERT INTO thugs(`userid`, `tName`) VALUES ('".$ir['userid']."', '".$name."')");
echo mysql_error();
mysql_query("UPDATE `users` SET `money`=`money`-'".$tSettings['ThugPrice']."' WHERE `userid`='".$ir['userid']."'");
echo 'You Hired '.htmlspecialchars($name).' <a href="thugs.php">Back</a>';
} else {
echo 'Chose a name<br /><form name="form1" method="post" action="thugs.php?action=hire">
<input type="text" name="name">
<input type="submit" name="Submit" value="Submit">
</form>
';
}
}
//////////////
// Actions //
//////////////
function actions(){
global $ir, $h, $tSettings, $actions;
$id=abs(@intval($_GET['id']));
$qry=mysql_query("SELECT `tActions`, `userid` FROM `thugs` WHERE `tID`='".$id."'");
$t=mysql_fetch_array($qry);
$a=explode('-', $t['tActions']);
if ($ir['userid'] != $t['userid']) { echo 'This is not your thug! <a href="thugs.php?action=thug&id='.$id.'">Back</a>';$h->endpage();exit;}
echo '<table width="98%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center"><strong>Crime</strong></td>
<td align="center"><strong>Income</strong></td>
<td align="center"><strong>Cost</strong></td>
<td align="center"><strong>Current Ammount</strong> </td>
<td align="center"><strong> Max</strong> </td>
<td align="center"><strong>Buy</strong></td>
</tr>
<tr>
<td align="center">'.$tSettings['Actions']['1']['Name'].'</td>
<td align="center">$'.number_format($tSettings['Actions']['1']['Income']).'</td>
<td align="center">'.number_format($tSettings['Actions']['1']['Price']).'</td>
<td align="center">'.$a[0].'</td>
<td align="center">'.$tSettings['Actions']['1']['Max'].'</td>
<td align="center"><a href="thugs.php?action=buy&id='.$id.'&type=0">Buy</a></td>
</tr>
<tr>
<td align="center">'.$tSettings['Actions']['2']['Name'].'</td>
<td align="center">$'.number_format($tSettings['Actions']['2']['Income']).'</td>
<td align="center">$'.number_format($tSettings['Actions']['2']['Price']).'</td>
<td align="center">'.$a[1].'</td>
<td align="center">'.$tSettings['Actions']['2']['Max'].'</td>
<td align="center"><a href="thugs.php?action=buy&id='.$id.'&type=1">Buy</a></td>
</tr>
<tr>
<td align="center">'.$tSettings['Actions']['3']['Name'].'</td>
<td align="center">$'.number_format($tSettings['Actions']['3']['Income']).'</td>
<td align="center">$'.number_format($tSettings['Actions']['3']['Price']).'</td>
<td align="center">'.$a[2].'</td>
<td align="center">'.$tSettings['Actions']['3']['Max'].'</td>
<td align="center"><a href="thugs.php?action=buy&id='.$id.'&type=2">Buy</a></td>
</tr>
<tr>
<td align="center">'.$tSettings['Actions']['4']['Name'].'</td>
<td align="center">$'.number_format($tSettings['Actions']['4']['Income']).'</td>
<td align="center">$'.number_format($tSettings['Actions']['4']['Price']).'</td>
<td align="center">'.$a[3].'</td>
<td align="center">'.$tSettings['Actions']['4']['Max'].'</td>
<td align="center"><a href="thugs.php?action=buy&id='.$id.'&type=3">Buy</a></td>
</tr>
<tr>
<td align="center">'.$tSettings['Actions']['5']['Name'].'</td>
<td align="center">$'.number_format($tSettings['Actions']['5']['Income']).'</td>
<td align="center">$'.number_format($tSettings['Actions']['5']['Price']).'</td>
<td align="center">'.$a[4].'</td>
<td align="center">'.$tSettings['Actions']['5']['Max'].'</td>
<td align="center"><a href="thugs.php?action=buy&id='.$id.'&type=4">Buy</a></td>
</tr>
</table>';
}
////////////
// Buy //
////////////
function buy() {
global $ir, $h, $tSettings, $actions;
$id=abs(@intval($_GET['id']));
$type=abs(@intval($_GET['type']));
$sql = "SELECT `userid`, `tID`, `tActions` FROM `thugs` WHERE `tID`='".$id."'";
$qry = mysql_query($sql);
$t = mysql_fetch_array($qry);
if ($ir['userid'] != $t['userid']) { echo 'This is not your thug! <a href="thugs.php?action=actions&id='.$id.'">Back</a>';$h->endpage();exit;}
$a=explode('-', $t['tActions']);
if ($tSettings['Actions'][($type+1)]['Max'] < ($a[$type]+1)) { echo 'You are only alowed to do this '.$tSettings['Actions'][($type+1)]['Max'].' times a hour! <a href="thugs.php?action=actions&id='.$id.'">Back</a>';$h->endpage();exit;}
mysql_query("UPDATE `users` SET `money`=`money`-'".$tSettings['Actions'][($type+1)]['Price']."' WHERE `userid`='".$ir['userid']."'");
$a[$type]=$a[$type]+1;
$implode=implode('-', $a);
$sql="UPDATE `thugs` SET `tActions`='".$implode."' WHERE `tID`='".$t['tID']."'";
mysql_query($sql);
echo mysql_error();
echo 'You now '.$tSettings['Actions'][($type+1)]['Name'].' '.($a[$type]).' times a hour. <a href="thugs.php?action=actions&id='.$id.'">Back</a>';
}
////////////
// Claim //
////////////
function claim() {
global $ir, $h, $tSettings;
$id=abs(@intval($_GET['id']));
$sql="SELECT `userid`, `tID`, `tName`, `tClaim`, `tActions` FROM `thugs` WHERE `tID`='".$id."'";
$qry=mysql_query($sql);
$t=mysql_fetch_array($qry);
if ($ir['userid'] != $t['userid']) { echo 'This is not your thug! <a href="thugs.php?action=thug&id='.$id.'">Back</a>';$h->endpage();exit;}
if ($t['tClaim'] != '0') { echo 'You have already claimed money for this thug! <a href="thugs.php?action=thug&id='.$id.'">Back</a>';$h->endpage();exit;}
$a=explode('-', $t['tActions']);
$income = ($tSettings['Actions'][1]['Income']*$a[0])+($tSettings['Actions'][2]['Income']*$a[1])+($tSettings['Actions'][3]['Income']*$a[2])+($tSettings['Actions'][4]['Income']*$a[3])+($tSettings['Actions'][5]['Income']*$a[4]);
mysql_query("UPDATE `users` SET `money`=`money`+'".$income."' WHERE `userid`='".$ir['userid']."'");
mysql_query("UPDATE `thugs` SET `tClaim`='1' WHERE `tID`='".$t['tID']."'");
echo $t['tName'].' handed you $'.number_format($income).'<a href="thugs.php?action=thug&id='.$id.'">Back</a>';
}
$h->endpage();
?>
and here is tglobals.php
<?php
///////////////////////////////////////////////////////////////////
// Thug Core System - McCodes V1/2 //
// Made By Christopher day (AKA Dayo) December 2009 //
// Support is limited for the Core system ONLY!!! //
// Support is located at cddesigns.org/support //
// Relesed under the GNU licence //
// This is the remake please email me any bugs //
// Enjoy this FREE mod Thanks, Dayo //
///////////////////////////////////////////////////////////////////
//This autoselects the version of mccodes (pure lazyness as i cant be asked to make 2 versions :P)
if (file_exists('globals.php'))
{include 'globals.php';
} else {
require "global_func.php";
if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
$userid=$_SESSION['userid'];
require "header.php";
$h = new headers;
$h->startheaders();
include "mysql.php";
global $c;
$is=mysql_query("SELECT u.,us. FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error());
$ir=mysql_fetch_array($is);
check_level();
$fm=money_formatter($ir['money']);
$lv=date('F j, Y, g:i a',$ir['laston']);
$h->userdata($ir,$lv,$fm);
$h->menuarea();
}
// Alowed values for the $_GET['action']
$actions = array('', 'thug', 'edit', 'train', 'hire', 'heal');
if (!in_array($_GET['action'], $actions)) {echo 'There was an error, The selected action is not allowed!';$h->endpage();exit;}
// This is the main settings for the thug system
$tSettings = array(
'ThugPrice'=>'2500',
'MaxThugs'=>'5'
);
// This selects the function we want to use
switch ($_GET['action']) {
default:
home();
break;
case 'thug':
thug();
break;
case 'train':
train();
break;
case 'edit':
edit();
break;
case 'heal':
heal();
break;
case 'hire':
hire();
break;
}
?>
Enjoy, Dayo 👍 .