Jump to content



Welcome to AstaHost - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!

Toggle shoutbox Shoutbox Open the Shoutbox in a popup

@  agyat : (24 May 2013 - 05:15 PM) O Dear, Where Are You? Without Your Words This Sb Is ..
@  agyat : (23 May 2013 - 01:23 AM) Wow! Mr. Sb Back Home.
@  OpaQue : (23 May 2013 - 12:44 AM) Ting
@  OpaQue : (24 April 2013 - 02:44 PM) I guess, Time to run Mycent script.
@  OpaQue : (24 April 2013 - 02:43 PM) wow.. not much spam. except habatt posting lot of links.. :P
@  yordan : (23 April 2013 - 01:04 PM) You're welcome, agyat. Nice to have been helpful. Second lesson: try full words, "you" instead of "EW".
@  agyat : (23 April 2013 - 05:03 AM) @YORDAN: tHANK EW FOR YOUR FIRST LESSON.   :D
@  yordan : (22 April 2013 - 09:43 PM) @agyat : "why don't you help me", or "please help me", or "please teach us"
@  yordan : (22 April 2013 - 09:42 PM) welcome back, velma
@  velma : (22 April 2013 - 07:51 AM) **yawns** Good to be back, wonder what is going on here :)
@  agyat : (22 April 2013 - 03:50 AM) Oh! so, why don't help me learn english..
@  yordan : (21 April 2013 - 08:38 PM) The goal mentioned by shiu : "learning english, learning computer"
@  agyat : (21 April 2013 - 06:31 PM) WHAT GOAL?
@  yordan : (20 April 2013 - 10:39 AM) yes, that's our goal. simultaneouly learning English and teaching/learning computer using.
@  shiyu : (20 April 2013 - 07:30 AM) learning english,learning computer
@  yordan : (19 April 2013 - 01:11 PM) Oh, I see, it's just a trick in order to force people looking at your texte. Somehow smart, maybe.
@  agyat : (19 April 2013 - 02:54 AM) And of course I know it is not SEO friendly.
@  agyat : (19 April 2013 - 02:52 AM) There may be two possible answers for that ....


1) Shout was posted using mobile keypad.

2) To force people read content carefully and/or with more concentration.
@  agyat : (19 April 2013 - 02:49 AM) There may be two possible answers for that ....
@  yordan : (18 April 2013 - 09:35 PM) however, why this mixing of capital letters in the middle of your text?

Replying to Attack Script In Php


Post Options

    • Can't make it out? Click here to generate a new image

  or Cancel


Topic Summary

richard_site

Posted 05 June 2008 - 04:55 PM

It needs explain more the objetive of the game.

mafialeg

Posted 24 May 2008 - 06:44 PM

I edit it to money :P
Thaks alot :(

Feelay

Posted 25 March 2008 - 06:23 PM

Heh =)
It was a long time I made this script :)
Now I don't reset the HP to 100. Instead, I make it unable to reach under 10, and use healing potions to heal.

And yeh =) I made it basic, because when I was a very newbie, I couldn't find these kind of tutorials. So I had very much trouble to learn these stuff =)

Thanks for the replies =) //Feelay

Miles

Posted 25 March 2008 - 11:56 AM

Good tutorial, a little basic, but should be helpful to any newbies to php. Also, as FireFoxRocks says, I wouldn't reset the HP count back to 100.

FirefoxRocks

Posted 25 March 2008 - 01:16 AM

This is an interesting script, however, in my opinion (or game if I'm designing one), I wouldn't reset the HP back to 100.
I think I might use this if I continue on with a game that I hope I'm motivated enough to create, lol.

Feelay

Posted 18 January 2008 - 08:28 PM

Hey!

I am going to share an attack script that i made for some time ago.
I made it, as a test for my game.. And ofc, you can use it for your game to. It is still version 1.0.
But I want you to learn something from it :P This is my second tutorial here, and I will try to make it better than my first one ^_^

Here is the SQL File.

CREATE TABLE `characterss` (
  `health` int(200) NOT NULL default '100',
  `id` int(10) NOT NULL auto_increment,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

insert  into `characterss`(`health`,`id`) values (100,2);



The second thing we should do, is creating a new php file, and call it "attack.php"

In the beginning of the file, we will add this code:

<html>
<head>
<body>
<form action="Attack.php" method="post">
<input type="submit" value="Attack">
<br><br><br>

This is just a simple html form, that shows the attack button.
It will send the form to the attack.php file (to itself).


Now lets beginn with the php code ;)

The first thing we should do, is: Create a connection to the database server, and chose a database.

$db = mysql_connect(localhost, mysql_username, mysql_password); 
mysql_select_db('database_name',$db)or die("Couldn't find the database");

If the database was not found, the code will write an error.

Now lets create the Attack Function.

As always, a function start like this:
function attack(){

Then, we should create some important variables.
$dbQuery = mysql_query("SELECT health FROM characterss WHERE id = 2 LIMIT 1");  
$currentHealth = mysql_result($dbQuery, 0);

The first thing we do, is: Create a Query, that selects the health colum from the characterss table.
Then we give $currenthealth a value.


$maxHealth = 100; 
		$healthAward = mt_rand (1, 30);   
		$winner= mt_rand (0, 1);

This is very clear, isn't it =?
We give $maxHealth a value.
We give $healthAward a value (the health the player wins/loses). the mt_rand function will randomize the health the player will get.
And we will also give the $winner chance a value.. it is 50% chance that the player wins, and 50% chance that the playe will lose.


if($winner) {
if(($currentHealth + $healthAward) <= $maxHealth) {   
				$currentHealth += $healthAward; 
				echo "You won! You've gained {$healthAward} HP. You now have {$currentHealth} HP.";  
			} else { 
				echo "You won! Your health  is at the maximum, {$maxHealth} HP."; 
				$currentHealth = $maxHealth;

If the player wins: Check if the player got full hp. If he don't have full hp, give him the healthAward, else, the code will write that he won, but the hp will not change.

} else { 
			if(($currentHealth - $healthAward) <= 0) { 
				echo "You died. Your HP is 100 again."; 
				$currentHealth = 100; 
			} else { 
				$currentHealth -= $healthAward; 
				echo "You lost! You've lost {$healthAward} HP. You now have {$currentHealth} HP."; 
			}  
		}

Else if the players hp is less than 0, the code will write that the player died, and reset the hp to 100.
if the player lost, but didn't die, the code will remove the hp that the player lost, and write that he lost, and show his remaining hp.


mysql_query ("UPDATE characterss SET health = \"{$currentHealth}\" WHERE id = 2");  
	}

And ofc, we must update the value in the database.. Else, it won't be fun ;)



echo attack();

mysql_close($db); 
?>

Then we echo the function, and close the mysql_connection.

Tell me if you find any errors, or if u want me to change something. And I also want to know if you liked this tutorial ;)

//Feelay


You are not allowed to copy anything from this tutorial, and paste it outside of this topic, without my permission.
But you are allowed to copy/paste parts of it, inside this topic.

Review the complete topic (launches new window)