Jump to content
MakeWebGames

[ v1 ] [ v2 ] Need code?


Recommended Posts

  • Replies 82
  • Created
  • Last Reply

Top Posters In This Topic

Mods that I really needed for V1 :)

1) A working equip/unequip weapons and armor like the in the V2 but for V1, and these weapons and armors can be used in the attack.php, exactly how its seen on V2. :)

2) A announcements mod for admins to make announcements via staff panel, and it to work exactly how it is in Mccodes V2. :)

Many thanks! :)

Link to comment
Share on other sites

Mods that I really needed for V1 :)

1) A working equip/unequip weapons and armor like the in the V2 but for V1, and these weapons and armors can be used in the attack.php, exactly how its seen on V2. :)

2) A announcements mod for admins to make announcements via staff panel, and it to work exactly how it is in Mccodes V2. :)

Many thanks! :)

With a name of "The Coder", I do believe a simple conversion should be easy for you ;)

View this topic for a short How To.

Be sure to copy over the SQL structure too ;)

Link to comment
Share on other sites

1 plug and play announcements

<?php
session_start();
require(__DIR__ . '/global_func.php');
if(!isset($_SESSION['loggedin'])) {
header("Location: login.php");
exit;
}
$userid = $_SESSION['userid'];
require(__DIR__ . '/header.php');
$h = new headers;
$h->startheaders();
require(__DIR__ . '/mysql.php');
global $c;
$is = mysql_query("SELECT `u`.*, `us`.* " . "FROM `users` AS `u` " . "LEFT JOIN `userstats` AS `us` ON (`u`.`userid` = `us`.`userid`) " . "WHERE (`u`.`userid` = " . $userid . ")", $c) or exit(mysql_error());
if(!mysql_num_rows($is)) {
echo "There appears to be an issue with your account";
$h->endpage();
exit;
}
$ir = mysql_fetch_assoc($is);
check_level();
$fm = money_formatter($ir['money']);
$cm = money_formatter($ir['crystals'], '');
$lv = date('F j, Y, g:i a', $ir['laston']);
$h->userdata($ir, $lv, $fm, $cm);
$h->menuarea();
$ac = $ir['new_announcements'];
$q = mysql_query("SELECT * FROM `announcements` ORDER BY `a_time` DESC", $c) or exit(mysql_error());
?><table width='80%' cellspacing='1' class='table'>
<tr>
	<th width='30%'>Time</th>
	<th width='70%'>Announcement</th>
</tr><?php
if(!mysql_num_rows($q)) {
?><tr><td colspan='2' style='text-align:center;'>There are no announcements</td></tr><?php
} else {
while($r = mysql_fetch_assoc($q)) {
	if($ac > 0) {
		$ac--;
		$new = '<br /><strong>New!</strong>';
	} else {
		$new = '';
	}
	?><tr style='vertical-align:top;'>
		<td><?php echo date('F j Y, g:i:s a', $r['a_time']), $new; ?></td>
		<td><?php echo nl2br(stripslashes($r['a_text'])); ?></td>
	</tr><?php
}
}
echo "</table>";
if($ir['new_announcements']) {
mysql_query("UPDATE `users` SET `new_announcements` = 0 WHERE (`userid` = " . $userid . ")", $c) or exit(mysql_error());
}
$h->endpage();
?>

 

Staff side (based on the v1 I "grew up" with):

Edit admin.php

Add

function announcements() {
global $ir, $c, $h;
if($ir['user_level'] != 2) {
	echo "You don't have access to this";
	$h->endpage();
	exit;
}
if(isset($_POST['text']) && !empty($_POST['text'])) {
	mysql_query(sprintf("INSERT INTO `announcements` VALUES('%s', %s)", mysql_real_escape_string($_POST['text'], $c), time()), $c) or exit(mysql_error());
	mysql_query("UPDATE `users` SET `new_announcements` = `new_announcements` + 1", $c) or exit(mysql_error());
	echo "Announcement added!<br />> <a href='admin.php'>Back</a>";
} else {
	?>Adding an announcement...<br />
	Please try to make sure the announcement is concise and covers everything you want it to.
	<form action='staff.php?action=announce' method='post'>
	<table class='table' width='75%' cellspacing='1'>
		<tr>
			<th width='45%'>Announcement text</th>
			<td width='55%'><textarea name='text' rows='10' cols='70'></textarea></td>
		</tr>
		<tr>
			<td colspan='2' style='text-align:center;'><input type='submit' value='Add Announcement' /></td>
		</tr>
	</table>
	</form><?php
}
}

 

SQLs

CREATE TABLE IF NOT EXISTS `announcements` (
`a_text` TEXT NOT NULL, 
`a_time` INT( 11 ) NOT NULL DEFAULT 0
);
ALTER TABLE `users` ADD `new_announcements` INT( 11 ) NOT NULL DEFAULT 0;
Edited by Magictallguy
Bug fix, converted all short tags to full
Link to comment
Share on other sites

I offer no guarantee that the code I've posted below will work as expected..

v1 attack from v2, with multiple bug/security/HTML fixes..

<?php
session_start();
require(__DIR__ . '/global_func.php');
if(!isset($_SESSION['loggedin'])) {
header("Location: login.php");
exit;
}
$userid = $_SESSION['userid'];
require(__DIR__ . '/header.php');
$h = new headers;
$h->startheaders();
require(__DIR__ . '/mysql.php');
global $c;
$is = mysql_query("SELECT `u`.*, `us`.* " . "FROM `users` AS `u` " . "LEFT JOIN `userstats` AS `us` ON (`u`.`userid` = `us`.`userid`) " . "WHERE (`u`.`userid` = " . $userid . ")", $c) or exit(mysql_error());
if(!mysql_num_rows($is)) {
echo "There appears to be an issue with your account";
$h->endpage();
exit;
}
$ir = mysql_fetch_assoc($is);
check_level();
$fm = money_formatter($ir['money']);
$cm = money_formatter($ir['crystals'], '');
$lv = date('F j, Y, g:i a', $ir['laston']);
$h->userdata($ir, $lv, $fm, $cm);
function format($str, $dec = 0) {
return ctype_digit($str) ? number_format($str, $dec) : stripslashes(htmlspecialchars($str));
}
$_GET['ID'] = isset($_GET['ID']) && ctype_digit($_GET['ID']) ? abs(@intval($_GET['ID'])) : null;
if(!$_GET['ID']) {
echo "*** you doing, bro?<br /><a href='index.php'>Back</a>";
$h->endpage();
exit;
}
if($_GET['ID'] == $userid) {
echo "Only the crazy attack themselves.<br /><a href='index.php'>Back</a>";
$h->endpage();
exit;
}
if($ir['hp'] <= 1) {
echo "Only the crazy attack when their unconscious.<br /><a href='index.php'>Back</a>";
$h->endpage();
exit;
}
if(isset($_SESSION['attacklost'])) {
echo "Only the losers of all their EXP attack when they've already lost.<br /><a href='index.php'>Back</a>";
$_SESSION['attacklost'] = 0;
$h->endpage();
exit;
}
//get player data
$q = mysql_query("SELECT `u`.*, `us`.* " . "FROM `users` AS `u` " . "LEFT JOIN `userstats` AS `us` ON (`u`.`userid` = `us`.`userid`) " . "WHERE (`u`.`userid` = " . $_GET['ID'] . ")", $c) or exit(mysql_error());
if(!mysql_num_rows($q)) {
echo "That player doesn't exist";
$h->endpage();
exit;
}
$them   = mysql_fetch_assoc($q);
$myabbr = ($ir['gender'] == "Male") ? "his" : "her";
$oabbr  = ($ir['gender'] == "Male") ? "his" : "her";
if($ir['attacking'] && $ir['attacking'] != $_GET['ID']) {
echo "Bad, bad, bad girl.<br /><a href='index.php'>Back</a>";
$_SESSION['attacklost'] = 0;
$h->endpage();
exit;
}
if($them['hp'] == 1) {
echo "This player is unconscious.<br /><a href='index.php'>> Back</a>";
$h->endpage();
$_SESSION['attacking'] = 0;
$ir['attacking']       = 0;
mysql_query("UPDATE `users` SET `attacking` = 0 WHERE (`userid` = " . $userid . ")", $c) or exit(mysql_error());
exit;
}
if($them['hospital']) {
echo "This player is in hospital.<br /><a href='index.php'>> Back</a>";
$h->endpage();
$_SESSION['attacking'] = 0;
$ir['attacking']       = 0;
mysql_query("UPDATE `users` SET `attacking` = 0 WHERE (`userid` = " . $userid . ")", $c) or exit(mysql_error());
exit;
}
if($ir['hospital']) {
echo "While in hospital you can't attack.<br /><a href='hospital.php'>> Back</a>";
$h->endpage();
$_SESSION['attacking'] = 0;
$ir['attacking']       = 0;
mysql_query("UPDATE `users` SET `attacking` = 0 WHERE (`userid` = " . $userid . ")", $c) or exit(mysql_error());
exit;
}
if($them['jail']) {
echo "This player is in jail.<br /><a href='index.php'>> Back</a>";
$h->endpage();
$_SESSION['attacking'] = 0;
$ir['attacking']       = 0;
mysql_query("UPDATE `users` SET `attacking` = 0 WHERE (`userid` = " . $userid . ")", $c) or exit(mysql_error());
exit;
}
if($ir['jail']) {
echo "While in jail you can't attack.<br /><a href='jail.php'>> Back</a>";
$h->endpage();
$_SESSION['attacking'] = 0;
$ir['attacking']       = 0;
mysql_query("UPDATE `users` SET `attacking` = 0 WHERE (`userid` = " . $userid . ")", $c) or exit(mysql_error());
exit;
}
if($them['travelling']) {
echo "That player is travelling.<br /><a href='index.php'>> Back</a>";
$h->endpage();
$_SESSION['attacking'] = 0;
$ir['attacking']       = 0;
mysql_query("UPDATE `users` SET `attacking` = 0 WHERE (`userid` = " . $userid . ")", $c) or exit(mysql_error());
exit;
}
echo "<table width='100%'><tr><td colspan='2' align='center'>";
if(isset($_GET['wepid'])) {
if(!isset($_SESSION['attacking']) && $ir['attacking'] == 0) {
	if($ir['energy'] >= $ir['maxenergy'] / 2) {
		$ir['energy'] -= floor($ir['maxenergy'] / 2);
		mysql_query(sprintf("UPDATE `users` SET `energy` = `energy` - %u WHERE (`userid` = %u)", floor($ir['maxenergy'] / 2), $userid), $c) or exit(mysql_error());
		$_SESSION['attacklog'] = "";
		$_SESSION['attackdmg'] = 0;
	} else {
		echo "You can only attack someone when you have 50% energy";
		$h->endpage();
		exit;
	}
}
$_SESSION['attacking'] = 1;
$ir['attacking']       = $them['userid'];
mysql_query("UPDATE `users` SET `attacking` = " . $ir['attacking'] . " WHERE (`userid` = " . $userid . ")", $c) or exit(mysql_error());
$_GET['wepid']    = isset($_GET['wepid']) && ctype_digit($_GET['wepid']) ? abs(@intval($_GET['wepid'])) : null;
$_GET['nextstep'] = isset($_GET['nextstep']) && ctype_digit($_GET['nextstep']) ? abs(@intval($_GET['nextstep'])) : null;
//damage

if($_GET['wepid'] != $ir['equip_primary'] && $_GET['wepid'] != $ir['equip_secondary']) {
	echo "Stop trying to abuse a game bug. You can lose all your EXP for that.<br /><a href='index.php'>> Home</a>";
	mysql_query("UPDATE `users` SET `exp` = 0 WHERE (`userid` = " . $userid . ")", $c) or exit(mysql_error());
	$h->endpage();
	exit;
}
$qo = mysql_query("SELECT * FROM `items` WHERE (`itmid` = " . $_GET['wepid'] . ")", $c) or exit(mysql_error());
if(!mysql_num_rows($qo)) {
	echo "That item doesn't exist";
	$h->endpage();
	$_SESSION['attacking'] = 0;
	$ir['attacking']       = 0;
	mysql_query("UPDATE `users` SET `attacking` = 0 WHERE (`userid` = " . $userid . ")", $c) or exit(mysql_error());
	exit;
}
$r1       = mysql_fetch_assoc($qo);
$mydamage = (int) (($r1['weapon'] * $ir['strength'] / ($them['guard'] / 1.5)) * (mt_rand(8000, 12000) / 10000));
$hitratio = max(10, min(60 * $ir['agility'] / $them['agility'], 95));
if(mt_rand(1, 100) <= $hitratio) {
	$q3 = mysql_query("SELECT `armor` FROM `items` WHERE (`itmid` = " . $them['equip_armor'] . ") ORDER BY RAND()");
	if(mysql_num_rows($q3)) {
		$mydamage -= mysql_result($q3, 0, 0);
	}
	$mydamage = ($mydamage < -100000) ? abs($mydamage) : 1;
	$crit     = mt_rand(1, 40);
	if($crit == 17) {
		$mydamage *= rand(20, 40) / 10;
	} else if($crit == 25 or $crit == 8) {
		$mydamage /= (mt_rand(20, 40) / 10);
	}
	$mydamage = round($mydamage);
	$them['hp'] -= $mydamage;
	if($them['hp'] == 1) {
		$them['hp'] = 0;
		$mydamage += 1;
	}
	mysql_query("UPDATE `users` SET `hp` = `hp` - $mydamage WHERE (`userid` = " . $_GET['ID'] . ")", $c) or exit(mysql_error());
	echo "<span style='color:red;'>", $_GET['nextstep'], ". Using your ", format($r1['itmname']), " you hit ", format($them['username']), " doing ", format($mydamage), " damage (", format($them['hp']), ")</span><br />\n";
	$_SESSION['attackdmg'] += $mydamage;
	$_SESSION['attacklog'] .= "<span style='color:red;'>" . $_GET['nextstep'] . ". Using " . $myabbr . " " . format($r1['itmname']) . ". " . format($ir['username']) . " hit " . format($them['username']) . " doing " . format($mydamage) . " damage (" . format($them['hp']) . ")</span><br />\n";
} else {
	echo "<span style='color:red;'>", $_GET['nextstep'], ". You tried to hit ", format($them['username']), " but missed (", format($them['hp']), ")</span><br />\n";
	$_SESSION['attacklog'] .= "<span style='color:red;'>" . $_GET['nextstep'] . ". " . format($ir['username']) . " tried to hit " . format($them['username']) . " but missed (" . format($them['hp']) . ")</span><br />\n";
}
if($them['hp'] <= 0) {
	$them['hp']            = 0;
	$_SESSION['attackwon'] = $_GET['ID'];
	mysql_query("UPDATE `users` SET `hp` = 0 WHERE (`userid` = " . $_GET['ID'] . ")", $c) or exit(mysql_error());
	echo "<br /><strong>What do you want to do with ", format($them['username']), " now?</strong><br />
	<form action='attackwon.php?ID=", $_GET['ID'], "' method='post'><input type='submit' value='Mug Them' /></form>
	<form action='attackbeat.php?ID=", $_GET['ID'], "' method='post'><input type='submit' value='Hospitalize Them' /></form>
	<form action='attacktake.php?ID=", $_GET['ID'], "' method='post'><input type='submit' value='Leave Them' /></form>";
} else {
	//choose opp gun
	$eq = mysql_query(sprintf("SELECT * FROM `items` WHERE (`itmid` IN(%u, %u))", $them['equip_primary'], $them['equip_secondary']), $c) or exit(mysql_error());
	if(!mysql_num_rows($eq)) {
		$wep = "Fists";
		$dam = (int) ((((int) ($them['strength'] / $ir['guard'] / 100)) + 1) * (mt_rand(8000, 12000) / 10000));
	} else {
		$cnt = 0;
		while($r = mysql_fetch_assoc($eq)) {
			$enweps[] = $r;
			$cnt++;
		}
		$weptouse = mt_rand(0, $cnt - 1);
		$wep      = $enweps[$weptouse]['itmname'];
		$dam      = (int) (($enweps[$weptouse]['weapon'] * $them['strength'] / ($ir['guard'] / 1.5)) * (mt_rand(8000, 12000) / 10000));
	}
	$hitratio = max(10, min(60 * $them['agility'] / $ir['agility'], 95));
	if(mt_rand(1, 100) <= $hitratio) {
		$q3 = mysql_query("SELECT `armor` FROM `items` WHERE (`itmid` = " . $ir['equip_armor'] . ") ORDER BY RAND()");
		if(mysql_num_rows($q3)) {
			$dam -= mysql_result($q3);
		}
		if($dam < -100000) {
			$dam = abs($dam);
		} else if($dam < 1) {
			$dam = 1;
		}
		$crit = rand(1, 40);
		if($crit == 17) {
			$dam *= rand(20, 40) / 10;
		} else if($crit == 25 or $crit == 8) {
			$dam /= (mt_rand(20, 40) / 10);
		}
		$dam = round($dam);
		$ir['hp'] -= $dam;
		if($ir['hp'] == 1) {
			$dam += 1;
			$ir['hp'] = 0;
		}
		mysql_query("UPDATE `users` SET `hp` = `hp` - " . $dam . " WHERE (`userid` = " . $userid . ")", $c) or exit(mysql_error());
		$ns = $_GET['nextstep'] + 1;
		echo "<span style='color:blue;'>", $ns, ". Using ", $oabbr, " ", format($wep), " ", format($them['username']), " hit you doing ", format($dam), " damage (", format($ir['hp']), ")</span><br />\n";
		$_SESSION['attacklog'] .= "<span style='color:blue;'>" . $ns . ". Using " . $oabbr . " " . format($wep) . " " . format($them['username']) . " hit " . format($ir['username']) . " doing " . format($dam) . " damage (" . format($ir['hp']) . ")</span><br />\n";
	} else {
		$ns = $_GET['nextstep'] + 1;
		echo "<span style='color:red;'>", $ns, ". ", format($them['username']), " tried to hit you but missed (", format($ir['hp']), ")</span><br />\n";
		$_SESSION['attacklog'] .= "<span style='color:blue;'>" . $ns . ". " . format($them['username']) . " tried to hit " . format($ir['username']) . " but missed (" . format($ir['hp']) . ")</span><br />\n";
	}
	if($ir['hp'] <= 0) {
		$ir['hp']               = 0;
		$_SESSION['attacklost'] = 1;
		mysql_query("UPDATE `users` SET `hp` = 0 WHERE (`userid` = " . $userid . ")", $c) or exit(mysql_error());
		echo "<form action='attacklost.php?ID=", $_GET['ID'], "' method='post'><input type='submit' value='Continue' />";
	}
}
} else if($them['hp'] < 5) {
echo "You can only attack those who have health";
$h->endpage();
exit;
} else if($ir['gang'] == $them['gang'] && $ir['gang'] > 0) {
echo "You are in the same gang as ", format($them['username']), "! What are you smoking today dude!";
$h->endpage();
exit;
} else if($ir['energy'] < $ir['maxenergy'] / 2) {
echo "You can only attack someone when you have 50% energy";
$h->endpage();
exit;
} else if($ir['location'] != $them['location']) {
echo "You can only attack someone in the same location!";
$h->endpage();
exit;
}
echo "</td></tr>";
if($ir['hp'] <= 0 || $them['hp'] <= 0) {
echo "</table>";
} else {
$vars['hpperc']  = round($ir['hp'] / $ir['maxhp'] * 100);
$vars['hpopp']   = 100 - $vars['hpperc'];
$vars2['hpperc'] = round($them['hp'] / $them['maxhp'] * 100);
$vars2['hpopp']  = 100 - $vars2['hpperc'];

$mw = mysql_query(sprintf("SELECT * FROM `items` WHERE (`itmid` IN(%u, %u)", $ir['equip_primary'], $ir['equip_secondary']), $c) or exit(mysql_error());
echo "<tr><td colspan='2' align='center'>Attack with:<br />";
if(mysql_num_rows($mw)) {
	while($r = mysql_fetch_assoc($mw)) {
		$ns = (!$_GET['nextstep']) ? 1 : $_GET['nextstep'] + 2;
		if($r['itmid'] == $ir['equip_primary']) {
			echo "<strong>Primary Weapon:</strong> ";
		}
		if($r['itmid'] == $ir['equip_secondary']) {
			echo "<strong>Secondary Weapon:</strong> ";
		}
		echo "<a href='attack.php?nextstep=", $ns, "&ID=", $_GET['ID'], "&wepid=", $r['itmid'], "'>", format($r['itmname']), "</a><br />";
	}
} else {
	echo "You have nothing to fight with.";
}
echo "</table>";
echo "<table width='50%' align='center'>
	<tr>
		<td align='right'>Your Health:</td>
		<td><img src='greenbar.png' width='", $vars['hpperc'], "' height='10' /><img src='redbar.png' width='", $vars['hpopp'], "' height='10' /></td>
	</tr>
	<tr>
		<td align='right'>Opponents Health:</td>
		<td><img src='greenbar.png' width='", $vars2['hpperc'], " height='10' /><img src='redbar.png' width='", $vars2['hpopp'], "' height='10' /></td>
	</tr>
</table>";
}
$h->endpage();
?>

 

