Page 2 of 12

Re: Video#7

Posted: Tue Jun 30, 2009 1:39 pm
by hallsofvallhalla
nice work mrmajic!


What is causing your problem is $newhp variable. Somewhere something is wrong. Can you post your battle.php?

Re: Video#7

Posted: Tue Jun 30, 2009 2:08 pm
by mrmajic
If i was making a video series, i think id get jack of people asking me when the next video was coming .. but .. how long till ya next vid hall??


:D

Rob

Re: Video#7

Posted: Tue Jun 30, 2009 2:26 pm
by hallsofvallhalla
haha well i am having to fit them in my schedule here and there. Seems to be one of the busiest times for me right now but I think I can get one in tonight or tomorrow night maybe.

Re: Video#7

Posted: Tue Jun 30, 2009 5:00 pm
by Bones
mrmajic wrote:just to confirm, you are talking about the players hitpoints .. right?
yes, though I changed that to health... I'll probably change it back to hpoints just to make things easier...

Code: Select all

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

if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
  echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
  exit;
}
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);

$playerhp = $playerinfo3['health'];
$playerattack = $playerinfo3['attack'];
$playerdefense = $playerinfo3['defense'];

////////////////new for video 7///////////////
if (isset($_GET['randid']))
{
   $randid=$_GET['randid'];
   $iteminfo="SELECT * from inventory where randid='$randid'";
$iteminfo2=mysql_query($iteminfo) or die("could not get item stats!");
$iteminfo3=mysql_fetch_array($iteminfo2);

if (!$iteminfo3['name'])
{
}
else
{

$name = $iteminfo3['name'];
$stats = $iteminfo3['stats'];
$statadd = $iteminfo3['statadd'];
$type = $iteminfo3['type'];

if ($type == "healing")
{
   $newhp = $statadd + $playerhp;
   if ($newhp > $playerinfo3['maxhp'])
   {
    $newhp = $playerinfo3['maxhp'];
   }
    $updateplayer="update players set health='$newhp' where name='$player'";
  mysql_query($updateplayer) or die("Could not update player");

    $updateitem="DELETE from inventory where name='$name' AND randid='$randid' limit 1";
  mysql_query($updateitem) or die("Could not delete item");

   $playerhp = $newhp;
 
  echo "Used " . $name . " and recovered " . $statadd . ".<br>";
}

}}
////////////////////////////////



if (isset($_GET['creature']))
{
   $creature=$_GET['creature'];
   $creatureinfo="SELECT * from creatures where name = '$creature'";
$creatureinfo2=mysql_query($creatureinfo) or die("could not get the creature you were fighting!");
$creatureinfo3=mysql_fetch_array($creatureinfo2);

}
else
{
  $creatureinfo="SELECT * from creatures order by rand() limit 1";
$creatureinfo2=mysql_query($creatureinfo) or die("could get a creature!");
$creatureinfo3=mysql_fetch_array($creatureinfo2);
}

$creature = $creatureinfo3['name'];
$creaturehp = $creatureinfo3['health'];
$creatureattack = $creatureinfo3['attack'];
$creaturedefense = $creatureinfo3['defense'];

/////player info
echo "<u> " . $playerinfo3['name'] . "</u><br>";
echo "Health = " . $playerhp . "<br>";
echo "Attack = " . $playerattack . "<br>";
echo "Defense = " . $playerdefense . "<br><br><br>";




///////creature info
echo "<u> " . $creatureinfo3['name'] . "</u><br>";
echo "Halth = " . $creaturehp . "<br>";
echo "Attack = " . $creatureattack . "<br>";
echo "Defense = " . $creaturedefense . "<br><br><br>";

echo "<a href='attack.php?creature=$creature'>Attack!";

///////////////////new for tutorial 7/////////////////////
echo "<br><a href='useitem.php?creature=$creature'>Use Item";
echo "<br><a href='store.php?creature=$creature'>Go to Store";
echo "<br><br><a href='create_creatures.php'>Release Creatures";

?>

Code: Select all

if ($type == "healing")
{
   $newhp = $statadd + $playerhp;
   if ($newhp > $playerinfo3['maxhp'])
   {
    $newhp = $playerinfo3['maxhp'];
   }
    $updateplayer="update players set health='$newhp' where name='$player'";
  mysql_query($updateplayer) or die("Could not update player");

    $updateitem="DELETE from inventory where name='$name' AND randid='$randid' limit 1";
  mysql_query($updateitem) or die("Could not delete item");

   $playerhp = $newhp;

Re: Video#7

Posted: Fri Jul 03, 2009 10:31 am
by mrmajic
hi,

i tried the script online, and i had one of my friends test out the scripts. . i saw that when he was playing the game, he could run the _add_items_to_shop.php script, so i made it so he couldnt run it if he was in the game ... something like this:

<?php
session_start();
if (isset($_SESSION['player'])) {

echo "You are not authorised to view this page!";
exit;
}
else
{
require_once 'connect.php';
$SQL = "INSERT into store(name, stats, statadd, price, amount, randid, type) VALUES ('Weak healing potion','hpoints','15','12','5','1','healing')";
mysql_query($SQL) or die("could not insert items");
$SQL = "INSERT into store(name, stats, statadd, price, amount, randid, type) VALUES ('Strong healing potion','hpoints','15','18','10','2','healing')";
mysql_query($SQL) or die("could not insert items");
$SQL = "INSERT into store(name, stats, statadd, price, amount, randid, type) VALUES ('Majic healing potion','hpoints','15','30','20','3','healing')";
mysql_query($SQL) or die("could not insert items");
echo "The following items were restocked into the shop: Weak healing potion, Strong healing potion, Majic healing potion";
}
?>


should this be ok??


Mr Majic...

Re: Video#7

Posted: Fri Jul 03, 2009 10:38 am
by mrmajic
ialso made a logout.php file:

<?php
session_start();
session_destroy();
echo "You are now logged out!";
exit(); ?>

so he just ran than to destory the session, then restocked the the shop then logged back in .. i think that i might have to make it so you can only log in x amounts of times a day .. :) that'll stuff him up :)

Re: Video#7

Posted: Fri Jul 03, 2009 2:29 pm
by hallsofvallhalla
i would go beyond that and make a new field in the players table named admin...if admin then it equals 1

then in that script have it query the players but not select all, only select admin

$selectplayers = select admin from players where player = $player....ect...

then make a if statement

if $selectplayers[admin] = 1
{
run add item code
}
else
{
you are not an admin
}

Re: Video#7

Posted: Tue Jul 07, 2009 7:36 am
by fleaky
My randid never works i have to always for everything put in a manual id for everything evan the md5?? and i haven't done anything wrong.

Re: Video#7

Posted: Tue Jul 07, 2009 12:57 pm
by hallsofvallhalla
sounds like you have, I think it might be a database field type issue. Y9ou can export the database as a file and send it to me if you want, then zip up your project and I will take a look.

Re: Video#7

Posted: Thu Oct 15, 2009 9:47 pm
by adamrain
its beautiful i wise icould script like you.

btw when have you started learning it? 3years ago?