Witam. Z PHP styczno¶æ mam od nie dawna. Nie umiem wiele, a wrecz prawie nic. Ale do rzeczy.
Chce zedytowaæ pewien skrypt RPG. Nawet dobrze mi idzie, ale napotka³em problem.
To jest oryginalny kod:
<?php
/*
MCCodes Lite
itemuse.php Rev 1.0.0
Copyright (C) 2006 Dabomstew
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
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";
$is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid W
HERE u.userid=$userid",$c) or
die(mysql_error()); check_level();
$fm=money_formatter($ir['money']);
$lv=date('F j, Y, g:i a',$ir['laston']); $h->userdata($ir,$lv,$fm);
$h->menuarea();
$_GET['ID'] = abs((int
) $_GET['ID']); //Medical
if(!$_GET['ID'])
{
print "Invalid use of file"; }
else
{
$i=mysql_query("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_id={$_GET['ID']} AND iv.inv_userid=$userid",$c); {
}
else
{
if($r['itmtypename'] == 'Medical')
{
$f=mysql_query("SELECT * FROM medical WHERE item_id={$r['itmid']}",$c); mysql_query("UPDATE inventory SET inv_qty=inv_qty-1 WHERE inv_id={$_GET['ID']}",$c); mysql_query("DELETE FROM inventory WHERE inv_qty=0",$c); mysql_query("UPDATE users SET hp=hp+{$fr['hp']} WHERE userid=$userid"); mysql_query("UPDATE users SET hp=maxhp WHERE hp > maxhp"); print "You cram a {$r['itmname']} into your mouth. You feel a bit of energy coming back to you."; }
else
{
print "You cannot use this item."; }
}
}
$h->endpage();
?>
Tutaj chodzi o regeneracje hp przez medicine. I dodam, ze tutaj wszystko dziala bez problemów. Ja chcia³bym dodaæ regenracje energii przez jedzenie (food). Na podstawie urywku tego kodu stworzy³em cos takiego:
<?php
//Food
if(!$_GET['ID'])
{
print "Invalid use of file"; }
else
{
$i=mysql_query("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_id={$_GET['ID']} AND iv.inv_userid=$userid",$c); {
}
else
{
if($r['itmtypename'] == 'Food')
{
$f=mysql_query("SELECT * FROM food WHERE item_id={$r['itmid']}",$c); mysql_query("UPDATE inventory SET inv_qty=inv_qty-1 WHERE inv_id={$_GET['ID']}",$c); mysql_query("DELETE FROM inventory WHERE inv_qty=0",$c); mysql_query("UPDATE users SET energy=energy+{$fr['energy']} WHERE userid=$userid"); mysql_query("UPDATE users SET energy=maxenergy WHERE energy > maxenergy"); print "You cram a {$r['itmname']} into your mouth. You feel a bit of energy coming back to you."; }
?>
Po prostu wszystkie Medical pozmienia³em na food i wszystkie hp na energy. To równiez dzia³a jezeli zamienie ten urywek z tamtym. Ale jezeli po³±cze ten drugi pod ten pierwszy w jedym kodzie nie dzia³a. Tak to wyglada po moim po³aczeniu:
<?php
/*
MCCodes Lite
itemuse.php Rev 1.0.0
Copyright (C) 2006 Dabomstew
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
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";
$is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid W
HERE u.userid=$userid",$c) or
die(mysql_error()); check_level();
$fm=money_formatter($ir['money']);
$lv=date('F j, Y, g:i a',$ir['laston']); $h->userdata($ir,$lv,$fm);
$h->menuarea();
$_GET['ID'] = abs((int
) $_GET['ID']); //Medical
if(!$_GET['ID'])
{
print "Invalid use of file"; }
else
{
$i=mysql_query("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_id={$_GET['ID']} AND iv.inv_userid=$userid",$c); {
}
else
{
if($r['itmtypename'] == 'Medical')
{
$f=mysql_query("SELECT * FROM medical WHERE item_id={$r['itmid']}",$c); mysql_query("UPDATE inventory SET inv_qty=inv_qty-1 WHERE inv_id={$_GET['ID']}",$c); mysql_query("DELETE FROM inventory WHERE inv_qty=0",$c); mysql_query("UPDATE users SET hp=hp+{$fr['hp']} WHERE userid=$userid"); mysql_query("UPDATE users SET hp=maxhp WHERE hp > maxhp"); print "You cram a {$r['itmname']} into your mouth. You feel a bit of energy coming back to you."; }
//Food
if(!$_GET['ID'])
{
print "Invalid use of file"; }
else
{
$i=mysql_query("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_id={$_GET['ID']} AND iv.inv_userid=$userid",$c); {
}
else
{
if($r['itmtypename'] == 'Food')
{
$f=mysql_query("SELECT * FROM food WHERE item_id={$r['itmid']}",$c); mysql_query("UPDATE inventory SET inv_qty=inv_qty-1 WHERE inv_id={$_GET['ID']}",$c); mysql_query("DELETE FROM inventory WHERE inv_qty=0",$c); mysql_query("UPDATE users SET energy=energy+{$fr['energy']} WHERE userid=$userid"); mysql_query("UPDATE users SET energy=maxenergy WHERE energy > maxenergy"); print "You cram a {$r['itmname']} into your mouth. You feel a bit of energy coming back to you."; }
else
{
print "You cannot use this item."; }
}
}
$h->endpage();
?>
Wyskakuje cos tam z unexpected $end. Moze mi ktos pomóc to dobrze po³±czyc?