| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| The original NP Emo Kid | [PHP] making a battle script Well i have started making a battle script for use in my game but i am really stuck i have all the values ready to use but i'm not exactly sure how to make the you and them battle? PHP Code: |
| |
| | #2 (permalink) |
| NamePros Regular | here are some thoughts: Hit chance: $your['hitchance'] = $your_mecha['agility'] / ( $your['agility'] - $enemy_mecha['agility'] ) $enemy['hitchance']= $enemy_mecha['agility'] / ( $enemy['agility'] - $your_mecha['agility'] ) Combat damage: $your['maxdamage'] = $your_mecha['strength'] + $your_weapon['power'] - $enemy_mecha['armour'] $your['mindamage'] = $your_mecha['strength'] + $your_weapon['power'] - $enemy_mecha['armour'] + $enemy_armour['power'] ( the same for the enemy )
__________________ Joćo Fernandes Silva Selling : 19P.ORG - ARCADEHITS.ORG - AZIAN.NET - COREFANS.COM - CTUTORIALS.NET - DEDISEEK.COM - HITCHECK.COM - HOST15.COM - HOSTCUSTOMER.COM - LARGETIPS.COM - SCRIPTCANDY.COM - VISUALBOOK.NET - VOXVPS.COM / .NET - WALLPAPERSARENA.COM |
| |
| | #3 (permalink) |
| The original NP Emo Kid | Thanks for the input, here is what i have now, think all that is left is to actually do the battle, to which i am unsure about how to do? PHP Code: Last edited by liam_d; 03-06-2008 at 05:06 AM. |
| |
| | #5 (permalink) |
| Pro Coder & Designer | This is how i would do it : This is not tested- just written to give you a idea PHP Code:
__________________ Online Dragonball Game |
| |
| | #7 (permalink) |
| Pro Coder & Designer | basically - you can do like the above - you have to add certain health (which is i guess armour) to be deducted from the total amount untill one of them drops to zero might be handy if they can choose what attack - since i assume every attack has their own strength?
__________________ Online Dragonball Game |
| |
| | #8 (permalink) |
| New Member | I wrote this up in this post when i saw your post, so i definately didnt test it, but its a very good start to the direction your heading in Code: <?
session_start();
// lets tell the script that if the user is not logged in they cannot access
// the game, when the user is logging in, some variable should be
// set that they are logged in, a basic easy one is
// $_SESSION['loggedin']=1;
// and when they logout destroy the session, google is your friend.
if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
$userid=$_SESSION['userid']; //assuming you have sessions set
$id=$_GET['userid']; // assuming the url uses a GET function
$z=mysql_query("SELECT * FROM users WHERE userid='$userid'");
$x=mysql_fetch_array($z);
// Protect the admin, you.
if($_GET['userid'] == '1') {
print "You cannot attack the admin, i am all powerful"; die;
}
// Lets make sure they are not attacking themselves
if($_GET['userid'] == '$userid') {
print "You cannot attack yourself"; die;
}
if(isset($_GET['userid'])) {
$q=mysql_query("SELECT * FROM users WHERE userid='$id'");
$r=mysql_fetch_array($q);
// Set some variables
$offender=$x['name'];
$defender=$r['name'];
$offhealth=$x['health'];
$defhealth=$r['health'];
$offstat1=$x['stat1'];
$defstat1=$r['stat1'];
$offstat2=$x['stat2'];
$defstat2=$r['stat2'];
// Lets make sure the user isn't trying to kill a dead user
// Or trying to kill people even though they are dead
if($offhealth<1) {
print "You are dead, you cannot attack while dead, jerk."; die;
}
if($defhealth<1) {
print "This Player Is Dead"; die;
}
// Set a random factor so the most powerful is not always the winner
$offrand=rand(0,100);
$defrand=rand(0,100);
$rand=rand(100,999);
// Do some math
$offpower=($offstat1+$offstat2+$offrand);
$defpower=($defstat1+$defstat2+$defrand);
$offdamage=($defpower-$defrand/*3);
$defdamage=($offpower-$offrand/*3);
// This is where you let the user know what is going on
// Send them to a link
// attack.php?userid=$id&math=$rand
// Print the names and health of each user
if($offpower>$defpower){
// print the action that took place, defense lost health
mysql_query("UPDATE users SET health=health-'$defdamamge' WHERE userid='$id'"); }
if($offpower<$defpower){
// print the action that took place, offense lost health
mysql_query("UPDATE users SET health=health-'$offdamamge' WHERE userid='$userid'"); }
// when a player reaches 1 health or lower it will state the player is dead
// this script will need editing if stats are involved
// but this is a good start to get you on your way
}
?>
Last edited by jessemiller; 03-19-2008 at 12:04 AM. |
| |
| | #9 (permalink) | |
| The original NP Emo Kid | Quote:
Is that the best way? | |
| |
| | #10 (permalink) |
| The original NP Emo Kid | Okay i have gotten it working for all but one thing, the attack_back function and the hitchance dont seem to work properly, for one thing i seem to always attack first even if the enemy hitchance is bigger and i always attack_back not the enemy? PHP Code: |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |