I got bored earlier so decided to re create the gym that is seen on "Torn", yes I copied so what I was bored and it's 1,000,000 times better than default gym.
gym.php
<?php
//
# Only to be posted on MAKEWEBGAMES #
# Made by the user Zed #
# No re-distribution or reselling #
//
include(DIRNAME(__FILE__).'/globals.php');
?>
<noscript>This gym requires the use of [b]JAVASCRIPT[/b] in order to work.</noscript>
<div style=" background-color: #dfdfdf; -moz-border-radius: 5px; -webkit-border-radius: 5px; border: 2px solid #A7A7A7; padding: 10px; width: 70%;" id = "gContent" >
[b]Welcome to the gym! What would you like to train today?[/b]
<span style = "font-size:10px; color: #8B0000;">You have <?php echo (''.number_format($ir['energy']).'/'.number_format($ir['maxenergy']).''); ?> energy available</span>
</div>
<table width = "75%" style = "border: 1px solid #A7A7A7; text-align:left; padding: 10px;">
<form action = "" method = "">
<tr style = "background: #CCCCCC; padding: 10px;">
<td width = "80%">
-Strength
<span style = "font-size:10px; color: #8B0000;">-Increases the damage you make on impact</span>
</td>
<td width = "50%"> <input type = "text" value = "1" id = "strength" size = "1" /> <input type = "button" value = "Train" onClick = "javascript: gDo('strength');" /> </td>
</tr>
<tr style = "background: #dfdfdf; padding: 10px;">
<td width = "80%">
-Defence
<span style = "font-size:10px; color: #8B0000;">-Increases your ability to withstand damage</span>
</td>
<td> <input type = "text" value = "1" id = "defence" size = "1" /> <input type = "button" value = "Train" onClick = "javascript: gDo('defence');" /> </td>
</tr>
<tr style = "background: #CCCCCC; padding: 10px;">
<td width = "80%">
-Speed
<span style = "font-size:10px; color: #8B0000;">-Increases your likelihood to make contact with your opponent</span>
</td>
<td> <input type = "text" value = "1" id = "speed" size = "1" /> <input type = "button" value = "Train" onClick = "javascript: gDo('speed');" /> </td>
</tr>
</form>
</table>
<?php $h->endpage(); ?>
<script type = "text/javascript">
var xmlhttp;
try { xmlhttp = new XMLHttpRequest(); } catch(e) { try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { alert("Browser Incompatibility error!"); } } }
function gDo(stat)
{
xmlhttp.onreadystatechange = function()
{
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
document.getElementById("gContent").innerHTML = xmlhttp.responseText;
}
}
var uAmt = document.getElementById(stat).value;
xmlhttp.open("GET","gDo.php?uStat=" + stat +"&uAmount="+ uAmt, true);
xmlhttp.send();
}
</script>
gDo.php
<?php
//
# Only to be posted on MAKEWEBGAMES #
# Made by the user Zed #
# No re-distribution or reselling #
//
if(!isset($_GET['uStat']) || !isset($_GET['uAmount']))
{
echo ('An error has occured, please try again.');
exit;
}
//DB connections.
session_start();
include "config.php";
global $_CONFIG;
define("MONO_ON", 1);
require "class/class_db_{$_CONFIG['driver']}.php";
$db=new database;
$db->configure($_CONFIG['hostname'],
$_CONFIG['username'],
$_CONFIG['password'],
$_CONFIG['database'],
$_CONFIG['persistent']);
$db->connect();
$c=$db->connection_id;
//
$Data = mysql_fetch_assoc(mysql_query("SELECT `energy`,`will`,`maxenergy` FROM `users` WHERE (`userid` = ".$_SESSION['userid'].")")) or die(mysql_error());
if(!in_array($_GET['uStat'], array('strength','speed','defence')))
{
echo ('An error has occured, please try again.');
exit;
}
if(!ctype_digit($_GET['uAmount']))
{
echo ('An error has occured, please try again.');
exit;
}
if($_GET['uAmount'] > $Data['energy'])
{
echo ('You don\'t have enough energy to train this amount.
<span style = "font-size:10px; color: #8B0000;">You have '.number_format($Data['energy']).'/'.number_format($Data['maxenergy']).' energy available</span>
');
exit;
}
//Formula, YES it sucks but you can change it whenever.
$Gain = $_GET['uAmount'] * $Data['will'] / 551;
echo ('<span style = "color:green; font-weight:bold;">You gained '.number_format($Gain, 3).' '.$_GET['uStat'].' by training '.number_format($_GET['uAmount']).' times.</span>
<span style = "font-size:10px; color: #8B0000;">You have '.number_format($Data['energy']).'/'.number_format($Data['maxenergy']).' energy available</span>');
mysql_query("UPDATE `users` SET `energy` = `energy` - ".intval($_GET['uAmount']).", `will` = `will` - ".intval($_GET['uAmount'])." * 2 WHERE (`userid` = ".$_SESSION['userid'].")");
mysql_query("UPDATE `userstats` SET ".$_GET['uStat']." = ".$_GET['uStat']." + ".intval($Gain)." WHERE (`userid` = ".$_SESSION['userid'].")");
exit;
?>
It hasn't been tested very well, I'll leave that to you guys, it was just something I did in a spare 15mins, let me know of any problems, .
If anyone is going to cry about it looking like torns (Danny696) please cry somewhere else, it's better than the default.
EDIT: http://img821.imageshack.us/img821/9906/1280584817955.png