inventory.php

<?php
session_start();
require(__DIR__ . '/global_func.php');
if(!isset($_SESSION['loggedin'])) {
header("Location: login.php");
exit;
}
$userid = $_SESSION['userid'];
require(__DIR__ . '/header.php');
$h = new headers;
$h->startheaders();
require(__DIR__ . '/mysql.php');
global $c;
$is = mysql_query("SELECT `u`.*, `us`.* " . "FROM `users` AS `u` " . "LEFT JOIN `userstats` AS `us` ON (`u`.`userid` = `us`.`userid`) " . "WHERE (`u`.`userid` = " . $userid . ")", $c) or exit(mysql_error());
if(!mysql_num_rows($is)) {
echo "There appears to be an issue with your account";
$h->endpage();
exit;
}
$ir = mysql_fetch_assoc($is);
check_level();
$fm = money_formatter($ir['money']);
$cm = money_formatter($ir['crystals'], '');
$lv = date('F j, Y, g:i a', $ir['laston']);
$h->userdata($ir, $lv, $fm, $cm);
$h->menuarea();
function format($str, $dec = 0) {
return ctype_digit($str) ? number_format($str, $dec) : stripslashes(htmlspecialchars($str));
}
$equp = array();
$q = mysql_query(sprintf("SELECT * FROM `items` WHERE (`itmid` IN(%u, %u, %u))", $ir['equip_primary'], $ir['equip_secondary'], $ir['equip_armor']), $c) or exit(mysql_error());
echo "<h3>Equipped Items</h3><hr />";
while($r = mysql_fetch_assoc($q)) {
$equip[$r['itmid']] = $r;
}
echo "<table width='75%' cellspacing='1' class='table'>
<tr>
<th>Primary Weapon</th>
<td>";
if($equip[$ir['equip_primary']]['itmid']) {
echo format($equip[$ir['equip_primary']]['itmname']) , "</td><td><a href='unequip.php?type=equip_primary'>Unequip Item</a></td>";
} else {
echo "None equipped.</td><td> </td>";
}
echo "</tr>
<tr>
<th>Secondary Weapon</th>
<td>";
if($equip[$ir['equip_secondary']]['itmid']) {
echo format($equip[$ir['equip_secondary']]['itmname']) , "</td><td><a href='unequip.php?type=equip_secondary'>Unequip Item</a></td>";
} else {
echo "None equipped.</td><td> </td>";
}
echo "</tr>
<tr>
<th>Armor</th>
<td>";
if($equip[$ir['equip_armor']]['itmid']) {
echo format($equip[$ir['equip_armor']]['itmname']) , "</td><td><a href='unequip.php?type=equip_armor'>Unequip Item</a></td>";
} else {
echo "None equipped.</td><td> </td>";
}
echo "</tr>
</table><hr />
<h3>Inventory</h3><hr />";
$inv = mysql_query("SELECT `iv`.*, `i`.*, `it`.* " .
				"FROM `inventory` AS `iv` " .
				"LEFT JOIN `items` AS `i` ON (`iv`.`inv_itemid` = `i`.`itmid`) " .
				"LEFT JOIN `itemtypes` AS `it` ON (`i`.`itmtype` = `it`.`itmtypeid`) " .
				"WHERE (`iv`.`inv_userid` = ".$userid.") " .
				"ORDER BY `i`.`itmtype` ASC, `i`.`itmname` ASC", $c) or exit(mysql_error());
