deletion of creatures

Location of the Videos
Post Reply
greasontim
Posts: 73
Joined: Tue Feb 15, 2011 3:14 pm

deletion of creatures

Post by greasontim »

okay I have a small issue.
when I defeat a monster is deletes from my creature table.
How do I stop this?
(sorta annoying that I have to keep making new monsters)
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: deletion of creatures

Post by PaxBritannia »

For a temporary solution, try making a script that will create several of them for you when you run the script.

There are better ways to do it, but they are a bit more advanced and involve editing the mysql database. :)

pax.
greasontim
Posts: 73
Joined: Tue Feb 15, 2011 3:14 pm

Re: deletion of creatures

Post by greasontim »

1 thing though
I don't understand mysql well

my learning style is taking something and editing it to see what it does
so making a script is sorta out of the question

nevermind
set it up on logon to create 20+ monsters (same type but I'll change that)
that will do for now
n04h
Posts: 151
Joined: Thu Feb 10, 2011 4:48 am

Re: deletion of creatures

Post by n04h »

You could just keep adding creatures into your Database the way you did when halls showed you.
Image
greasontim
Posts: 73
Joined: Tue Feb 15, 2011 3:14 pm

Re: deletion of creatures

Post by greasontim »

only at video 8 right now
and adding them in by hand takes to long
Huezzer
Posts: 72
Joined: Mon Jan 31, 2011 7:47 pm

Re: deletion of creatures

Post by Huezzer »

I've added a new field called ''amount'' ('smallint(5)) in my database don't know if it works, A person told me that it should work, but I don't know 'cause my Battle.php or something don't work as it should do., It says error on arenainfo Line 94 and 95, ^^

Huezzer
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: deletion of creatures

Post by Callan S. »

I made a tute for just this issue, awhile ago -

Modular tute: Basic, repeatable monsters
Fight Cycle : My latest Browser game WIP
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
greasontim
Posts: 73
Joined: Tue Feb 15, 2011 3:14 pm

Re: deletion of creatures

Post by greasontim »

Code: Select all

            $SQL = "INSERT into creatures(name, level, exper, attack, defense, hpoints) VALUES('$creatureinfo3['name']','$creatureinfo3['level']','$creatureinfo3['exper']','$creatureinfo3['attack']',$creatureinfo3['defense']','$creatureinfo3['hpoints']')";
            mysql_query($SQL) or die("could not register");
If I put that in after the creature killed part of the attack.php
it should add a monster of the same ID and stats in the database shouldn't it?
Full code

