Jump to content

Somethings wrong with script


ILYAS415

Recommended Posts

Okay sorry for not being specific in the title. Its because im not exactly sure whats wrong.

I am making a battle script for my game and im starting off with a function. Okay the page im running this script on is...

http://www.ragingmortals.com/game/test.php

 

LOGIN:

demo

demo

 

Whenever I run this page, nothing happens. (nothing appears in the middle table).

This isnt always the case, sometimes is comes up and sometimes it doesnt.

Heres the function im using...

 

function melee($enemy, $user){ //ROUND OF MELEE FUNCTION USED FOR FIGHTING
$sql= mysql_query("SELECT * FROM enemies WHERE name='$enemy'");
$sql_num= mysql_num_rows($sql);
$get= mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$user'"));
if ($sql_num == "0"){ }else{
$the= mysql_fetch_object($sql);
session_register('enemyhealth');
$_SESSION['enemyhealth'] = $the->maxhealth;
$enemyhealth= $_SESSION['enemyhealth'];

$message="";

//WHO ATTACKS FIRST?
$speed= rand($get->agility-5, $get->agility+5);
$espeed= rand($the->agility-5, $the->agility+5);

//-------------------
//BATTLE STATS FOR YOU ------------------------------------
$wep= mysql_fetch_object(mysql_query("SELECT * FROM weapons WHERE name='$getfetch->weapon'"));
$arm= mysql_fetch_object(mysql_query("SELECT * FROM armour WHERE name='$get->armour'"));
$wep_power= rand($wep->power-2, $wep->power+2);
$arm_def= $arm->power;

if ($wep->type == classes($get->class, "weapontype")){
$wep_power= $wep_power+2;
}
//---------------------------------------------------------
//ENEMY BATTLE STATS --------------------------------------
$ewep= mysql_fetch_object(mysql_query("SELECT * FROM weapons WHERE name='$the->weapon'"));
$earm= mysql_fetch_object(mysql_query("SELECT * FROM armour WHERE name='$the->armour'"));
$ewep_power= rand($ewep->power-2, $ewep->power+2);
$earm_def= $arm->power;

//NO SPECIAL CLASS ATTRIBUTES FOR ENEMIES 
//---------------------------------------------------------
//FIRST ATTACK
$off= $get->offense/5;
$defense= $get->defense/5;
$damage= $wep_power+$defense+$offense; //PLAYER TOTAL DAMAGE
$damage= intval($damage); //MAKE WHOLE NUMBER

$eoff= $the->offense/5;
$edefense= $the->defense/5;
$edamage= $wep_power+$edefense+$eoffense; //AI ENEMY TOTAL DAMAGE
$edamage= intval($edamage); //MAKE WHOLE NUMBER

if ($speed >= $espeed){
$message.= "$user hit $the->name first for $damage damage using his $get->weapon!<br />";
}elseif ($speed < $espeed){
$message.= "$the->name attacked $user first to hit for $edamage damage using his $the->weapon!<br />";
}
//END OF FIRST ATTACK

while ($enemyhealth>0 && $get->health != 0){
$erand= rand(1, 10);
$rand= rand(1, 10);
$dam= $damage/2;
$edam= $edamage/2;
$damage= rand($damage-$dam, $damage+$dam);
$edamage= rand($edamage-$edam, $edamage+$edam);

if ($rand == "5"){ //IF CRITICAL HIT
$message.= "<br /><b>$user hit down with strength and hit $enemy for $damage hit points critical damage! $enemy has $enemyhealth hitpoints left!</b><br />";
}else{ //IF NO CRITICAL HIT
$message.= "<br />$user hit $enemy for $damage lots of hp! $enemy has $enemyhealth left!<br />";
$enemyhealth= $enemyhealth-$damage;
}
if ($erand == "5"){
$message.= "<b>$enemy got lucky and swiped a critical hit. $user lost $edamage hitpoints! $user has $get->health health left!</b><br />";
}else{
$message.= "$enemy hit you for $edamage hitpoints! $user has $get->health health left!<br />";
}
mysql_query("UPDATE users SET health=health-'0' WHERE username='$user'");
}

}
return $message;
} //END OF MELEE FUNCTION

 

As you can see its quite a long function.

Any help would be appreciated.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.