Well, i was trying to learn javascript, in the book, it had jQuery, talked about $.get and $.post so i thought could it be usefull for equiping/unequipping quicker. So ive re-coded it and im thinking of re-coding others with parts of jQuery, i pull it from google, uses less stress on sever load. but anyway, 4 re-coded files, no tables, great mod!
inv/inventory.php:
<?php
@include_once(DIRNAME(__FILE__) .'/globals.php');
?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<?php
$items = $db->query(sprintf("SELECT itmname FROM items WHERE itmid IN(%u, %u, %u)", $ir['equip_primary'], $ir['equip_secondary'], $ir['equip_armor']));
$r = $db->fetch_row($items);
echo'<h3><span style="font-weight: bold;">Equipped Items</span></h3>';
echo'<table width="80%" class="table" style="text-align: center;">
<tr style="align: center;">
<th>Primary Weapon</th>
<th>Secondary Weapon</th>
<th>Armor</th>
</tr>
<tr>
<td>';
if($ir['equip_primary'] != 0) {
$name = @mysql_result($db->query(sprintf("SELECT itmname FROM items WHERE itmid=%u LIMIT 1", $ir['equip_primary'])), 0, 0);
echo $name;
echo'</td><td>';
}
else { echo'Nothing Equipped.</td><td>'; }
if($ir['equip_secondary'] != 0) {
$name = @mysql_result($db->query(sprintf("SELECT itmname FROM items WHERE itmid=%u LIMIT 1", $ir['equip_secondary'])), 0, 0);
echo $name;
echo'</td><td>';
}
else { echo'Nothing Equipped.</td><td>'; }
if($ir['equip_armor'] != 0) {
$name = @mysql_result($db->query(sprintf("SELECT itmname FROM items WHERE itmid=%u LIMIT 1", $ir['equip_armor'])), 0, 0);
echo $name;
echo'</td>';
}
else { echo'Nothing Equipped.</td>'; }
echo'</tr>
<tr>
<td>';
if($ir['equip_primary'] != 0) {
echo'[url=""]Unequip weapon[/url]</td><td>';
}
else {
echo'No weapon equipped.</td><td>';
}
if($ir['equip_secondary'] != 0) {
echo'[url=""]Unequip weapon[/url]</td><td>';
}
else {
echo'No weapon equipped.</td><td>';
}
if($ir['equip_armor'] != 0) {
echo'[url=""]Remove armor[/url]</td>';
}
else {
echo'No weapon equipped.</td>';
}
echo'</tr>
</table>';
$itemsleft = $db->query(sprintf("SELECT iv.*,i.*,it.* ".
"FROM inventory iv ".
"LEFT JOIN items i ON iv.inv_itemid=i.itmid ".
"LEFT JOIN itemtypes it ON i.itmtype=it.itmtypeid ".
"WHERE iv.inv_userid=%u ".
"ORDER BY i.itmtype ASC, i.itmname ASC", $userid));
echo'<hr />';
if($db->num_rows($itemsleft) == 0) {
echo'<big>You have no items!</big>';
$h->endpage();
exit;
}
echo'Your items are listed below.
<table width="100%" class="table" style="text-align: center;">
<tr>
<th>Item name</th>
<th>Sell value</th>
<th>Total sell value</th>
<th>Links</th>
</tr>';
$name="";
while($item = $db->fetch_row($itemsleft)) {
if($name != $item['itmtypename']) {
$name = $item['itmtypename'];
echo'<tr>
<td colspan="4"><span style="font-weight: bold;">'.$name.'</span></td>
</tr>';
}
$a = ($item['weapon'] > 0) ? '<span style="color: red;">*</span>' : '';
$b = ($item['armor'] > 0) ? '<span style="color: green;">*</span>' : '';
$c = ($item['inv_qty'] > 1) ? 'X '.number_format($item['inv_qty']).'' : '';
echo'<tr>
<td>'.$a.$b.$item['itmname'].$c.'</td>
<td>'.money_formatter($item['itmsellprice']).'</td>
<td>'.money_formatter($item['itmsellprice']*$item['inv_qty']).'</td>
<td>[[url="iteminfo.php?ID='.$item['itmid'].'"]Info[/url]][[url="itemsend.php?ID='.$item['inv_id'].'"]Send[/url]][[url="itemsell.php?ID='.$item['inv_id'].'"]Sell[/url]][[url="imadd.php?ID='.$item['inv_id'].'"]Add to market[/url]]';
if($item['effect1_on'] || $item['effect2_on'] || $item['effect3_on']) {
echo'[[url="itemuse.php?ID='.$item['inv_id'].'"]Use[/url]]';
}
if($item['weapon']) {
echo' [[url=""]Equip as primary[/url]][[url=""]Equip as secondary[/url]]';
}
if($item['armor']) {
echo' [[url=""]Equip as armor[/url]]';
}
echo'</td></tr>';
}
echo'<tr>
<td colspan="4">[size="1"]<span style="font-weight: bold;">Note:</span><small>Items with a small red [/size]
<span style="color: red;">*</span>[size="1"]next to their name can be used as weapons in combat.
Items with a small green [/size]<span style="color: green;">*</span>[size="1"] next to their name can be used as armor in combat.[/size]
</td>
</tr>
</table>';
$h->endpage()
?>
Equip_armor.php:
<?php
@include_once(DIRNAME(__FILE__) .'/globals.php');
error_reporting(E_ALL);
//The user should never see this file, no need to use echo or print anywhere!!!!!! :D
$_GET['item'] = abs(@intval($_GET['item']));
$iteminfo = $db->query(sprintf("SELECT itmname, itmid, armor FROM items WHERE itmid=%u LIMIT 1", $_GET['item']));
if($db->num_rows($iteminfo) == 0) {
exit;
}
$i = $db->fetch_row($iteminfo);
if($i['armor'] == 0) {
exit;
}
if($ir['equip_armor']) {
item_add($userid, $ir['equip_armor'], 1);
}
item_remove($userid, $_GET['item'], 1);
$db->query(sprintf("UPDATE users SET equip_armor=%u WHERE userid=%d", $_GET['item'], $userid));
?>
equip_weapon.php:
<?php
@include_once(DIRNAME(__FILE__) .'/globals.php');
error_reporting(E_ALL);
//The user should never see this file, no need to use echo or print anywhere!!!!!! :D
$_GET['item'] = abs(@intval($_GET['item']));
$iteminfo = $db->query(sprintf("SELECT itmname, itmid, weapon FROM items WHERE itmid=%u LIMIT 1", $_GET['item']));
if($db->num_rows($iteminfo) == 0) {
exit;
}
$i = $db->fetch_row($iteminfo);
if($i['weapon'] == 0) {
exit;
}
if(!in_array($_GET['slot'], array('pri', 'sec'))) {
exit;
}
if($_GET['slot'] == 'pri') {
if($ir['equip_primary']) {
item_add($userid, $ir['equip_primary'], 1);
}
item_remove($userid, $_GET['item'], 1);
$db->query(sprintf("UPDATE users SET `equip_primary`=%u WHERE userid=%d", $_GET['item'], $userid));
}
else if($_GET['slot'] == 'sec') {
if($ir['equip_secondary']) {
item_add($userid, $ir['equip_secondary'], 1);
}
item_remove($userid, $_GET['item'], 1);
$db->query(sprintf("UPDATE users SET `equip_secondary`=%u WHERE userid=%d", $_GET['item'], $userid));
}
else { exit; }
?>
Unequip.php:
<?php
@include_once(DIRNAME(__FILE__) .'/globals.php');
error_reporting(E_ALL);
//The user should never see this file, no need to use echo or print anywhere!!!!!! :D
if(!in_array($_GET['type'], array('pri', 'sec', 'arm'))) {
exit;
}
if($_GET['type'] == 'pri') {
if($ir['equip_primary'] == 0) { exit; }
item_add($userid, $ir['equip_primary'], 1);
$db->query(sprintf("UPDATE users SET equip_primary=0 WHERE userid=%u", $userid));
}
elseif($_GET['type'] == 'sec') {
if($ir['equip_secondary'] == 0) { exit; }
item_add($userid, $ir['equip_secondary'], 1);
$db->query(sprintf("UPDATE users SET equip_secondary=0 WHERE userid=%u", $userid));
}
elseif($_GET['type'] == 'arm') {
if($ir['equip_armor'] == 0) { exit; }
item_add($userid, $ir['equip_armor'], 1);
$db->query(sprintf("UPDATE users SET equip_armor=0 WHERE userid=%u", $userid));
}
else { exit; }
?>
Simplez