So here is the break down. The first function called in my program is monstats(); and that sets up all the monsters stats which randomize every time the person fights even if they fight again. The only thing that shouldn't change in that fight is the health because I don't want the monster to have a new health.
So from here we go to function hitfirst(); which determins who hits first. The player or the monster. Monster hitting first isn't the problem. My problem is the player attacking monster which leads to function dealdamage(); to update the variable $monster health.
My problem is that it isn't carrying that variable back and keeps the monster with the same health it started with.
This is my first time actually using functions and I think so far its a good job. Just not sure about the variable going back.
Hope you guys can help =)
<?php
include("../../connect.php");
if(!isset($_COOKIE['player_id']))
die('Please login.<br><a href=../../index.php>Go back</a>.');
$Player=$_COOKIE['player_id'];
setcookie('player_id',$Player,time()+60*60*24);
setcookie('password',$_COOKIE['password'],time()+60*60*24);
$Query="SELECT * from Users where ID='$Player'";
$Query2=mysql_query($Query) or die("Could not get user stats.");
$User=mysql_fetch_array($Query2);
if($_COOKIE['password'] !=md5($User['Password']))
die('Your Password doesnt seem right for this account. <a href=../../index.php>go back</a>');
function monstats($monpow, $Monsters){
if(isset($_POST['monsterhealth'])){
$monsterhealth=$_POST['monsterhealth'];
}else{
$monsterhealth=$monpow*rand(1,15);
}
if(isset($_POST['monsterenergy'])){
$monsterenergy=$_POST['monsterenergy'];
}else{
$monsterenergy=$monpow*rand(1,15);
}
$monsterstrength=$monpow*rand(1,5);
$monsterwisdom=$monpow*rand(1,5);
$monsterdefence=$monpow*rand(1,5);
$monsterdexterity=$monpow*rand(1,5);
$monsteraccuracy=$monpow*rand(1,5);
echo"You fight ".$Monsters.", with ".$monsterhealth." health.<br>$User[Dexterity]";
hitfirst($monsterhealth, $monsterdexterity, $monsterenergy, $monsterstrength, $monsterwisdom, $monsterdefence, $monsteraccuracy);
if($monsterhealth>=1){
print"<form method=post action=index.php><input type=hidden name=monsterfight value=$Monsters><input type=hidden name=monsterhealth value=$monsterhealth><input type=hidden name=monsterenergy value=$monsterenergy><input type=submit value=\"Fight Again\" name=fight></form>";
}else{
print"You win the battle!<br>";
}
}
function hitfirst($monsterhealth, $monsterdexterity, $monsterenergy, $monsterstrength, $monsterwisdom, $monsterdefence, $monsteraccuracy){
$Player=$_COOKIE['player_id'];
$Query="SELECT * from Users where ID='$Player'";
$Query2=mysql_query($Query) or die("Could not get user stats.");
$User=mysql_fetch_array($Query2);
if($monsterdexterity>=($User['Dexterity']*rand(1,5))){
print"The monster attacks faster!<br>";
takedamage($monsterstrength, $monsteraccuracy);
}else{
print"You attack the monster faster!<br>";
dealdamage($monsterhealth, $monsterdefence);
}
}
function takedamage($monsterstrength, $monsteraccuracy){
$Player=$_COOKIE['player_id'];
$Query="SELECT * from Users where ID='$Player'";
$Query2=mysql_query($Query) or die("Could not get user stats.");
$User=mysql_fetch_array($Query2);
$damage=round($monsterstrength*($monsteraccuracy*3.5)/$User['Defence']);
print"You took ".$damage." damage!";
}
function dealdamage($monsterhealth, $monsterdefence){
$Player=$_COOKIE['player_id'];
$Query="SELECT * from Users where ID='$Player'";
$Query2=mysql_query($Query) or die("Could not get user stats.");
$User=mysql_fetch_array($Query2);
$mondamage=round($User['Strength']*($User['Accuracy']*1.5)/$monsterdefence);
print"You hit the monster for ".$mondamage."!";
$monsterhealth=$monsterhealth-$mondamage;
}
?>
Sorry if it's really long.