Video 27 [SOLVED]

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
Cdaman
Posts: 15
Joined: Tue Dec 06, 2011 2:08 am

Video 27 [SOLVED]

Post by Cdaman »

I have tryed following Video27 to make quests. it refuses to complete the quests. here is my code:

Code: Select all

<?php

include_once 'connect.php';
session_start();

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style.css" rel="stylesheet" type="text/css" />
<title>MMO Tutorial</title>
</head>

<?php

if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
  $playerinfo="SELECT * from gamers where playername='$player'";
  $playerinfo2=mysql_query($playerinfo) or die(mysql_error());
  $playerinfo3=mysql_fetch_array($playerinfo2);
}
else
{
  print "Sorry, you are not logged in, please <A href='login.php'>Login</a><br>";
  exit;
}

$bypass = 0;
$newquest = 0;

if(isset($_POST['giver']))
{
  $qname = $_POST['name'];

  $bypass = 1;
  $house = "SELECT * from playerquests where pname='$playerinfo3[playername]' AND name='$qname' order by level DESC Limit 1";
  $house2 = mysql_query($house) or die(mysql_error());
  $house3 = mysql_fetch_array($house2);
  
  if (!isset($house3['name']))
  {
    $house3['level'] = 1;
    $newquest = 1;
  }
  
  $selectquest="SELECT * from questgivers where name='$qname' AND level='$house3[level]'";
  $selectquest2=mysql_query($selectquest) or die(mysql_error());
  $selectquest3=mysql_fetch_array($selectquest2);
  if (!isset($selectquest3['name']))
  {
    echo "There are no available quests at this time.<br><br>";
  }
  else
  {
  echo "<b><u>". $selectquest3['name'] . "</b></u><br><br>";
  echo $selectquest3['givequest'] . "<br><br>";

  echo "
       <form method='POST' action='quests.php'>
       <input type='submit' value='Accept' name='addw1' />
       <input type='hidden' name='name' value='$selectquest3[name]' />
       <input type='hidden' name='description' value='$selectquest3[description]' />
       <input type='hidden' name='preitem' value='$selectquest3[preitem]' />
       <input type='hidden' name='preitemtype' value='$selectquest3[preitemtype]' />
       <input type='hidden' name='accept' value='1'>
       </form><br><br>";
  if ($newquest != 1)
  {
    echo "
    <form method='POST' action='quests.php'>
    <input type='submit' value='Complete Quest' name='addw' />
    <input type='hidden' name='name' value='$selectquest3[name]' />
    <input type='hidden' name='level' value='1'>
    <input type='hidden' name='qcompleted' value='1'>
    
    </form><br><br";
  }
  else
  {
    echo "
    <form method='POST' action='quests.php'>
    <input type='submit' value='Complete Quest' name='addw' />
    <input type='hidden' name='name' value='$selectquest3[name]' />
    <input type='hidden' name='level' value='$house3[level]'>
    <input type='hidden' name='qcompleted' value='1'>
    </form><br><br";

    echo "
        <form method='POST' action='index.php'>
        <input type='submit' value='Leave' name='addw' />
        </form><br><br>";
  }}
  }

  if (isset($_POST['qcompleted']))
  {
     $qname = $_POST['name'];
     $qlevel = $_POST['level'];
     $bypass = 1;
     
     $selectquest="SELECT * from questgivers where  name='$qname' AND level='$qlevel'";
     $selectquest2=mysql_query($selectquest) or die(mysql_error());
     $selectquest3=mysql_fetch_array($selectquest2);

  if($selectquest3['reqitemtype'] == 'item')
  {
    $itemcount = 0;
    $iteminfo="SELECT * from inventory where name='$selectquest3[reqitem]' AND pname='$playerinfo3[playername]'";
    $iteminfo2=mysql_query($iteminfo) or die(mysql_error());
    while ($iteminfo3=mysql_fetch_array($iteminfo2))
    {
      $itemcount= $itemcount + 1;
    }
    if($itemcount < $selectquest3['reqamount'])
    {echo "You do not have enough " . $selectquest3['reqitem'] . " to complete this quest. ";}
    else
    {
      $iamount = $selectquest3['reqamount'];
      for($i = 0; $i < $iamount; $i=$i+1)
      {
        $updateinv="DELETE FROM inventory where pname='$playerinfo3[playername]' AND name='$selectquest3[reqitem]' limit 1";
        mysql_query($updateinv) or die(mysql_error());
      }

      echo $selectquest3['reqamount'] . " " . $selectquest3['reqitem'] . " removed from inventory<br><br>";
      echo $selectquest3['finishquest'] . "<Br><br>";

      $updatecurquests="DELETE FROM currentquests where pname='$playerinfo3[playername]' AND name='$qname' limit 1";
      mysql_query($updatecurquests) or die(mysql_error()); 

      if (isset($_POST['newquest']))
      {$SQL="INSERT into playerquests(pname,name,level) VALUES ('$playerinfo3[playername]','$qname','2')";
       mysql_query($SQL) or die(mysql_error());}
      else
      { $updatepquests="Update playerquests SET level=level+1 WHERE name='$playerinfo3[playername] AND name='$qname'";
        mysql_query($updatepquests) or die(mysql_error());
      }
      $updateplay="Update gamers SET credits=credits+'$selectquest3[copper]',exper=exper+'$selectquest3[exper]' WHERE playername='$playerinfo3[playername]'";
      mysql_query($updateplay) or die(mysql_error());
      echo "<br><br>Recieved " .$selectquest3['exper'] . " experience and " . $selectquest3['copper'] . " credits.";
      //////////////////if item is given//////////////////////////////////
     if($selectquest3['item'] != 'none')
        {
          $iteminfo="SELECT * from items where name='$selectquest3[item]'";
          $iteminfo2=mysql_query($iteminfo) or die(mysql_error());
          $iteminfo3=mysql_fetch_array($iteminfo2);
          $SQL="INSERT into inventory(pname,name,type,stats,statadd,price) VALUES ('$playerinfo3[pname]','$iteminfo3[name]','$iteminfo3[type]','$iteminfo3[stats]','$iteminfo3[statadd]','$iteminfo3[price]')";
          mysql_query($SQL) or die(mysql_error());
          echo $selectquest3['item'] . " added to your backpack.<br>";
        }

       echo "<br><form method='POST' action='quests.php'>
             <input type='submit' value='Finish' name='addw' />
             </form><br><br>";
    }
  }
}
  
  if (isset($_POST['accept']))
  {
    $qname = $_POST['name'];
    $preitemtype = $_POST['preitemtype'];
    $descript = $_POST['description'];
    $bypass = 1;
    
    $selectquest="SELECT * from currentquests where pname='$playerinfo3[playername]'";
    $selectquest2=mysql_query($selectquest) or die(mysql_error());
    $selectquest3=mysql_fetch_array($selectquest2);
    
    if (isset($selectquest3['name'])) {echo "You have already accepted this quest!<br><br>";}
    else
    {
      $SQL="INSERT into currentquests(pname,description,name) VALUES ('$playerinfo3[playername]','$descript','$qname')";
      mysql_query($SQL) or die(mysql_error());
      echo "Quest added to your quest log!.<br>";
      
      if ($preitemtype == 'item')
      {
        $iteminfo="SELECT * from item where name='$preitem'";
        $iteminfo2=mysql_query($iteminfo) or die(mysql_error());
        $iteminfo3=mysql_fetch_array($iteminfo2);
        $randid2 = rand(1000,999999999);
        $SQL="INSERT into inventory(id,name,type,stats,statadd,price) VALUES ('$playerinfo3[id]',
        '$iteminfo3[name]',$iteminfo3[type],'$iteminfo3[stats]','$iteminfo3[statadd]','$iteminfo3[price]')";
        mysql_query($SQL) or die(mysql_error());
        echo $iteminfo3['name'] . " has been added to your inventory.<br><br>";
      }
      echo "
       <form method='POST' action='index.php'>
        <input type='submit' value='Leave' name='addw1' />
       </form><br><br>";
    }
}
  if($bypass != 1)
  {
    $selectbackpack="SELECT * from questgivers where level=1";
    $selectbackpack2=mysql_query($selectbackpack) or die(mysql_error());
    while($selectbackpack3=mysql_fetch_array($selectbackpack2))
    {
      echo "
      <form method='POST' action='quests.php'>
      <input type='submit' value='$selectbackpack3[name]' name='addw' />
      <input type='hidden' name='name' value='$selectbackpack3[name]'>
      <input type='hidden' name='giver' value='1'>
      </form><br><br>";
      
      echo "
        <form method='POST' action='index.php'>
        <input type='submit' value='Leave' name='addw' />
        </form><br><br>";
    }
  }
  ?>