if(!mysql_num_rows($inv)) {
echo "<strong>You have no items!</strong>";
$h->endpage();
exit;
}
echo "<strong>Your items are listed below.</strong><br />
<table width='100%' class='table' border='0' cellspacing='1'>
<tr>
<td class='h'>Item</td>
<td class='h'>Sell Value</td>
<td class='h'>Total Sell Value</td>
<td class='h'>Links</td>
</tr>";
$lt = "";
while($i = mysql_fetch_assoc($inv)) {
if($lt != $i['itmtypename']) {
	$lt = $i['itmtypename'];
	echo "\n<tr><td colspan=4><strong>",format($lt),"</strong></td></tr>";
}
if($i['weapon']) {
	$i['itmname'] = "<span style='color:red;'>*</span>" . format($i['itmname']);
}
if($i['armor']) {
	$i['itmname'] = "<span style='color:green;'>*</span>" . format($i['itmname']);
}
echo "<tr><td>{$i['itmname']}";
if($i['inv_qty'] > 1) {
	echo " x",format($i['inv_qty']);
}
echo "</td><td>\$",format($i['itmsellprice']),"</td><td>";
echo "$" . format($i['itmsellprice'] * $i['inv_qty']);
echo "</td><td>[<a href='iteminfo.php?ID=",$i['itmid'],"'>Info</a>] [<a href='itemsend.php?ID=",$i['inv_id'],"'>Send</a>] [<a href='itemsell.php?ID=",$i['inv_id'],"'>Sell</a>] [<a href='imadd.php?ID=",$i['inv_id'],"'>Add To Market</a>]";
if($i['effect1_on'] || $i['effect2_on'] || $i['effect3_on']) {
	echo " [<a href='itemuse.php?ID=",$i['inv_id'],"'>Use</a>]";
}
if($i['weapon']) {
	echo " [<a href='equip_weapon.php?ID=",$i['inv_id'],"'>Equip as Weapon</a>]";
}
if($i['armor']) {
	echo " [<a href='equip_armor.php?ID=",$i['inv_id'],"'>Equip as Armor</a>]";
}
echo "</td></tr>";
}
echo "</table><small><strong>NB:</strong> 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>";

