Ahojte, mám script, ktorý mi vypíše používateľov hrajúcich hru. V hre mám 6 frakcií, 3 z nich sa radia k USA (Spojencom) a ostatné k Nemecku (Osi). Chcel by som zadať podmienku, že používateľ nemôže zaútočiť na spriateľenú frakciu, teda frakcia 0 by nemohla zaútočiť na frakciu 3 a 5. Túto frakciu si vždy volí hráč pri registrácii. A samozrejme aj tie frakcie opačne, že 3 nemôže zaútočiť na 0 a na 5 a to isté pre 5 frakciu. Neviem kam by som if vnoril, lebo som to skúšal všade. Aj keď tam je podmienka, že ak je totožná frakcia pre útočníka a obrancu tak vypíše , že zaútočenie nie je možné. V elseif následne ale zaútoči, ak je iný stav. Teda dal som tam podmienku a vypísalo, že nie je možné zaútočiť, ale jednotka zaútočila. Tam by som to potreboval definovať. Neviem už ako, dokázali by ste mi pomôcť?? Prikladám aj kód, Ďakujem vám.
Kód:
if(!isset($_SESSION['uid'])){
echo "Musíš byť prihlásený!";
}else{
if(isset($_POST['attack2'])){
if($user['fraction'] == $attacked_user['fraction']){
output("Nemôžeš zaútočiť na svoju frakciu!");
}elseif($stats['battery'] >= 10 && $timer['atime'] == 0 && $stats['attack'] >= 10 && $_POST['attack1'] != "" && $_POST['attack1'] != $_SESSION['uid'] && is_numeric($_POST['attack1']) && $_POST['attack1'] <= $id['MAX(`id`)'] && $_POST['attack1'] > 0){
output("Bojovníci začali útok!");
$azarobok1 = 0;
$azarobok2 = 0;
$atime = time();
$working['ayes'] = $atime;
$stats['battery'] -= 10;
$stats['rank'] += 4;
$timer['atime'] = 1;
$info1 = mysql_query("SELECT `id` FROM `stats` WHERE `id`='".$_POST['attack1']."'") or die(mysql_error());
$info2 = mysql_fetch_assoc($info1);
$info3 = $info2['id'];
$update_working = mysql_query("UPDATE `working` SET `ayes`='".$working['ayes']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
$update_stats = mysql_query("UPDATE `stats` SET `battery`='".$stats['battery']."',`rank`='".$stats['rank']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
$update_timer = mysql_query("UPDATE `timer` SET `atime`='".$timer['atime']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
$update_ranking = mysql_query("UPDATE `ranking` SET `number`='".$info3."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
}elseif((time() - $working['ayes']) >= 600 && $timer['atime'] == 1){
$info1 = mysql_query("SELECT `number` FROM `ranking` WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
$info2 = mysql_fetch_assoc($info1);
$info3 = $info2['number'];
$info4 = mysql_query("SELECT `defense`,`food`,`gold` FROM `stats` WHERE `id`='".$info3."'") or die(mysql_error());
$info5 = mysql_fetch_assoc($info4);
if($stats['attack'] > $info5['defense']){
$azarobok1 = round($info5['food'] / 2);
$azarobok2 = round($info5['gold'] / 2);
output("Získal si ".$azarobok1." jedla a ".$azarobok2." zlata!");
$atime = 0;
$working['ayes'] = $atime;
$stats['food'] += $azarobok1;
$stats['gold'] += $azarobok2;
if($azarobok1 > 0){
$stats['rank'] += 1;
}
if($azarobok2 > 0){
$stats['rank'] += 1;
}
$info5['food'] -= $azarobok1;
$info5['gold'] -= $azarobok2;
$azarobok1 = 0;
$azarobok2 = 0;
$timer['atime'] = 0;
$update_working = mysql_query("UPDATE `working` SET `ayes`='".$working['ayes']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
$update_stats = mysql_query("UPDATE `stats` SET `food`='".$stats['food']."',`gold`='".$stats['gold']."',`rank`='".$stats['rank']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
$update_stats = mysql_query("UPDATE `stats` SET `food`='".$info5['food']."',`gold`='".$info5['gold']."' WHERE `id`='".$info3."'") or die(mysql_error());
$update_timer = mysql_query("UPDATE `timer` SET `atime`='".$timer['atime']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
}elseif($stats['attack'] <= $info5['defense']){
output("Bojovníci sa vzdali!");
$atime = 0;
$working['ayes'] = $atime;
$timer['atime'] = 0;
$update_working = mysql_query("UPDATE `working` SET `ayes`='".$working['ayes']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
$update_timer = mysql_query("UPDATE `timer` SET `atime`='".$timer['atime']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
}
}elseif($timer['atime'] == 0){
if($stats['attack'] == 0){
output("Nemáš žiaden útok!");
}elseif($stats['battery'] < 10){
output("Nemáš dostatok baterky!");
}elseif($_POST['attack1'] == "" | $_POST['attack1'] == $_SESSION['uid'] | !is_numeric($_POST['attack1']) | $_POST['attack1'] > $id['MAX(`id`)'] | $_POST['attack1'] <= 0){
output("Toto nieje dobre číslo starostu!");
}
}else{
$zostava = (600 - (time() - $working['ayes']));
output("Musíš počkať ".$zostava." sekúnd.");
}
}
if(isset($_POST['askip'])){
if((time() - $working['ayes']) >= 600){
output("Bojovníci už skončili svoj útok!");
}elseif($stats['battery'] >= 10){
$info1 = mysql_query("SELECT `number` FROM `ranking` WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
$info2 = mysql_fetch_assoc($info1);
$info3 = $info2['number'];
$info4 = mysql_query("SELECT `defense`,`food`,`gold` FROM `stats` WHERE `id`='".$info3."'") or die(mysql_error());
$info5 = mysql_fetch_assoc($info4);
if($stats['attack'] > $info5['defense']){
$azarobok1 = round($info5['food'] / 2);
$azarobok2 = round($info5['gold'] / 2);
output("Získal si ".$azarobok1." jedla a ".$azarobok2." zlata!");
$atime = 0;
$working['ayes'] = $atime;
$stats['food'] += $azarobok1;
$stats['gold'] += $azarobok2;
if($azarobok1 > 0){
$stats['rank'] += 1;
}
if($azarobok2 > 0){
$stats['rank'] += 1;
}
$info5['food'] -= $azarobok1;
$info5['gold'] -= $azarobok2;
$azarobok1 = 0;
$azarobok2 = 0;
$stats['battery'] -= 10;
$stats['rank'] += 4;
$timer['atime'] = 0;
$update_working = mysql_query("UPDATE `working` SET `ayes`='".$working['ayes']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
$update_stats = mysql_query("UPDATE `stats` SET `food`='".$stats['food']."',`gold`='".$stats['gold']."',`rank`='".$stats['rank']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
$update_stats = mysql_query("UPDATE `stats` SET `food`='".$info5['food']."',`gold`='".$info5['gold']."' WHERE `id`='".$info3."'") or die(mysql_error());
$update_stats = mysql_query("UPDATE `stats` SET `battery`='".$stats['battery']."',`rank`='".$stats['rank']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());//new
$update_timer = mysql_query("UPDATE `timer` SET `atime`='".$timer['atime']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
}elseif($stats['attack'] <= $info5['defense']){
output("Bojovníci sa vzdali!");
$atime = 0;
$working['ayes'] = $atime;
$stats['battery'] -= 10;
$stats['rank'] += 4;
$timer['atime'] = 0;
$update_working = mysql_query("UPDATE `working` SET `ayes`='".$working['ayes']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
$update_stats = mysql_query("UPDATE `stats` SET `battery`='".$stats['battery']."',`rank`='".$stats['rank']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());//new
$update_timer = mysql_query("UPDATE `timer` SET `atime`='".$timer['atime']."' WHERE `id`='".$_SESSION['uid']."'") or die(mysql_error());
}
}else{
output("Nemáš dostatok baterky!");
}
}
?>
<center><h2>Majori</h2></center>
<br />
<form action="rankings.php" method="post">
<td><input type="text" name="attack1"></td>
<?php
if($timer['atime'] == 0){?>
<td><button type="submit" name="attack2" class="btn btn-success">Zaútočiť (10% Batérie)</button></td><?php
}else{?>
<td><button type="submit" name="attack2" class="btn btn-warning">Skontrolovať</button></td><?php
if((time() - $working['ayes']) < 600){?>
<td><button type="submit" name="askip" class="btn btn-danger">Preskočiť (10% Batérie)</button></td><?php
}
}
?>
</form>
<table cellpadding="2" cellspacing="4">
<tr>
<td><img src="images/rank.png"></td>
<td width="100px">Pozícia:</td>
<td><img src="images/number.png"></td>
<td width="100px">Číslo:</td>
<td><img src="images/mayor.png"></td>
<td width="100px">Starosta:</td>
<td><img src="images/food.png"></td>
<td width="100px">Jedlo:</td>
<td><img src="images/gold.png"></td>
<td width="100px">Zlato:</td>
</tr>
<?php
$mayors = mysql_query("SELECT `rank`,`id`,`food`,`gold`,`b4` FROM `stats` WHERE `rank`>='0' ORDER BY `rank` DESC,`id` ASC") or die(mysql_error());
$rank = 1;
while($line = mysql_fetch_assoc($mayors)){
echo "<tr>";
echo "<td><td><i>" . $rank . ". (" . $line['rank'] . ")" . "</i></td></td>";
$rank++;
echo "<td><td><i>" . $line['id'] . "</i></td></td>";
$get_mayor = mysql_query("SELECT * FROM `user` WHERE `id`='".$line['id']."'") or die(mysql_error());
$mayor = mysql_fetch_assoc($get_mayor);
?><td><img src="images/fraction<?php echo $mayor['fraction']; ?>.png" style="width: 30px; height: 32px;"/></td><td><i><a <?php if($line['b4'] == 1){ ?>style="color: #2196F3;"<?php } ?> href="mayor.php?<?php echo $line['id']; ?>"><?php echo $mayor['username']; ?></a></i></td></td><?php
echo "<td><td><i>" . $line['food'] . "</i></td></td>";
echo "<td><td><i>" . $line['gold'] . "</i></td></td>";
echo "</tr>";
}
?>
</table>
<?php
}?>
Potreboval by som definovať toto:
if($user['fraction'] == 0) {
if($attacked_user['fraction']== 3){
output("Nemôžeš zaútočiť spojeneckú frakciu!");
}}
Ďakujem za každú pomoc, už si neviem pomôcť
POTREBOVAL BY SOM TO INTEGROVAŤ NIEKDE TU!!
if(isset($_POST['attack2'])){
if($user['fraction'] == $attacked_user['fraction']){
output("Nemôžeš zaútočiť na svoju frakciu!");
}elseif($stats['battery'] >= 10 && $timer['atime'] == 0 && $stats['attack'] >= 10 && $_POST['attack1'] != "" && $_POST['attack1'] != $_SESSION['uid'] && is_numeric($_POST['attack1']) && $_POST['attack1'] <= $id['MAX(`id`)'] && $_POST['attack1'] > 0){
output("Bojovníci začali útok!");// Spojený príspevok Pon 30.05.16 20:26 Nech skúšam ako skúšam, vždy tento výsledok aj keď dám podmienku nad ten output.