Funktion med error
Hey, jeg har et lille problem med en funktion jeg ikke kan få til at virke.Har den her kode:
<?
session_start();
if(!$_SESSION[user_id] > 0) {
header("location:index.php");
exit;
}
$user_data = mysql_query("SELECT * FROM players WHERE id=$_SESSION[user_id]");
?>
<?php
/*
* $player1 = id på spiller1
* $player2 = id på spiller2
*
* Spiller 1 angriber først
* udskriver vinder men kan evt. retunere vinderen i stedet...
*/
require_once('connect.php');
function attack($player1, $player2)
{
$data = mysql_query("SELECT * FROM players WHERE id='$player1'") or die(mysql_error());
$p1_data = mysql_fetch_array($data);
$data = mysql_query("SELECT * FROM players WHERE id='$player2'") or die(mysql_error());
$p2_data = mysql_fetch_array($data);
$p1_hit_chance = $p1_data["hitchance"] - $p2_data["dodgechance"];
$p2_hit_chance = $p2_data["hitchance"] - $p1_data["dodgechance"];
$p1_damage = $p1_data["str"] * $p1_data["attackspeed"];
$p2_damage = $p2_data["str"] * $p2_data["attackspeed"];
while(true) //begynd at slå
{
if(mt_rand(0, 100) <= $p1_hit_chance) //spiller 1 rammer
{
$p2_data["currenthp"] -= $p1_damage;
if($p2_data["currenthp"] < 0) $p2_data["currenthp"] = 0;
mysql_query("UPDATE players SET currenthp = $p2_data["currenthp"] WHERE id = '$player2'") or die(mysql_error());
}
if($p2_data["currenthp"] == 0) //spiller 2 død
{
$win = $p1_data;
$lose = $p2_data;
break;
}
if(mt_rand(0, 100) <= $p2_hit_chance) //spiller 2 rammer
{
$p1_data["currenthp"] -= $p2_damage;
if($p1_data["currenthp"] < 0) $p1_data["currenthp"] = 0;
mysql_query("UPDATE players SET currenthp = $p1_data["currenthp"] WHERE id = '$player1'") or die(mysql_error());
}
if($p1_data["currenthp"] == 0) //spiller 1 død
{
$win = $p2_data;
$lose = $p1_data;
break;
}
}
echo $win["accountname"] . " vinder over " . $lose["accountname"] . "!";
}
?>
Og det giver den her error:
Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/virtual/xsix.dk/public_html/online/attacknow.php on line 41
Har siddet og rodet lidt med det, men kan ikke rigtig få det til at virke.
På forhånd tak,
Mvh.
XsiX