$h->endpage();
?>

 

equip_armor.php

<?php
session_start();
require(__DIR__ . '/global_func.php');
if(!isset($_SESSION['loggedin'])) {
header("Location: login.php");
exit;
}
$userid = $_SESSION['userid'];
require(__DIR__ . '/header.php');
$h = new headers;
$h->startheaders();
require(__DIR__ . '/mysql.php');
global $c;
$is = mysql_query("SELECT `u`.*, `us`.* " . "FROM `users` AS `u` " . "LEFT JOIN `userstats` AS `us` ON (`u`.`userid` = `us`.`userid`) " . "WHERE (`u`.`userid` = " . $userid . ")", $c) or exit(mysql_error());
if(!mysql_num_rows($is)) {
echo "There appears to be an issue with your account";
$h->endpage();
exit;
}
$ir = mysql_fetch_assoc($is);
check_level();
$fm = money_formatter($ir['money']);
$cm = money_formatter($ir['crystals'], '');
$lv = date('F j, Y, g:i a', $ir['laston']);
$h->userdata($ir, $lv, $fm, $cm);
$h->menuarea();
function format($str, $dec = 0) {
return ctype_digit($str) ? number_format($str, $dec) : stripslashes(htmlspecialchars($str));
}
$_GET['ID'] = isset($_GET['ID']) && ctype_digit($_GET['ID']) ? abs(@intval($_GET['ID'])) : null;
$id         = mysql_query("SELECT `iv`.*, `it`.* " .
						"FROM `inventory` AS `iv` " .
						"LEFT JOIN `items` AS `it` ON (`iv`.`inv_itemid` = `it`.`itmid`) " .
						"WHERE ((`iv`.`inv_id` = ".$_GET['ID'].") AND (`iv`.`inv_userid` = ".$userid.")) LIMIT 1", $c) or exit(mysql_error());
