question abou attack

Location of the Videos
Post Reply
claymore88
Posts: 10
Joined: Tue Aug 16, 2011 8:27 pm

question abou attack

Post by claymore88 »

Im new. Went through the videos. Read user posts and came across thorians post about selecting monsters through a drop down menu. But after I made the code how do I fight the creatures submitted/selected it just shows the random monster in that location when I make a submit form to attack.php

I want to b able to select the creature and be able to fight that creature through submission
User avatar
62896dude
Posts: 516
Joined: Thu Jan 20, 2011 2:39 am

Re: question abou attack

Post by 62896dude »

You need to do something like this:

<form method = 'post' action = 'attack.php'>
<option>ghost</option>
<option>goblin</option>
<br />
<input type = 'submit' value = 'Submit!' name = 'creature'>

THEN, on attack.php (Assuming you want to select the creature in battle.php and then fight it in attack.php) get the creature like this:

$creature = $_POST['creature'];

And that should get you the creature that was selected.

Now don't copy and paste the first part with the form, because that was pretty much pseudo code, but it needs to be something like that

Then when defining $creatureinfo, instead of something like "SELECT * FROM creatures WHERE level = '$playerinfo3[level]'";

Do this: "SELECT * FROM creatures WHERE name = '$creature'"; //this will send the creature that was selected from the dropdown menu into the query, and it will select all of the information from that selected creature

Hoped this helped!
Languages: C++, C#, Javascript + Angular, PHP
Programs: Webstorm 2017, Notepad++, Photoshop
Current Project: HP Destiny
claymore88
Posts: 10
Joined: Tue Aug 16, 2011 8:27 pm

Re: question abou attack

Post by claymore88 »

I still get nothing. is there a similar open source script with this feature? I learn best by actually seeing it
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: question abou attack

Post by Jackolantern »

You forgot the <select> tag, #dude! (Ahh, just saw you meant it as psuedo code)

Code: Select all

<form action="process.php" method="post">
  <select id="monster" name="monster">
    <option value="sandbug">A Giant Sand Beetle</option>
    <option value="mummy">An Ancient Mummy</option>
  </select>
  <input type="submit" value="Submit" />
</form>
I also demonstrate how you can set "values" in each option tag. That way you can use multiple words, or give more description in each option's text, but you will be using the value to actually check what was chosen in the form's action script.
The indelible lord of tl;dr
claymore88
Posts: 10
Joined: Tue Aug 16, 2011 8:27 pm

Re: question abou attack

Post by claymore88 »

jack, I see what you mean. but if I list all the creatures with one command how do I give them a different name
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: question abou attack

Post by Jackolantern »

What do you mean list all the creatures in one command? That is not what I was suggesting.
The indelible lord of tl;dr
Tim
Posts: 37
Joined: Fri Jun 10, 2011 12:49 am

Re: question abou attack

Post by Tim »

Code: Select all

$creature = $_POST['creature'];
The $creature variable will carry the name of the creature, depending on what the user selects. User selects Goblin and hits submit, $creature = Goblin. User selects Orc and hits submit, $creature = Orc.

This is when you query the database to get all the info about the creature.

Code: Select all

$creature_info_1 = "SELECT * from creatures where name = '$creature'";
$creature_info_2 = mysql_query($creature_info_1) or die("System: Unable to retrieve creature information.");
$creature_info_3 = mysql_fetch_array($creature_info_2);
claymore88
Posts: 10
Joined: Tue Aug 16, 2011 8:27 pm

Re: question abou attack

Post by claymore88 »

thanks tim. jack I was referring to how you would give each option a different name if. my option displays all creatures with one line..
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: question abou attack

Post by Jackolantern »

Wait, you have all your creatures in one option tag?
The indelible lord of tl;dr
claymore88
Posts: 10
Joined: Tue Aug 16, 2011 8:27 pm

Re: question abou attack

Post by claymore88 »

maybe I could just make a new table and query what to display
Post Reply

Return to “Older Browser MMO Videos”