Cronwerks MCCode/MCCodes Forums

Please login or register.

Login with username, password and session length

News:

Have errors in your coding or want something specific added to your game? Check out our paid support here.


AuthorTopic: Re-coded inv with jQuery  (Read 212 times)

Danny696

  • Excellent Member
  • ***
  • Reputation Power: 276
  • Danny696 has a powerful will.Danny696 has a powerful will.Danny696 has a powerful will.Danny696 has a powerful will.Danny696 has a powerful will.Danny696 has a powerful will.Danny696 has a powerful will.
  • Offline Offline
  • Posts: 457
    • View Profile
Re-coded inv with jQuery
« on: February 25, 2010, 02:37:31 PM »
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:
Code: [Select]
<?php
@include_once(DIRNAME(__FILE__) .'/globals.php');
?>

<!-- Get the jquery from google. -->
<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'])), 00);
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'])), 00);
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'])), 00);
echo 
$name;
echo
'</td>';
}
else { echo
'Nothing Equipped.</td>'; }
echo
'</tr>
<tr>
<td>'
;
if(
$ir['equip_primary'] != 0) {
echo
'<a href="" onmousedown=\'$.get("unequip.php", { action: "type", type: "pri" } )\'>Unequip weapon</a></td><td>';
}
else {
echo
'No weapon equipped.</td><td>';
}
if(
$ir['equip_secondary'] != 0) {
echo
'<a href="" onmousedown=\'$.get("unequip.php", { action: "type", type: "sec" } )\'>Unequip weapon</a></td><td>';
}
else {
echo
'No weapon equipped.</td><td>';
}
if(
$ir['equip_armor'] != 0) {
echo
'<a href="" onmousedown=\'$.get("unequip.php", { action: "type", type: "arm" } )\'>Remove armor</a></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.<br />
<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) ? '&nbsp;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>[<a href="iteminfo.php?ID='
.$item['itmid'].'">Info</a>]&nbsp;[<a href="itemsend.php?ID='.$item['inv_id'].'">Send</a>]&nbsp;[<a href="itemsell.php?ID='.$item['inv_id'].'">Sell</a>]&nbsp;[<a href="imadd.php?ID='.$item['inv_id'].'">Add to market</a>]';
if(
$item['effect1_on'] || $item['effect2_on'] || $item['effect3_on']) {
echo
'&nbsp;[<a href="itemuse.php?ID='.$item['inv_id'].'">Use</a>]';
}
if(
$item['weapon']) {
echo
'&nbsp; [<a href="" onmousedown=\'$.get("equip_weapon.php", { action: "item", item: "'.$item['itmid'].'", slot: "pri" } )\'>Equip as primary</a>]&nbsp;[<a href="" onmousedown=\'$.get("equip_weapon.php", { action: "item", item: "'.$item['itmid'].'", slot: "sec" } )\'>Equip as secondary</a>]';
}
if(
$item['armor']) {
echo
'&nbsp; [<a href="" onmousedown=\'$.get("equip_armor.php", { action: "item", item: "'.$item['itmid'].'" } )\'>Equip as armor</a>]';
}
echo
'</td></tr>';
}
echo
'<tr>
<td colspan="4"><small><span style="font-weight: bold;">Note:</span><small>Items with a small red </small>
<span style="color: red;">*</span><small>next to their name can be used as weapons in combat.<br />
Items with a small green </small><span style="color: green;">*</span><small> next to their name can be used as armor in combat.</small>
</td>
</tr>
</table>'
;
$h->endpage()
?>


Equip_armor.php:
Code: [Select]
<?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:
Code: [Select]
<?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:
Code: [Select]
<?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
Logged
My Game: GraveYard; Madness || Projects; N/A -  Available for work. Please IM/PM me.