Last edited by Cdaman on Thu Dec 22, 2011 8:58 pm, edited 1 time in total.
Cdaman
Posts: 15
Joined: Tue Dec 06, 2011 2:08 am

Re: Video 27

Post by Cdaman »

I use Easyphp5.3.8 or somthing like that (can't rember the numbers exactly), it i sthe second latest version.
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Video 27

Post by hallsofvallhalla »

do you get an error or anything?
Cdaman
Posts: 15
Joined: Tue Dec 06, 2011 2:08 am

Re: Video 27

Post by Cdaman »

I have slightly fixed it. it now lets me finish the first quest, but will not finish the second.

I am basing my game off forsake sanctum.

I have changed the coding as well for easyphp5.8.3.1 so that is suggested to open this:
http://www.mediafire.com/?xmcbc0gzzezc6p7

It is easier to show you guys then to explain the problem (mainly becuase i don't know exactly what is causing it) :D
Cdaman
Posts: 15
Joined: Tue Dec 06, 2011 2:08 am

Re: Video 27

Post by Cdaman »

How do i make so that it is possible to have 2 or more quest lines?
This is the code for the main quest page:

Code: Select all

<?php
include_once 'connect.php';
session_start();
?>

<link href="style.css" rel="stylesheet" type="text/css" />
<div id="login2" div align="center">


<?php
if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
  echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
  exit;
}
?>
</div>

<?php
$bypass = 0;
$newquest = 0;

$playerinfo="SELECT * from gamers where playername='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);;

$qlevel="SELECT * from playerquests WHERE pname='$playerinfo3[playername]'";
$qlevel2=mysql_query($qlevel) or die(mysql_error() . " Line 34");
$qlevel3=mysql_fetch_array($qlevel2);

if (!$qlevel3['level'])
{
  $qlevel3['level'] = 1;
}

$questinfo="SELECT * from questgivers where level='$qlevel3[level]'";
$questinfo2=mysql_query($questinfo) or die(mysql_error() . " Line 38");
$questinfo3=mysql_fetch_array($questinfo2);

$questname = $questinfo3['name'];
$level = $playerinfo3['level'];

$house = "SELECT * from playerquests where pname='$playerinfo3[playername]' AND questgiver='$questinfo3[questgiver]' AND name='$questname' order by level DESC Limit 1";
$house2 = mysql_query($house) or die(mysql_error() . " Line 46");
$house3 = mysql_fetch_array($house2);

if (!isset($house3['name']))
{
   $house3['level'] = 1;
   $newquest = 1;
}

  $selectquest="SELECT * from questgivers where questgiver='$questinfo3[questgiver]' AND level='$questinfo3[level]'";
  $selectquest2=mysql_query($selectquest) or die(mysql_error() . " Line 57");
  $selectquest3=mysql_fetch_array($selectquest2);
  if (!isset($selectquest3['name']))
  {
    echo "There are no available quests at this time.<br><br>";
  }
  else
  {
      print "<center><h3>Quests</h3></center>";
            print "<center>";
            print "<table border='0' width='70%' cellspacing='20'>";
            print "<tr><td width='25%' valign='top'>";
            print "</td>";
            print "<td valign='top' width='75%'>";
            $selectquests="SELECT * from questgivers where level='$qlevel3[level]'";
            $selectquests2=mysql_query($selectquests) or die(mysql_error() . " Line 71");
            print "<table border='1' bordercolor='black' bgcolor='#ffffff' >";
            print "<tr><td>Name<font color='ffffff'>_________________</td><td>Experience<font color='ffffff'>_</td><td>Credits<font color='ffffff'>_</td><td>Quest Giver<font color='ffffff'>_</td></tr>";
            while($selectquests3=mysql_fetch_array($selectquests2))
            {
                print "<tr><td>$selectquests3[name]</td><td>$selectquests3[exper]</td><td>$selectquests3[credits]</td><td>$selectquests3[questgiver]</td><td><a href='questsaccepted.php?name=$questinfo3[name]'>Accept</a></td</tr>";
            }
            echo "</table>";
            echo "</td></tr>";
            echo "</table>";

            echo "<br><br><a href='index.php?$_POST($qlevel3[level])'>Home</a>";
  }
The code for the page when you accept a quest:

Code: Select all

<?php
include_once 'connect.php';
session_start();
?>

<link href="style.css" rel="stylesheet" type="text/css" />
<div id="login2" div align="center">


<?php
if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
  echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
  exit;
}
?>
</div>