if(!mysql_num_rows($id)) {
echo "Invalid item ID";
$h->endpage();
exit;
}
$r = mysql_fetch_assoc($id);
if(!$r['armor']) {
echo "This item cannot be equipped to this slot.";
$h->endpage();
exit;
}
if(isset($_GET['type'])) {
if($_GET['type'] != 'equip_armor') {
	echo "This slot ID is not valid.";
	$h->endpage();
	exit;
}
if($ir[$_GET['type']]) {
	item_add($userid, $ir[$_GET['type']], 1);
}
item_remove($userid, $r['itmid'], 1);
mysql_query("UPDATE `users` SET `".$_GET['type']."` = ".$r['itmid']." WHERE (`userid` = ".$userid.")", $c) or exit(mysql_error());
echo "Your ",format($r['itmname'])," has been equipped successfully.";
} else {
echo "<h3>Equip Armor</h3><hr />
<form action='equip_armor.php' method='get'>
<input type='hidden' name='ID' value='",$_GET['ID'],"' />
Click Equip Armor to equip ",format($r['itmname'])," as your armor, if you currently have any armor equipped it will be removed back to your inventory.<br />
<input type='hidden' name='type' value='equip_armor'  />
<input type='submit' value='Equip Armor' /></form>";
}
$h->endpage();
?>

 

equip_weapon.php

