Nov 24, 2009

Attack Script In Php - This is a funny attack script that i made

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > How-To's and Tutorials > Programming > PHP

Attack Script In Php - This is a funny attack script that i made

Feelay
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 wink.gif This is my second tutorial here, and I will try to make it better than my first one smile.gif

Here is the SQL File.

CODE
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:

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 smile.gif

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

CODE
$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:
CODE
function attack(){


Then, we should create some important variables.
CODE
$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.


CODE
$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.


CODE
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.

CODE
} 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.


CODE
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 wink.gif



CODE
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 smile.gif

//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.

 

 

 


Comment/Reply (w/o sign-up)

FirefoxRocks
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.

Comment/Reply (w/o sign-up)

Miles
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.

Comment/Reply (w/o sign-up)

Feelay
Heh =)
It was a long time I made this script wink.gif
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

Comment/Reply (w/o sign-up)

mafialeg
I edit it to money wink.gif
Thaks alot biggrin.gif

Comment/Reply (w/o sign-up)

richard_site
It needs explain more the objetive of the game.

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : attack, script, php, funny, attack, script, made

  1. Creating A Php Login Script
    A thorough look at the process behind it (3)
  2. A Simple Register Script
    This Is a Very Simple Register-Script (3)
    Some time ago, i made a login-script. But how do you use a login-script, if you can't register.
    So this morning, I decided to make a register-script.. What you should already know: The php
    basics and a little more. How to use php and mysql together. The HTML basics (to make the forms).
    The first thing we should do, is creating the database tables. Here is the code: CODE CREATE
    TABLE `user` (   `id` int(4) unsigned NOT NULL auto_increment,   `username` varchar(32) NOT NULL,
      `password` varchar(32) NOT NULL,   `level` int(4) default '1',   PRIMARY K....
  3. Very Simple Login-script
    This is a very simple and secure login-script (18)
    Hi. This is my first post here. please Tell me if i do something wrong. This is a very simple and
    secure login script. I will try to add as many comments as possible, to make it easier to
    understand. Lets start with the database. Just make a new SQL file, and call it whatever you want.
    Paste this code: CODE CREATE TABLE `user` (   `id` int(4) unsigned NOT NULL auto_increment,
      `username` varchar(32) NOT NULL,   `password` varchar(32) NOT NULL,   `level` int(4) default
    '1',   PRIMARY KEY  (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=latin1; ....
  4. Simple User Validation Script
    (7)
    This tutorial will show you how to create a simple user validation script with PHP. We will need
    two files: "protect.php" and "login.php". The protect file is not meant to be viewed by itself. In
    order to protect a page, you need to include that file by using PHP code like the following: CODE
    include("protect.php"); Keep in mind that this needs to be in between your tags. This bit of
    code uses the include function. It is a handy function that reads all the information contained in
    one file and temporarily adds it to another. For example, this can be used to cr....
  5. PHP Tutorial: Form Verification And Simple Validation
    A One Page script for PHP form verification. (12)
    Having used various means of verifying HTML forms I believe that this method of verifying a form
    to be the best mostly because it does everything on one page. It presents the form on one page and
    then when the submit button is pressed, if all the required fields are not filled out then it will
    present the form again with all the fields intact and in red lettering will point out the fields
    that are required to be filled out in red. It is not possible to click submit using this method even
    if the user has turned JavaScript off. While it is possible to use javascript to ....
  6. PHP Tutorial: Menu Or Sidebar Script For CMS101
    and other applications as well (6)
    A Php Menu-builder Tutorial This Sidebar Menu-builder code and the php scripts are adapted from
    a Tutorial on the Astahost.com Forum titled : CMS101 - Content Management System Design .
    Since the original tutorial's author (vujsa) did such a marvellous job of describing the system
    in the original Topic posting, I will not attempt to explain it here, rather, I invite you to have a
    look at his Topic and learn from it. The Basic tutorial provided coding for developing a table-based
    web-site template which used php includes and embedded data to create a &....
  7. PHP: Writing A Generic Login And Register Script
    (15)
    Now there are basically 3 functions that a user management system provides: login, register, and
    protection. A user management system can do more than this but that is all that this tutorial will
    be covering. I will try to explain what I am doing as I go along but to fully understand what is
    happening you should have a basic knowledge of PHP, SQL, and HTML. This tutorial assumes you are
    using MySQL, adjust accordingly for a different DBMS. First off lets define the database table
    where our users will be stored. Using phpMyAdmin run this statement to create our table....

    1. Looking for attack, script, php, funny, attack, script, made

See Also,

*SIMILAR VIDEOS*
Searching Video's for attack, script, php, funny, attack, script, made
advertisement



Attack Script In Php - This is a funny attack script that i made

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com