<?php

$newquest = 0;
//$questgiver=$_GET['questgiver'];

//gets the playerinfo from the table gamers
$playerinfo="SELECT * from gamers where playername='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);

//gets the level of the quest the character is up to
$qlevel="SELECT level from playerquests WHERE pname='$playerinfo3[playername]'";
$qlevel2=mysql_query($qlevel) or die(mysql_error());
$qlevel3=mysql_fetch_array($qlevel2);

//if the player hasn't done any quests then the quest level is 1
if (!$qlevel3['level'])
{
  $qlevel3['level'] = 1;
}

//selects the needed information from the table questgivers, based on the what level the character is up to, and who the quest giver is
$questinfo="SELECT * from questgivers WHERE level='$qlevel3[level]'";
$questinfo2=mysql_query($questinfo) or die(mysql_error() .  " Line 45");
$questinfo3=mysql_fetch_array($questinfo2);

$questname = $questinfo3['name'];
$level = $playerinfo3['level'];
$preitemtype = $questinfo3['preitemtype'];
$descript = $questinfo3['description'];
$bypass = 1;

//if the name of the quest is already set then it says you have already accepted that quest
    if (isset($selectquest3['name'])) {echo "You have already accepted this quest!<br><br>";}
    else
    {
      //inserts the quest giver, player's name, quest description, the quest name, and the required item type into the 
      //current quests table
      $SQL="INSERT into currentquests(questgiver,pname,description,name,reqitemtype) VALUES ('$questinfo3[questgiver]','$playerinfo3[playername]','$descript','$questname','$questinfo3[reqitemtype]')";
      mysql_query($SQL) or die(mysql_error());
      echo "Quest added to your quest log!.<br>";

      //selects all from the current quests table where the playername is the player's name
      $selectquest="SELECT * from currentquests where pname='$playerinfo3[playername]'";
      $selectquest2=mysql_query($selectquest) or die(mysql_error() . " Line 62");
      $selectquest3=mysql_fetch_array($selectquest2);

    //if the type of item required is an item then
    if($questinfo3['reqitemtype'] == 'item')
  {
    //makes a variable called item count and sets it to 0
    $itemcount = 0;
    //selects everything in the inventory under the name of the item required for the quest, and the name of the player
    $iteminfo="SELECT * from inventory where name='$questinfo3[reqitem]' AND pname='$playerinfo3[playername]'";
    $iteminfo2=mysql_query($iteminfo) or die(mysql_error() . " Line 69");
    
    //while the variable $iteminfo3 has any items under the name of the required item
    //it increases what $itemcount equals
    while ($iteminfo3=mysql_fetch_array($iteminfo2))
    {
      $itemcount= $itemcount + 1;
    }
    
    //if the variable $itemcount has less in it then is required for the quest then
    if($itemcount < $questinfo3['reqamount'])
    {echo "You do not have enough " . $questinfo3['reqitem'] . "s to complete this quest. ";}
    //else if it has more than the required amount, or the the same as
    else
    {
      //it creates a variable with the required amount in it
      $iamount = $questinfo3['reqamount'];
      
      //this says that while the variable $i has less value then the variable $item amount
      //it deletes the required item out of the inventory and adds 1 to the variable $i.
      //when the two variables have the same value it stops deleting items from the inventory
      for($i = 0; $i < $iamount; $i=$i+1)
      {
        $updateinv="DELETE FROM inventory where pname='$playerinfo3[playername]' AND name='$questinfo3[reqitem]' limit 1";
        mysql_query($updateinv) or die(mysql_error()  . " Line 82");
      }

      //it prints out the required amount, and required item, then says that they have been removed from the inventory
      echo $questinfo3['reqamount'] . " " . $questinfo3['reqitem'] . "s removed from inventory<br><br>";
      //prints out the finishquest message that was set the the quest givers table
      echo $questinfo3['finishquest'] . "<Br><br>";

      //deletes the quest from current quests table
      $updatecurquests="DELETE FROM currentquests where pname='$playerinfo3[playername]' AND questgiver='$questinfo3[questgiver]' limit 1";
      mysql_query($updatecurquests) or die(mysql_error()  . " Line 89");

       //when the quest is finished it adds it to the player quests table so that the second level of that quest can be started
        $SQL="INSERT into playerquests(pname,name,level,questgiver) VALUES ('$playerinfo3[playername]','$questname','$qlevel3[level]','$questinfo3[questgiver]')";
        mysql_query($SQL) or die(mysql_error() . " Line 124");}

        $updatepquests="update playerquests set level=level+1 where questgiver='$questinfo3[questgiver]' AND level='$qlevel3[level]'";
        mysql_query($updatepquests) or die(mysql_error() . " Line 127");
      //gives the player the reward of credits and experience specified in the quest givers table
      $updateplay="Update gamers SET credits=credits+'$questinfo3[credits]',exper=exper+'$questinfo3[exper]' WHERE playername='$playerinfo3[playername]'";
      mysql_query($updateplay) or die(mysql_error()  . " Line 99");
      //prints out how much credits and experience the player recieved
      echo "<br><br>Recieved " .$questinfo3['exper'] . " experience and " . $questinfo3['credits'] . " credits.";

     //if an item is given as a reward
     if($questinfo3['item'] != 'none')
        {
          //selects all out of the item's table
          $iteminfo="SELECT * from items where name='$questinfo3[item]'";
          $iteminfo2=mysql_query($iteminfo) or die(mysql_error()  . " Line 105");
          $iteminfo3=mysql_fetch_array($iteminfo2);
          //then inserts it into the player's inventory
          $SQL="INSERT into inventory(pname,name,type,stats,statadd,price) VALUES ('$playerinfo3[playername]','$iteminfo3[name]','$iteminfo3[type]','$iteminfo3[stats]','$iteminfo3[statadd]','$iteminfo3[price]')";
          mysql_query($SQL) or die(mysql_error()  . " Line 108");
          echo $questinfo3['item'] . " added to your backpack.<br>";
        }

        //puts up a button that allows you to finish the quest
       echo "<br><form method='POST' action='quests2.php'>
             <input type='submit' value='Finish' name='addw' />
             </form><br><br>";
     }
   }