<?php
session_start();
require(__DIR__ . '/global_func.php');
if(!isset($_SESSION['loggedin'])) {
header("Location: login.php");
exit;
}
$userid = $_SESSION['userid'];
require(__DIR__ . '/header.php');
$h = new headers;
$h->startheaders();
require(__DIR__ . '/mysql.php');
global $c;
$is = mysql_query("SELECT `u`.*, `us`.* " . "FROM `users` AS `u` " . "LEFT JOIN `userstats` AS `us` ON (`u`.`userid` = `us`.`userid`) " . "WHERE (`u`.`userid` = " . $userid . ")", $c) or exit(mysql_error());
if(!mysql_num_rows($is)) {
echo "There appears to be an issue with your account";
$h->endpage();
exit;
}
$ir = mysql_fetch_assoc($is);
check_level();
$fm = money_formatter($ir['money']);
$cm = money_formatter($ir['crystals'], '');
$lv = date('F j, Y, g:i a', $ir['laston']);
$h->userdata($ir, $lv, $fm, $cm);
$h->menuarea();
function format($str, $dec = 0) {
return ctype_digit($str) ? number_format($str, $dec) : stripslashes(htmlspecialchars($str));
}
$_GET['ID'] = isset($_GET['ID']) && ctype_digit($_GET['ID']) ? abs(@intval($_GET['ID'])) : null;
$id         = mysql_query("SELECT `iv`.*, `it`.* " .
						"FROM `inventory` AS `iv` " .
						"LEFT JOIN `items` AS `it` ON (`iv`.`inv_itemid` = `it`.`itmid`) " .
						"WHERE ((`iv`.`inv_id` = ".$_GET['ID'].") AND (`iv`.`inv_userid` = ".$userid.")) LIMIT 1", $c) or exit(mysql_error());
if(!mysql_num_rows($id)) {
echo "Invalid item ID";
$h->endpage();
exit;
}
$r = mysql_fetch_assoc($id);
if(!$r['weapon']) {
echo "This item cannot be equipped to this slot.";
$h->endpage();
exit;
}
if(isset($_GET['type'])) {
if(!in_array($_GET['type'], array('equip_primary', 'equip_secondary'))) {
	echo "This slot ID is not valid.";
	$h->endpage();
	exit;
}
if($ir[$_GET['type']]) {
	item_add($userid, $ir[$_GET['type']], 1);
}
item_remove($userid, $r['itmid'], 1);
mysql_query("UPDATE `users` SET `".$_GET['type']."` = ".$r['itmid']." WHERE (`userid` = ".$userid.")", $c) or exit(mysql_error());
echo "Your ",format($r['itmname'])," has been equipped successfully.";
} else {
echo "<h3>Equip Weapon</h3><hr />
<form action='equip_weapon.php' method='get'>
<input type='hidden' name='ID' value='",$_GET['ID'],"' />
Please choose the slot to equip ",format($r['itmname'])," to, if there is already a weapon in that slot, it will be removed back to your inventory.<br />
<input type='radio' name='type' value='equip_primary' checked='checked' /> Primary<br />
<input type='radio' name='type' value='equip_secondary' /> Secondary<br />
<input type='submit' value='Equip Weapon' /></form>";
}
$h->endpage();
?>

 

I don't know what v1 SQLs exist.. So I'll stick the SQLs needed here anyway

ALTER TABLE `users` ADD (
`equip_primary` INT( 11 ) NOT NULL DEFAULT 0,
`equip_secondary` INT( 11 ) NOT NULL DEFAULT 0,
`equip_armor` INT( 11 ) NOT NULL DEFAULT 0
);
Link to comment
Share on other sites

With a name of "The Coder", I do believe a simple conversion should be easy for you ;)

View this topic for a short How To.

Be sure to copy over the SQL structure too ;)

If you take anything from v2's database or the actual code from one file doesn't that negate the point of using the free one in the first place?

Link to comment
Share on other sites

If you take anything from v2's database or the actual code from one file doesn't that negate the point of using the free one in the first place?

