Jump to content

[SOLVED] Troop Wont Train...


Dethman

Recommended Posts

Hey guys I have just finished with this code and everything plays out accept this:

 

Note The Adding of +{$def} Is working Fine...

<?php
//Actuall MySql_Query:
mysql_query("UPDATE `user_users` SET `credits` =(`credits` -{$cost}), `attackTroops` =(`attackTroops` +{$atk}-{$satk}), `atkTroops` =(`atkTroops` +{$satk}), `defenseTroops` =(`defenseTroops` +{$def}-{$sdef}),`defTroops` =(`defTroops` +{$sdef}), `covertTroops` = (`covertTroops` +{$spy}), `wizzards` =(`wizzards` +{$wiz}), `farmer` =(`farmer` +{$far}), `miner` = (`miner` +{$cre}), `untrainedTroops` =(`untrainedTroops` - {$atk}-{$def}-{$spy}-{$wiz}-{$far}-{$cre}) WHERE `userid` = '$userid'") or die("SQL Error: ".mysql_error());

//Line that isnt working:
`defenseTroops` =(`defenseTroops` +{$def}-{$sdef}),`defTroops` =(`defTroops` +{$sdef}),
?>

 

Entire Code:

 

<?php

function spyBoost($cost,$id){
$q="UPDATE `user_users` SET `credits` =`credits` - '$cost', `covertLVL` = `covertLVL` +'1' WHERE `userid` = '$id'";
mysql_query($q);
header("Location: train.php?strErr=Covert Level Upgraded");
}
function birthBoost($amt,$cost,$id){
$q="UPDATE `user_users` SET `credits` =`credits` - '$cost', `birthrate` = `birthrate` +'$amt' WHERE `userid` = '$id'";
mysql_query($q);
header("Location: train.php?strErr=Birth Rate Upgraded");
}

function trainTroops($atk,$satk,$def,$sdef,$spy,$wiz,$far,$cre,$userid){
$sql="SELECT * FROM `user_users` WHERE `userid` = '$userid'";
$query=mysql_query($sql);
$player=mysql_fetch_array($query);
$atk=floor($atk);
$satk=floor($satk);
$def=floor($def);
$sdef=floor($sdef);
$spy=floor($spy);
$wiz=floor($wiz);
$far=floor($far);
$cre=floor($cre);

if($cre<=0){
$cre=0;
}
if($far<=0){
$far=0;
}
if($wiz<=0){
$wiz=0;
}
if($spy<=0){
$spy=0;
}
if($sdef<=0){
$sdef=0;
}
if($def<=0){
$def=0;
}
if($satk<=0){
$satk=0;
}
if($atk<=0){
$atk=0;
}

if($player['untrainedTroops']-($atk+$satk+$def+$sdef+$spy+$wiz+$far+$cre)>=0){ 
 if($player['attackTroops']-$satk >=0){	
  if($player['defenseTroops']-$sdef >=0){
	if($player['credits']-((($atk+$def)*3000)+($spy*5000)+($satk+$sdef*89000)+($wiz*5500)+($far*5000)+($cre*1500))>=0){
	$cost=$spy*5000;
	$cost+=($atk+$def)*3000;
	$cost+=($satk+$sdef)*89000;
	$cost+=$wiz*5500;
	$cost+=$far*5000;
	$cost+=$cre*1500;
		mysql_query("UPDATE `user_users` SET `credits` =(`credits` -{$cost}), `attackTroops` =(`attackTroops` +{$atk}-{$satk}), `atkTroops` =(`atkTroops` +{$satk}), `defenseTroops` =(`defenseTroops` +{$def}-{$sdef}),`defTroops` =(`defTroops` +{$sdef}), `covertTroops` = (`covertTroops` +{$spy}), `wizzards` =(`wizzards` +{$wiz}), `farmer` =(`farmer` +{$far}), `miner` = (`miner` +{$cre}), `untrainedTroops` =(`untrainedTroops` - {$atk}-{$def}-{$spy}-{$wiz}-{$far}-{$cre}) WHERE `userid` = '$userid'") or die("SQL Error: ".mysql_error());

		header("Location: train.php?strErr=TRAINING SUMMARY<br>Troops Trained!");
	}else{
	header("Location: train.php?strErr=TRAINING SUMMARY<br>Not Enough Magi!");
	}
}
else{
header("Location: train.php?strErr=TRAINING SUMMARY<br>You Need Enouph Attackers to Train that Many Supers");	
}	
}else{
	header("Location: train.php?strErr=TRAINING SUMMARY<br>You Need Enouph Attackers to Train that Many Supers");
}
}else{
header("Location: train.php?strErr=TRAINING SUMMARY<br>Not Enough Civillians");
}
}

function untrainTroops($atk,$def,$spy,$userid){
$sql="SELECT * FROM `user_users` WHERE `userid` = '$userid'";
$query=mysql_query($sql);
$user=mysql_fetch_array($query);
$atk=floor($atk);
$def=floor($def);
$spy=floor($spy);
if($spy<=0){
$spy=0;
}
if($def<=0){
$def=0;
}
if($atk<=0){
$atk=0;
}
if($user['untrainedTroops']-($atk+$def+$spy)>=0){	
	if($user['credits']-((($atk+$def)*000)+($spy*000))>=0){
	$cost=$spy*000;
	$cost+=($atk+$def)*000;
		mysql_query("UPDATE `user_users` SET `credits` = `credits` - '$cost', `attackTroops` = `attackTroops` -'$atk', `defenseTroops` = `defenseTroops` -'$def', `covertTroops` = `covertTroops` -'$spys', `untrainedTroops` = `untrainedTroops` + '$atk'+'$def'+'$spy' WHERE `userid` = '$userid'");
		header("Location: train.php?strErr=troops trained");
	}else{
	header("Location: train.php?strErr=not enough credits");
	}
}else{
header("Location: train.php?strErr=not enough civillians");
}
}
?>

 

Please help this thing is getting annoying....

 

Thanks for all of your help,

Brian Flores CEO

NimbusGames,llc

Link to comment
https://forums.phpfreaks.com/topic/114664-solved-troop-wont-train/
Share on other sites

you complain that one poster hasn't give enough info and then you post, show some code, and say "it isn't working".

 

How about some information from yourself

 

Define "not working"

What is it doing that id shouldn't?

What isn't it doing that it should?

 

You know, give us a clue.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.