And a copy of my DB:

Code: Select all

-- phpMyAdmin SQL Dump
-- version 3.4.5
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Dec 21, 2011 at 03:00 AM
-- Server version: 5.5.16
-- PHP Version: 5.3.8

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `planetarywars`
--

-- --------------------------------------------------------

--
-- Table structure for table `questgivers`
--

CREATE TABLE IF NOT EXISTS `questgivers` (
  `level` smallint(3) NOT NULL,
  `name` varchar(60) NOT NULL,
  `description` text NOT NULL,
  `givequest` text NOT NULL,
  `finishquest` text NOT NULL,
  `reqitem` varchar(60) NOT NULL,
  `reqitemtype` varchar(30) NOT NULL,
  `credits` int(9) NOT NULL,
  `itemtype` varchar(30) NOT NULL,
  `item` varchar(60) NOT NULL,
  `exper` int(9) NOT NULL,
  `preitemtype` varchar(21) NOT NULL,
  `preitem` varchar(21) NOT NULL,
  `preamount` int(9) NOT NULL,
  `reqamount` int(9) NOT NULL,
  `pid` int(11) NOT NULL,
  `questgiver` varchar(60) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `questgivers`
--

INSERT INTO `questgivers` (`level`, `name`, `description`, `givequest`, `finishquest`, `reqitem`, `reqitemtype`, `credits`, `itemtype`, `item`, `exper`, `preitemtype`, `preitem`, `preamount`, `reqamount`, `pid`, `questgiver`) VALUES
(1, 'Pesky Pirates', 'I need 2 Pirate Power cores, they drop from bandit ships. please grab me some?', 'Please get me 2 Pirate Power cores?', 'Good Job!', 'Pirate power core', 'item', 1000, 'none', 'none', 100, 'none', 'none', 0, 2, 0, 'Jaenor the Awsome'),
(2, 'Hungery for Meat', 'Hey buddy, can you get me some rabbit meat?', 'Please get an ol''buddy some rabbit meat?', 'Thanks buddy!', 'rabbit meat', 'item', 50, 'none', 'none', 100, 'none', 'none', 0, 1, 0, 'Jaenor the Awsome'),
(1, 'Testing line 2', 'This is a test.', 'Get me 1 test item.', 'Good, now on to part 2', 'test item', 'item', 20, 'item', 'test item 2', 100, 'none', 'noone', 0, 1, 0, 'Test'),
(2, 'testing line 2 part 2', '...', 'get me 1 test item 2', 'good', 'test item 2', 'item', 20, 'none', 'none', 100, 'none', 'none', 0, 1, 0, 'Test');

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Cdaman
Posts: 15
Joined: Tue Dec 06, 2011 2:08 am

Re: Video 27

Post by Cdaman »

All it does is show both quests, but i click to accept one, and it says it is done, but it doesn't require anything. same goes for the second. I do not know why it does this.
Post Reply

Return to “Beginner Help and Support”