Perhaps he likes the v1 code structure (why, I don't know..), and also likes the features of v2.

Those 3 column additions to the users table really isn't that much, and the conversion was simple enough.. There's enough of v2 floating around to grab a copy

Link to comment
Share on other sites

Perhaps he likes the v1 code structure (why, I don't know..), and also likes the features of v2.

Those 3 column additions to the users table really isn't that much, and the conversion was simple enough.. There's enough of v2 floating around to grab a copy

Fair enough. I would have added another bit of reputation, but apparently I still need to give it out to others first. :p

Link to comment
Share on other sites

You may have a little problem with this:

 

if(isset($_POST['text']) && empty($_POST['text'])) {

 

1 plug and play announcements
<?php
session_start();
require(__DIR__ . '/global_func.php');
if(!isset($_SESSION['loggedin'])) {
   header("Location: login.php");
   exit;
}
$userid = $_SESSION['userid'];
require(__DIR__ . '/header.php');
$h = new headers;
$h->startheaders();
require(__DIR__ . '/mysql.php');
global $c;
$is = mysql_query("SELECT `u`.*, `us`.* " .
                   "FROM `users` AS `u` " .
                   "LEFT JOIN `userstats` AS `us` ON (`u`.`userid` = `us`.`userid`) " .
                   "WHERE (`u`.`userid` = ".$userid.")", $c) or exit(mysql_error());
if(!mysql_num_rows($is)) {
   echo "There appears to be an issue with your account";
   $h->endpage();
   exit;
}
$ir = mysql_fetch_assoc($is);
check_level();
$fm = money_formatter($ir['money']);
$cm = money_formatter($ir['crystals'], '');
$lv = date('F j, Y, g:i a', $ir['laston']);
$h->userdata($ir, $lv, $fm, $cm);
$h->menuarea();
$ac = $ir['new_announcements'];
$q  = mysql_query("SELECT * FROM `announcements` ORDER BY `a_time` DESC", $c) or exit(mysql_error());
?><table width='80%' cellspacing='1' class='table'>
   <tr>
       <th width='30%'>Time</th>
       <th width='70%'>Announcement</th>
   </tr><?
if(!mysql_num_rows($q)) {
   ?><tr><td colspan='2' style='text-align:center;'>There are no announcements</td></tr><?
} else {
   while($r = mysql_fetch_assoc($q)) {
       if($ac > 0) {
           $ac--;
           $new = '<br /><strong>New!</strong>';
       } else {
           $new = '';
       }
       ?><tr style='vertical-align:top;'>
           <td><? echo date('F j Y, g:i:s a', $r['a_time']) , $new; ?></td>
           <td><? echo nl2br(stripslashes($r['a_text'])); ?></td>
       </tr><?
   }
}
echo "</table>";
if($ir['new_announcements']) {
   mysql_query("UPDATE `users` SET `new_announcements` = 0 WHERE (`userid` = ".$userid.")", $c) or exit(mysql_error());
}
$h->endpage();
?>

 

Staff side (based on the v1 I "grew up" with):

Edit admin.php

Add

function announcements() {
   global $ir, $c, $h;
   if($ir['user_level'] != 2) {
       echo "You don't have access to this";
       $h->endpage();
       exit;
   }
   if(isset($_POST['text']) && empty($_POST['text'])) {
       mysql_query(sprintf("INSERT INTO `announcements` VALUES('%s', %s)", mysql_real_escape_string($_POST['text'], $c), time()), $c) or exit(mysql_error());
       mysql_query("UPDATE users SET new_announcements=new_announcements+1");
       echo "Announcement added!<br />> <a href='admin.php'>Back</a>";
   } else {
       ?>Adding an announcement...<br />
       Please try to make sure the announcement is concise and covers everything you want it to.
       <form action='staff.php?action=announce' method='post'>
       <table class='table' width='75%' cellspacing='1'>
           <tr>
               <th width='45%'>Announcement text</th>
               <td width='55%'><textarea name='text' rows='10' cols='70'></textarea></td>
           </tr>
           <tr>
               <td colspan='2' style='text-align:center;'><input type='submit' value='Add Announcement' /></td>
           </tr>
       </table>
       </form><?
   }
}

 

SQLs

CREATE TABLE IF NOT EXISTS `announcements` (
`a_text` TEXT NOT NULL, 
`a_time` INT( 11 ) NOT NULL DEFAULT 0
);
ALTER TABLE `users` ADD `new_announcements` INT( 11 ) NOT NULL DEFAULT 0;
Link to comment
Share on other sites

You also appear to be using short PHP tags which aren't always enabled and can cause issues.

if(!mysql_num_rows($q)) {    
?><tr><td colspan='2' style='text-align:center;'>There are no announcements</td></tr><?
} else {
Link to comment
Share on other sites

Hey, heres one, this one quite nifty and big, and you don't need to do it at all MTG. :)

A new Donator System with IPN.

Features:

- Staff Side to create DP's (no limit to amount of items used in DP's)

- Admins can also set a limited stock on whatever DP... E.g = Special Donator Pack [10 Left].

- An IPN so after purchase, the user is automatically given the item.

If its possible, that would be an awesome mod. :)

Link to comment
Share on other sites

No it doesn't but in my opinion it's not right in creating the exact same mod as someone else and realising it for free.

That's fair enough, but I believe there is actually such a system on here already. It doesn't have 1/2 the features Dave's does, but then... it's free what do you expect?

Link to comment
Share on other sites

Getting back to the Donator with IPN request... You do realise, right, that "IPN" stands for "Instant Payment Notification" - that part is enabled on your PayPal itself.

You can set up your system to automatically credit the donator pack/will potions using an IPN, but the IPN itself is *not* the auto-credit..

Screenshots on how to set up IPN

Edited by Magictallguy
Added visual instructions on how to set up IPN
Link to comment
Share on other sites

Getting back to the Donator with IPN request... You do realise, right, that "IPN" stands for "Instant Payment Notification" - that part is enabled on your PayPal itself.

You can set up your system to automatically credit the donator pack/will potions using an IPN, but the IPN itself is *not* the auto-credit..

Screenshots on how to set up IPN

He was asking for a full donation system not just the IPN itself.

Link to comment
Share on other sites

Thanks. And what i wanted was something like Daves Mod but different in its own ways. So no cart system like Daves, No ajax, etc etc. Just a simple auto crediting dp system with the acess for staff to create dp's with unlimted item and set some dp's with a limited stock. :)

Link to comment
Share on other sites

Thanks. And what i wanted was something like Daves Mod but different in its own ways. So no cart system like Daves, No ajax, etc etc. Just a simple auto crediting dp system with the acess for staff to create dp's with unlimited item and set some dp's with a limited stock. :)

May write that up, sounds like something I'd use

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...