Code: Select all

    <?php
    include_once 'connect.php';
      session_start();
      ///new for video 8/////////////
    include_once 'logo.php';
    ?>
     
      <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;
    }




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

    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
    {
      echo "<a href='battle.php'>No Creature selected. Go Back!";
      exit;
    }

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

    $creature = $creatureinfo3['name'];
    $creatureid = $creatureinfo3['id'];
    $creaturelvl = $creatureinfo3['level'];
    $creatureexp = $creatureinfo3['exper'];
    $creaturehp = $creatureinfo3['hpoints'];
    $creatureattack = $creatureinfo3['attack'];
    $creaturedefense = $creatureinfo3['defense'];

    ?>
    </div>
    <div id="player">
    <?php
    ///////////////////////players turn////////////////////

    echo "<u> " . $playerinfo3['name'] . "'s Attack</u><br>";
    $playerattack = rand(1,20) + $playerattack;
    $creaturedefense = rand(1,20) + $creaturedefense;

    echo $playerinfo3['name'] . "'s Attack roll is " . $playerattack . "<br>";
    echo $creature . "'s defense roll is " . $creaturedefense. "<br>";

    if ($playerattack  > $creaturedefense)
    {
      echo $playerinfo3['name'] . " hits! <br>";
      $playerdamage = rand(1,6);
       $newcreaturehp = $creaturehp - $playerdamage;
      echo "For " . $playerdamage . " points of damage. <br>";
       if ($newcreaturehp < 1)
       {
         echo "The " . $creature . " has been killed";

            $SQL = "INSERT into creatures(name, level, exper, attack, defense, hpoints) VALUES('$creatureinfo3['name']','$creatureinfo3['level']','$creatureinfo3['exper']','$creatureinfo3['attack']',$creatureinfo3['defense']','$creatureinfo3['hpoints']')";
            mysql_query($SQL) or die("could not register");
            $updatecreature="DELETE from creatures where name='$creature' limit 1";
            mysql_query($updatecreature) or die("Could not update creature");

           if ($playerinfo3['level'] > $creatureinfo3['level'])
            {
             $firstmod = $playerinfo3['level'] - $creatureinfo3['level'];
             $secondmod = $firstmod * 10 ;
             if ($secondmod > 90){$secondmod = 90;}
             $thirdmod = ($secondmod / 100) * $creatureinfo3['exper'];
             $totalexper =$creatureinfo3['exper'] - $thirdmod;
            }
            else
            {
             $firstmod = $creatureinfo3['level'] - $playerinfo3['level'];
             $secondmod = $firstmod * 10 ;
             if ($secondmod > 90){$secondmod = 90;}
             $thirdmod = ($secondmod / 100) * $creatureinfo3['exper'];
             $totalexper =$creatureinfo3['exper'] + $thirdmod;
            }
              $totalexper = (int)$totalexper;

               echo "<br><b><big>You gain " . $totalexper . " experience.</b></big><br>";
          $updateplayer="update players set exper=exper+'$totalexper' where name='$player'";
      mysql_query($updateplayer) or die("Could not update player");



          echo "<a href='battle.php'>Go Back";
          exit;
       }

      $updatecreature="update creatures set hpoints='$newcreaturehp' where name='$creature' limit 1";
      mysql_query($updatecreature) or die("Could not update creature");
    }
    else
    {
       echo $playerinfo3['name'] . " misses!<br>";
    }
    ?>
    </div>
    <div id="creature">
    <?php
    //////////////////////creatures turn //////////////////

    echo "<u> " . $creature . "'s Attack</u><br>";
    $creatureattack = rand(1,20) + $creatureattack;
    $playerdefense = rand(1,20) + $playerdefense;

    echo $creature . "'s Attack roll is " . $creatureattack . "<br>";
    echo $playerinfo3['name'] . "'s defense roll is " . $playerdefense . "<br>";

    if ($creatureattack  > $playerdefense)
    {
      echo $creature . " hits! <br>";
      $creaturedamage = rand(1,6);
       $newplayerhp = $playerhp - $creaturedamage;
       echo "For " . $creaturedamage . " points of damage. <br>";
       if ($newplayerhp < 1)
       {
         echo $playerinfo3['name'] . " has been killed<br>";
          echo "<a href='gameover.php>Continue'";
          exit;
       }
      $updateplayer="update players set hpoints='$newplayerhp' where name='$player'";
      mysql_query($updateplayer) or die("Could not update player");
    }
    else
    {
      echo $creature . " misses!";
    }
    echo "<br><br><a href='battle.php?creature=$creature'>Battle Again!";
    ?>
    </div>
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: deletion of creatures

Post by Callan S. »

I'll pull a jackolantern and say that would be quite inefficient. Delete the data only to put it back again a second latter?

The fact is at this stage in the tute it's using a $_GET to pass on the monster. Your going to have to modify that anyway unless you like your players simply deciding which monster they fight and for how long.

If you want a short term, ugly fix though (I know, I've been there, where I just want something that works now)

Code: Select all

$SQL = "INSERT into creatures(name, level, exper, attack, defense, hpoints) VALUES('$creatureinfo3['name']','$creatureinfo3['level']','$creatureinfo3['exper']','$creatureinfo3['attack']',$creatureinfo3['defense']','$creatureinfo3['hpoints']')";
            mysql_query($SQL) or die("could not register");
            $updatecreature="DELETE from creatures where name='$creature' limit 1";
            mysql_query($updatecreature) or die("Could not update creature");
Put the creature insert after the delete, not before it. Otherwise I'm guessing it'll just delete both.

Code: Select all

            $updatecreature="DELETE from creatures where name='$creature' limit 1";
            mysql_query($updatecreature) or die("Could not update creature");

$SQL = "INSERT into creatures(name, level, exper, attack, defense, hpoints) VALUES('$creatureinfo3['name']','$creatureinfo3['level']','$creatureinfo3['exper']','$creatureinfo3['attack']',$creatureinfo3['defense']','$creatureinfo3['hpoints']')";
            mysql_query($SQL) or die("could not register");
Fight Cycle : My latest Browser game WIP
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
greasontim
Posts: 73
Joined: Tue Feb 15, 2011 3:14 pm

Re: deletion of creatures

Post by greasontim »

changed a thing or two
now when creature dies and doesn't delete it updates its hp back to the number I have set as its max hp in the creature table
so now when goblin is killed its HP is set back to 8

Also another quick question
For leveling do I have to make a table for the class's stat growth or is it for EXP required?
Cause if EXP required is done through the attack.php than great cause I have a formula ready to try out at some point

start + (lvl * 50) + constant increase = exp required
50 + (level * 50) + (level * 100 - 100) = EXP required
So exp required would start at 100 and increase by 150 each level
I'll also be reducing player EXP to 0 each time they level so its not oh gain 150 gain a level every time.
Post Reply

Return to “Older Browser MMO Videos”