Small problem with my php code...Please help me

Discussion in 'PHP' started by starscream, Jun 27, 2009.

  1. #1
    Hi guys, I have a small problem which I hope someone here can help me with. Here is the problem, the code below is suppose to output the number of kills to the database tab "mostKills"

    So for example, during the 1st attack, I killed 4 robbers. The "4" robbers goes into the "mostKills" tab and it stores fine.

    However, when I launch the 2nd attack, and kill 3 robbers, it erases the previous "4" that I killed and only inputs and stores "3" in the "mostKills" tab in the database.

    Does anyone have a quick fix that I could add to the code below so that it will store the existing "4" robbers and add "3" to it after the 2nd attack. So after the first 2 attacks, it will store "7" in the "MostKills" tab? And after the 3rd attack, it will take that number and add it to the "7" previously killed.

    I'm really new to programming so if there is a kind soul here that can help me with this, I would really appreciate it :eek:


    $die2total = $die2[unit2]+$die2[unit3]+$die2[unit4]+$die2[unit5]+$die2[unit6]+$die2[unit7]+$die2[unit8]+$die2[unit9]+$die2[unit10];


    $mostKills = $die2total;
    $session['mostKills'] = $mostKills;

    mysql_query("UPDATE $tab[player] SET gold='$session[gold]', wood='$session[wood]', worth='$session[worth]', online='$time', mostKills='$mostKills' WHERE id='$session[id]';");
     
    starscream, Jun 27, 2009 IP
  2. alfa_375

    alfa_375 Active Member

    Messages:
    445
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #2
    try to display the $die2total variable to see what exactly the figure there. Then do the update table, just comment out the line for mysq_query and print the $die2total(echo $die2total); command.

    It seems you have problem before the code you had posted here. If you can post all of the code of that file, may be you will get good help.

    Otherwise pm me the details , I will see how can I help you.
     
    alfa_375, Jun 27, 2009 IP
  3. starscream

    starscream Peon

    Messages:
    305
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi alfa_375,

    Thanks for taking the time to try to help me. I have included the whole file below. Any help you could give me would be greatly appreciated :)
    <?
    $session['enemyrace'] = $enemy['race'];
    $session['enemyid'] = $pid;

    include("../config_races.php");

    $session['enemyrace'] = "";
    $session['enemyid'] = "";
    //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    //|||||||||||||||IF ZEROED ATTACK||||||||||||||||||||||||||||||||||||||||||||||
    //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    $zeroed = $enemyUnit[unit2]+$enemyUnit[unit3]+$enemyUnit[unit4]+$enemyUnit[unit5]+$enemyUnit[unit6]+$enemyUnit[unit7]+$enemyUnit[unit8]+$enemyUnit[unit9]+$enemyUnit[unit10];

    //REMOVE MILITIA FROM ZERO COUNT
    if($enemy[race] == 1){ $zeroed=$zeroed-$enemyUnit[unit2]; }

    if($zeroed == 0){

    if($enemy['race'] == 1){ $enemy['militia']=$time+3600; }

    $totalvils = $enemyUnit['unit1']+$enemyUnit['unit2']+$enemyUnit['lumberjack']+$enemyUnit['miner'];

    //echo"$totalvils last attack units<br>";

    $maxkill = $totalvils*.02;
    $minkill = $maxkill*.80;

    $killGather = rand($minkill,$maxkill);

    //echo"only $killGather can die<br><br>";

    $eUnit[unit1] = $killGather;

    $unitarray[2] = $unit2;
    $unitarray[3] = $unit3;
    $unitarray[4] = $unit4;
    $unitarray[5] = $unit5;
    $unitarray[6] = $unit6;
    $unitarray[7] = $unit7;
    $unitarray[8] = $unit8;
    $unitarray[9] = $unit9;
    $unitarray[10] = $unit10;

    $run=2;
    while(($run != 10) && ($killGather > 0)){

    if($run == 2){ $uid=unit2; }elseif($run == 3){ $uid=unit3; }elseif($run == 4){ $uid=unit4; }elseif($run == 5){ $uid=unit5; }elseif($run == 6){ $uid=unit6; }elseif($run == 7){ $uid=unit7; }elseif($run == 8){ $uid=unit8; }elseif($run == 9){ $uid=unit9; }elseif($run == 10){ $uid=unit10; }
    $units = $unitarray[$run];

    $nme=$name[$session[race]][$uid];

    if($units){

    //echo"<br><big><font color=white>$units</font> $nme attacking...</big>";

    $dmgMax = $units*$stat[$session[race]][$uid][atk];
    $dmgMin = $dmgMax*.80;
    $dmgType = $stat[$session[race]][$uid][atkType];
    $damage=rand($dmgMin,$dmgMax);

    //echo"doing $damage dmg<br>";

    if($enemy[race] == 4){
    $vil[unit1] = $enemyUnit[unit1];
    $vil[lumberjack] = $enemyUnit[lumberjack];
    }
    if($enemy[race] == 3){
    $vil[unit1] = $enemyUnit[unit1];
    $vil[miner] = $enemyUnit[miner];
    $vil[lumberjack] = $enemyUnit[lumberjack];
    }
    if($enemy[race] == 2){
    $vil[unit1] = $enemyUnit[unit1];
    $vil[miner] = $enemyUnit[miner];
    $vil[lumberjack] = $enemyUnit[lumberjack];
    }
    if($enemy[race] == 1){
    $vil[unit1] = $enemyUnit[unit1];
    $vil[unit2] = $enemyUnit[unit2];
    $vil[miner] = $enemyUnit[miner];
    $vil[lumberjack] = $enemyUnit[lumberjack];
    }


    $fails=0;
    while(($damage > 0) && ($fails < 5) && ($killGather > 0)){

    $id=1;
    if($vil[unit1] > 0){ $attacking[$id++]=unit1; }
    if($vil[unit2] > 0){ $attacking[$id++]=unit2; }
    if($vil[miner] > 0){ $attacking[$id++]=miner; }
    if($vil[lumberjack] > 0){ $attacking[$id++]=lumberjack; }
    $id--;

    if($id == 0){ $damage=0; }
    else{

    $attackRand = rand(1,$id);
    $attackUnit = $attacking[$attackRand];
    $die = rand(1,$killGather);
    if($die > $killGather){ $die=$killGather; }

    $atk = $attackUnit;
    $rce = $enemy['race'];
    $nam = $name[$rce][$atk];
    $hps = $stat[$rce][$atk][hps];

    if($hps > $damage){ $fails++; }
    else{

    $arm = $stat[$rce][$atk][armor];
    $armType = $stat[$rce][$atk][armorType];
    $armTotal = $arm*$die;

    $dmgNeed = $hps;

    $buff=0; $debuff=0;
    if(($dmgType == Normal) && ($armType == Medium)){ $buff=round($dmgNeed*.50); }
    elseif(($dmgType == Normal) && ($armType == Fortified)){ $debuff=round($dmgNeed*.30); }
    elseif(($dmgType == Piercing) && ($armType == Light)){ $buff=round($dmgNeed*.75); }
    elseif(($dmgType == Piercing) && ($armType == Medium)){ $debuff=round($dmgNeed*.25); }
    elseif(($dmgType == Piercing) && ($armType == Fortified)){ $debuff=round($dmgNeed*.65); }
    elseif(($dmgType == Siege) && ($armType == Medium)){ $debuff=round($dmgNeed*.50); }
    elseif(($dmgType == Siege) && ($armType == Fortified)){ $buff=round($dmgNeed*.50); }
    elseif(($dmgType == Magic) && ($armType == Light)){ $buff=round($dmgNeed*.25); }
    elseif(($dmgType == Magic) && ($armType == Medium)){ $debuff=round($dmgNeed*.25); }
    elseif(($dmgType == Magic) && ($armType == Heavy)){ $buff=round($dmgNeed*.75); }
    elseif(($dmgType == Magic) && ($armType == Fortified)){ $debuff=round($dmgNeed*.65); }

    $newDmg=$dmgNeed-$buff+$debuff+$arm;

    if($newDmg > $damage){ $damage=0; }
    else{

    $dmgNeed=$newDmg*$die;

    if($dmgNeed > $damage){
    $kill = floor($damage/$newDmg);
    $useDmg = $kill*$newDmg;
    $die2[$atk] = $die2[$atk]+$kill;
    $vil[$atk] = $vil[$atk]-$kill;
    }
    else{
    $kill=$die;
    $useDmg = $kill*$newDmg;
    $die2[$atk] = $die2[$atk]+$kill;
    $vil[$atk] = $vil[$atk]-$kill;
    }

    }

    $killGather=$killGather-$die2[$atk];
    $noprotectDead=$noprotectDead+$die2[$atk];

    $damage=$damage-$useDmg;
    if($damage < 0){ $damage=0;}

    //echo"killed $kill $nam, costed u $useDmg damage<br>";
    //echo"$vil[$atk] $nam are left. $damage dmg left<br><br>";
    //echo"killgather $killGather<Br>";


    }

    }
    }









    }


    $run++;
    } // end last loop


    }else{


    //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    //|||||||||||||||ATTACKERS ATTACK||||||||||||||||||||||||||||||||||||||||||||||
    //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

    $plans = mysql_fetch_array(mysql_query("SELECT unit1,unit2,unit3,unit4,unit5,unit6,unit7,unit8,unit9,unit10 FROM $tab[plans] WHERE race='$enemy[race]' AND aid='$session[aid]';"));

    if($session[race] != 1){ $unitarray[2] = $unit2; }
    $unitarray[3] = $unit3;
    $unitarray[4] = $unit4;
    $unitarray[5] = $unit5;
    $unitarray[6] = $unit6;
    $unitarray[7] = $unit7;
    $unitarray[8] = $unit8;
    $unitarray[9] = $unit9;
    $unitarray[10] = $unit10;

    //enemy units
    if($enemy['race'] != 1){
    $eUnit[unit2] = $enemyUnit[unit2];
    } //dont let militia die if human
    $eUnit[unit3] = $enemyUnit[unit3];
    $eUnit[unit4] = $enemyUnit[unit4];
    $eUnit[unit5] = $enemyUnit[unit5];
    $eUnit[unit6] = $enemyUnit[unit6];
    $eUnit[unit7] = $enemyUnit[unit7];
    $eUnit[unit8] = $enemyUnit[unit8];
    $eUnit[unit9] = $enemyUnit[unit9];
    $eUnit[unit10] = $enemyUnit[unit10];
    //enemy buildings
    $eUnit[build2] = $enemyBuild[build2];
    $eUnit[build3] = $enemyBuild[build3];
    $eUnit[build4] = $enemyBuild[build4];
    $eUnit[build5] = $enemyBuild[build5];
    $eUnit[build6] = $enemyBuild[build6];
    $eUnit[build7] = $enemyBuild[build7];
    $eUnit[build8] = $enemyBuild[build8];
    $eUnit[build9] = $enemyBuild[build9];

    $run=2;
    while($run != 11){

    if($run == 2){ $uid=unit2; }elseif($run == 3){ $uid=unit3; }elseif($run == 4){ $uid=unit4; }elseif($run == 5){ $uid=unit5; }elseif($run == 6){ $uid=unit6; }elseif($run == 7){ $uid=unit7; }elseif($run == 8){ $uid=unit8; }elseif($run == 9){ $uid=unit9; }elseif($run == 10){ $uid=unit10; }
    $units = $unitarray[$run];

    $nme=$name[$session[race]][$uid];

    //echo"$run $uid $nme attacking doing $damage damage<br>";

    if($units){

    $dmgMax = $units*$stat[$session[race]][$uid][atk];
    $dmgMin = $dmgMax*.80;
    $dmgType = $stat[$session[race]][$uid][atkType];

    $damage=rand($dmgMin,$dmgMax);

    //echo"$nme attacking doing $damage damage<br>";

    $fails=0;
    while(($damage != 0) && ($damage > 1000) && ($fails < 5)){

    $wantToKill = $eUnit[$plans[$uid]];

    if(!$wantToKill){

    while(($damage > 0) && ($fails < 5)){

    $id=1;
    if($enemy[race] != 1){ if($eUnit[unit2] > 0){ $attacking[$id++]=unit2; } }
    if($eUnit[unit3] > 0){ $attacking[$id++]=unit3; }
    if($eUnit[unit4] > 0){ $attacking[$id++]=unit4; }
    if($eUnit[unit5] > 0){ $attacking[$id++]=unit5; }
    if($eUnit[unit6] > 0){ $attacking[$id++]=unit6; }
    if($eUnit[unit7] > 0){ $attacking[$id++]=unit7; }
    if($eUnit[unit8] > 0){ $attacking[$id++]=unit8; }
    if($eUnit[unit9] > 0){ $attacking[$id++]=unit9; }
    if($eUnit[unit10] > 0){ $attacking[$id++]=unit10; }

    if($enemy['race'] == $enemy['area']){
    if($eUnit[build2] > 0){ $attacking[$id++]=build2; }
    if($eUnit[build3] > 0){ $attacking[$id++]=build3; }
    if($eUnit[build4] > 0){ $attacking[$id++]=build4; }
    if($eUnit[build5] > 0){ $attacking[$id++]=build5; }
    if($eUnit[build6] > 0){ $attacking[$id++]=build6; }
    if($eUnit[build7] > 0){ $attacking[$id++]=build7; }
    if($eUnit[build8] > 0){ $attacking[$id++]=build8; }
    if($eUnit[build9] > 0){ $attacking[$id++]=build9; }
    }

    $id--;

    if($id == 0){ $damage=0; }
    else{

    $attackRand = rand(1,$id);
    $attackUnit = $attacking[$attackRand];
    $tenpercent = ($eUnit[$attackUnit]*0.1);
    $die = rand(1,$tenpercent);

    $atk = $attackUnit;
    $rce = $enemy['race'];
    $nam = $name[$rce][$atk];
    $hps = $stat[$rce][$atk][hps];

    if($hps > $damage){ $fails++; }
    else{

    $arm = $stat[$rce][$atk][armor];
    $armType = $stat[$rce][$atk][armorType];
    $armTotal = $arm*$die;

    $dmgNeed = $hps;

    $buff=0; $debuff=0;
    if(($dmgType == Normal) && ($armType == Medium)){ $buff=round($dmgNeed*.50); }
    elseif(($dmgType == Normal) && ($armType == Fortified)){ $debuff=round($dmgNeed*.30); }
    elseif(($dmgType == Piercing) && ($armType == Light)){ $buff=round($dmgNeed*.75); }
    elseif(($dmgType == Piercing) && ($armType == Medium)){ $debuff=round($dmgNeed*.25); }
    elseif(($dmgType == Piercing) && ($armType == Fortified)){ $debuff=round($dmgNeed*.65); }
    elseif(($dmgType == Siege) && ($armType == Medium)){ $debuff=round($dmgNeed*.50); }
    elseif(($dmgType == Siege) && ($armType == Fortified)){ $buff=round($dmgNeed*.50); }
    elseif(($dmgType == Magic) && ($armType == Light)){ $buff=round($dmgNeed*.25); }
    elseif(($dmgType == Magic) && ($armType == Medium)){ $debuff=round($dmgNeed*.25); }
    elseif(($dmgType == Magic) && ($armType == Heavy)){ $buff=round($dmgNeed*.75); }
    elseif(($dmgType == Magic) && ($armType == Fortified)){ $debuff=round($dmgNeed*.65); }


    $newDmg=$dmgNeed-$buff+$debuff+$arm;

    if($newDmg > $damage){ $damage=0; }
    else{

    $dmgNeed=$newDmg*$die;
    if($dmgNeed > $damage){
    $kill = floor($damage/$newDmg);
    $useDmg = $kill*$newDmg;
    $die2[$atk] = $die2[$atk]+$kill;
    $eUnit[$atk] = $eUnit[$atk]-$kill;
    }else{
    $kill=$die;
    $useDmg = $kill*$newDmg;
    $die2[$atk] = $die2[$atk]+$kill;
    $eUnit[$atk] = $eUnit[$atk]-$kill;

    }

    //PILLAGE
    if(($session['race'] == 2) && ($buff2[upgrade6] == 1)){
    if(($uid == unit3) || ($uid == unit4) || ($uid == unit6)){
    if(($atk == build2) || ($atk == build3) || ($atk == build4) || ($atk == build5) || ($atk == build6) || ($atk == build7) || ($atk == build8) || ($atk == build9)){

    $PILLunitDMG = $stat[$session[race]][$uid][atk];
    $PILLtotalDmg = $stat[$rce][$atk][hps]*$kill;
    $PILLtotalHits = round($PILLtotalDmg/$PILLunitDMG);

    $stealgold = $stealgold+(rand($PILLtotalHits*2,$PILLtotalHits*10));
    $stealwood = $stealwood+(rand($PILLtotalHits*2,$PILLtotalHits*10));



    }
    }
    }

    }

    $damage=$damage-$useDmg;
    if($damage < 0){ $damage=0;}

    //echo"killed $kill $nam, costed u $useDmg damage<br>";
    //echo"$eUnit[$atk] $nam are left. $damage dmg left<br><br>";


    }

    }
    }


    }
    else{

    $atk = $plans[$uid];

    if(($atk == build2) || ($atk == build3) || ($atk == build4) || ($atk == build5) || ($atk == build6) || ($atk == build7) || ($atk == build8) || ($atk == build9) || ($atk == build10)){
    $buildattack=yes;
    }

    if(($buildattack == yes) && ($enemy[race] != $enemy[area])){ echo"stopped"; $eUnit[$atk]=0; }

    $rce = $enemy['race'];
    $nam = $name[$rce][$atk];
    $die = $eUnit[$atk];

    $hps = $stat[$rce][$atk][hps];
    $arm = $stat[$rce][$atk][armor];
    $armType = $stat[$rce][$atk][armorType];
    $armTotal = $arm*$die;


    $dmgNeed = $hps;

    $buff=0; $debuff=0;
    if(($dmgType == Normal) && ($armType == Medium)){ $buff=round($dmgNeed*.50); }
    elseif(($dmgType == Normal) && ($armType == Fortified)){ $debuff=round($dmgNeed*.30); }
    elseif(($dmgType == Piercing) && ($armType == Light)){ $buff=round($dmgNeed*.75); }
    elseif(($dmgType == Piercing) && ($armType == Medium)){ $debuff=round($dmgNeed*.25); }
    elseif(($dmgType == Piercing) && ($armType == Fortified)){ $debuff=round($dmgNeed*.65); }
    elseif(($dmgType == Siege) && ($armType == Medium)){ $debuff=round($dmgNeed*.50); }
    elseif(($dmgType == Siege) && ($armType == Fortified)){ $buff=round($dmgNeed*.50); }
    elseif(($dmgType == Magic) && ($armType == Light)){ $buff=round($dmgNeed*.25); }
    elseif(($dmgType == Magic) && ($armType == Medium)){ $debuff=round($dmgNeed*.25); }
    elseif(($dmgType == Magic) && ($armType == Heavy)){ $buff=round($dmgNeed*.75); }
    elseif(($dmgType == Magic) && ($armType == Fortified)){ $debuff=round($dmgNeed*.65); }


    $newDmg=$dmgNeed-$buff+$debuff+$arm;
    //echo"newdmg $newDmg ";
    if($newDmg > $damage){ $damage=0; }
    else{

    $dmgNeed=$newDmg*$die;
    if($dmgNeed > $damage){
    $kill = floor($damage/$newDmg);
    $useDmg = $kill*$newDmg;
    $die2[$atk] = $die2[$atk]+$kill;
    $eUnit[$atk] = $eUnit[$atk]-$kill;
    }else{
    $kill=$die;
    $useDmg = $kill*$newDmg;
    $die2[$atk] = $die2[$atk]+$kill;
    $eUnit[$atk] = $eUnit[$atk]-$kill;

    }

    //PILLAGE
    if(($session['race'] == 2) && ($buff2[upgrade6] == 1)){
    if(($uid == unit3) || ($uid == unit4) || ($uid == unit6)){
    if(($atk == build2) || ($atk == build3) || ($atk == build4) || ($atk == build5) || ($atk == build6) || ($atk == build7) || ($atk == build8) || ($atk == build9)){

    $PILLunitDMG = $stat[$session[race]][$uid][atk];
    $PILLtotalDmg = $stat[$rce][$atk][hps]*$kill;
    $PILLtotalHits = round($PILLtotalDmg/$PILLunitDMG);

    $stealgold = $stealgold+(rand($PILLtotalHits*2,$PILLtotalHits*10));
    $stealwood = $stealwood+(rand($PILLtotalHits*2,$PILLtotalHits*10));




    }
    }
    }

    }

    $damage=$damage-$useDmg;
    if($damage < 0){ $damage=0;}

    //echo"killed $kill $nam, costed u $useDmg damage<br>";
    //echo"$eUnit[$atk] $nam are left. $damage dmg left<br><br>";



    }
    } //end 2nd loop


    }

    $run++;
    } // end last loop


    }
     
    starscream, Jun 27, 2009 IP
  4. starscream

    starscream Peon

    Messages:
    305
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    And the second part of the file is below. It was too big for me to post it all in the reply.

    //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    //|||||||||||ENEMIES RETURN ATTACK|||||||||||||||||||||||||||||||||||||||||||||
    //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    //|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||


    $enemyPlans = mysql_fetch_array(mysql_query("SELECT unit1,unit2,unit3,unit4,unit5,unit6,unit7,unit8,unit9,unit10 FROM $tab[plans] WHERE race='$session[race]' AND aid='$enemy[aid]';"));

    if(($enemy['race'] == 1) && ($zeroed == 0) && ($time > $enemy['militia'])){ $unitarray[2] = $enemyUnit[unit2]; }
    if($enemy['race'] != 1){ $unitarray[2] = $enemyUnit[unit2]; }
    $unitarray[3] = $enemyUnit[unit3];
    $unitarray[4] = $enemyUnit[unit4];
    $unitarray[5] = $enemyUnit[unit5];
    $unitarray[6] = $enemyUnit[unit6];
    $unitarray[7] = $enemyUnit[unit7];
    $unitarray[8] = $enemyUnit[unit8];
    $unitarray[9] = $enemyUnit[unit9];
    $unitarray[10] = $enemyUnit[unit10];

    if($enemy[race] == 1){
    $unitarray[11] = $enemyBuild[build7];
    $unitarray[12] = $enemyBuild[build8];
    $unitarray[13] = $enemyBuild[build9];
    }
    if($enemy[race] == 2){
    $unitarray[11] = $enemyBuild[build6];
    $unitarray[12] = $enemyBuild[build7];
    $unitarray[13] = $enemyBuild[build8];
    $unitarray[14] = $enemyBuild[build9];
    }
    if($enemy[race] == 3){
    $unitarray[11] = $enemyBuild[build7];
    $unitarray[12] = $enemyBuild[build8];
    $unitarray[13] = $enemyBuild[build9];
    }
    if($enemy[race] == 4){
    $unitarray[11] = $enemyBuild[build7];
    $unitarray[12] = $enemyBuild[build8];
    $unitarray[13] = $enemyBuild[build9];
    }

    $eUnit[unit1] = $unit1;
    $eUnit[unit2] = $unit2;
    $eUnit[unit3] = $unit3;
    $eUnit[unit4] = $unit4;
    $eUnit[unit5] = $unit5;
    $eUnit[unit6] = $unit6;
    $eUnit[unit7] = $unit7;
    $eUnit[unit8] = $unit8;
    $eUnit[unit9] = $unit9;
    $eUnit[unit10] = $unit10;

    $run=2;
    while($run != 13){
    if($run == 2){ $uid=unit2; }elseif($run == 3){ $uid=unit3; }elseif($run == 4){ $uid=unit4; }elseif($run == 5){ $uid=unit5; }elseif($run == 6){ $uid=unit6; }elseif($run == 7){ $uid=unit7; }elseif($run == 8){ $uid=unit8; }elseif($run == 9){ $uid=unit9; }elseif($run == 10){ $uid=unit10; }elseif(($run == 11) && ($enemy[race] == 1)){ $uid=build8; }elseif(($run == 11) && ($enemy[race] == 2)){ $uid=build6; }elseif(($run == 11) && ($enemy[race] == 2)){ $uid=build8; }elseif(($run == 13) && ($enemy[race] == 2)){ $uid=build7; }elseif(($run == 12) && ($enemy[race] == 3)){ $uid=build9; }elseif(($run == 13) && ($enemy[race] == 3)){ $uid=build8; }elseif(($run == 12) && ($enemy[race] == 3)){ $uid=build7; }elseif(($run == 11) && ($enemy[race] == 4)){ $uid=build8; }elseif(($run == 13) && ($enemy[race] == 4)){ $uid=build7; }elseif(($run == 12) && ($enemy[race] == 1)){ $uid=build9; }

    $units = $unitarray[$run];

    $nme=$name[$enemy[race]][$uid];

    if($units){

    //echo"<br><font color=white>$units $nme attacking</font><br><br>";

    $dmgMax = $units*$stat[$enemy[race]][$uid][atk];
    $dmgMin = $dmgMax*.80;
    $dmgType = $stat[$enemy[race]][$uid][atkType];

    $damage=rand($dmgMin,$dmgMax);

    //echo"doing $damage damage<br>";

    $fails=0;
    while(($damage != 0) && ($damage > 1000) && ($fails < 5)){

    $wantToKill = $eUnit[$enemyPlans[$uid]];

    if(!$wantToKill){


    //echo"<small>find random unit</small><br>";


    while(($damage > 0) && ($fails < 5)){

    $id=1;
    if($eUnit[unit2] > 0){ $attacking[$id++]=unit2; }
    if($eUnit[unit3] > 0){ $attacking[$id++]=unit3; }
    if($eUnit[unit4] > 0){ $attacking[$id++]=unit4; }
    if($eUnit[unit5] > 0){ $attacking[$id++]=unit5; }
    if($eUnit[unit6] > 0){ $attacking[$id++]=unit6; }
    if($eUnit[unit7] > 0){ $attacking[$id++]=unit7; }
    if($eUnit[unit8] > 0){ $attacking[$id++]=unit8; }
    if($eUnit[unit9] > 0){ $attacking[$id++]=unit9; }
    if($eUnit[unit10] > 0){ $attacking[$id++]=unit10; }
    $id--;

    if($id == 0){ $damage=0; }
    else{

    $attackRand = rand(1,$id);
    $attackUnit = $attacking[$attackRand];
    $tenpercent = ($eUnit[$attackUnit]*0.1);
    $die = rand(1,$tenpercent);

    $atk = $attackUnit;
    $rce = $session['race'];
    $nam = $name[$rce][$atk];
    $hps = $stat[$rce][$atk][hps];



    if($hps > $damage){ $fails++; }
    else{

    $arm = $stat[$rce][$atk][armor];
    $armType = $stat[$rce][$atk][armorType];
    $armTotal = $arm*$die;

    $dmgNeed = $hps;

    $buff=0; $debuff=0;
    if(($dmgType == Normal) && ($armType == Medium)){ $buff=round($dmgNeed*.50); }
    elseif(($dmgType == Normal) && ($armType == Fortified)){ $debuff=round($dmgNeed*.30); }
    elseif(($dmgType == Piercing) && ($armType == Light)){ $buff=round($dmgNeed*.75); }
    elseif(($dmgType == Piercing) && ($armType == Medium)){ $debuff=round($dmgNeed*.25); }
    elseif(($dmgType == Piercing) && ($armType == Fortified)){ $debuff=round($dmgNeed*.65); }
    elseif(($dmgType == Siege) && ($armType == Medium)){ $debuff=round($dmgNeed*.50); }
    elseif(($dmgType == Siege) && ($armType == Fortified)){ $buff=round($dmgNeed*.50); }
    elseif(($dmgType == Magic) && ($armType == Light)){ $buff=round($dmgNeed*.25); }
    elseif(($dmgType == Magic) && ($armType == Medium)){ $debuff=round($dmgNeed*.25); }
    elseif(($dmgType == Magic) && ($armType == Heavy)){ $buff=round($dmgNeed*.75); }
    elseif(($dmgType == Magic) && ($armType == Fortified)){ $debuff=round($dmgNeed*.65); }


    $newDmg=$dmgNeed-$buff+$debuff+$arm;
    //echo"newdmg $newDmg ";
    if($newDmg > $damage){ $damage=0; }
    else{

    $dmgNeed=$newDmg*$die;
    if($dmgNeed > $damage){
    $kill = floor($damage/$newDmg);
    $useDmg = $kill*$newDmg;
    $die1[$atk] = $die1[$atk]+$kill;
    $eUnit[$atk] = $eUnit[$atk]-$kill;
    }else{
    $kill=$die;
    $useDmg = $kill*$newDmg;
    $die1[$atk] = $die1[$atk]+$kill;
    $eUnit[$atk] = $eUnit[$atk]-$kill;

    }

    }


    $damage=$damage-$useDmg;
    if($damage < 0){ $damage=0;}

    // echo"killed $kill $nam, costed u $useDmg damage<br>";
    //echo"$eUnit[$atk] $nam are left. $damage dmg left<br><br>";


    }

    }
    }


    }
    else{
    $atk = $enemyPlans[$uid];
    $rce = $session['race'];
    $nam = $name[$rce][$atk];
    $die = $eUnit[$atk];

    $hps = $stat[$rce][$atk][hps];
    $arm = $stat[$rce][$atk][armor];
    $armType = $stat[$rce][$atk][armorType];
    $armTotal = $arm*$die;

    $dmgNeed = $hps;

    $buff=0; $debuff=0;
    if(($dmgType == Normal) && ($armType == Medium)){ $buff=round($dmgNeed*.50); }
    elseif(($dmgType == Normal) && ($armType == Fortified)){ $debuff=round($dmgNeed*.30); }
    elseif(($dmgType == Piercing) && ($armType == Light)){ $buff=round($dmgNeed*.75); }
    elseif(($dmgType == Piercing) && ($armType == Medium)){ $debuff=round($dmgNeed*.25); }
    elseif(($dmgType == Piercing) && ($armType == Fortified)){ $debuff=round($dmgNeed*.65); }
    elseif(($dmgType == Siege) && ($armType == Medium)){ $debuff=round($dmgNeed*.50); }
    elseif(($dmgType == Siege) && ($armType == Fortified)){ $buff=round($dmgNeed*.50); }
    elseif(($dmgType == Magic) && ($armType == Light)){ $buff=round($dmgNeed*.25); }
    elseif(($dmgType == Magic) && ($armType == Medium)){ $debuff=round($dmgNeed*.25); }
    elseif(($dmgType == Magic) && ($armType == Heavy)){ $buff=round($dmgNeed*.75); }
    elseif(($dmgType == Magic) && ($armType == Fortified)){ $debuff=round($dmgNeed*.65); }


    $newDmg=$dmgNeed-$buff+$debuff+$arm;
    //echo"newdmg $newDmg ";
    if($newDmg > $damage){ $damage=0; }
    else{

    $dmgNeed=$newDmg*$die;
    if($dmgNeed > $damage){
    $kill = floor($damage/$newDmg);
    $useDmg = $kill*$newDmg;
    $die1[$atk] = $die1[$atk]+$kill;
    $eUnit[$atk] = $eUnit[$atk]-$kill;
    }else{
    $kill=$die;
    $useDmg = $kill*$newDmg;
    $die1[$atk] = $die1[$atk]+$kill;
    $eUnit[$atk] = $eUnit[$atk]-$kill;

    }

    }


    $damage=$damage-$useDmg;
    if($damage < 0){ $damage=0;}

    //echo"killed $kill $nam, costed u $useDmg damage<br>";
    //echo"$eUnit[$atk] $nam are left. $damage dmg left<br><br>";


    }
    } //end 2nd loop


    }

    $run++;
    } // end last loop


    if($stealgold > $enemy['gold']){ $stealgold=$enemy['gold']; }
    if($stealwood > $enemy['wood']){ $stealwood=$enemy['wood']; }

    $die1total = $die1[unit2]+$die1[unit3]+$die1[unit4]+$die1[unit5]+$die1[unit6]+$die1[unit7]+$die1[unit8]+$die1[unit9]+$die1[unit10];
    $die2total = $die2[unit2]+$die2[unit3]+$die2[unit4]+$die2[unit5]+$die2[unit6]+$die2[unit7]+$die2[unit8]+$die2[unit9]+$die2[unit10];
    $totaldestroy = $die2[build2]+$die2[build3]+$die2[build4]+$die2[build5]+$die2[build6]+$die2[build7]+$die2[build8]+$die2[build9];

    if($die1total <= $die2total){ $victory='<font color="#00CC00" size="+1"><b>You are victorious!</b></font>'; }
    else{ $victory='<font color="#990000" size="+1"><b>You have been defeated!</b></font>'; }

    $mostKills = $die2total;
    $session['mostKills'] = $mostKills;

    mysql_query("UPDATE $tab[player] SET gold='$session[gold]', wood='$session[wood]', worth='$session[worth]', online='$time', mostKills='$mostKills' WHERE id='$session[id]';");

    $mostUnits = $unit['unit2']+$unit['unit3']+$unit['unit4']+$unit['unit5']+$unit['unit6']+$unit['unit7']+$unit['unit8']+$unit['unit9']+$unit['unit10'];
    $session['mostUnits'] = $mostUnits;

    mysql_query("UPDATE $tab[player] SET gold='$session[gold]', wood='$session[wood]', worth='$session[worth]', online='$time', mostUnits='$mostUnits' WHERE id='$session[id]';");
    mysql_query("UPDATE $tab[unit] SET unit2='$unit[unit2]', unit3='$unit[unit3]', unit4='$unit[unit4]', unit5='$unit[unit5]', unit6='$unit[unit6]', unit7='$unit[unit7]', unit8='$unit[unit8]', unit9='$unit[unit9]', unit10='$unit[unit10]', lumberjack='$unit[lumberjack]', miner='$unit[miner]' WHERE id='$session[id]';");


    ?>
    <table width="85%">
    <tr>
    <td align="center">
    <br>
    <?
    if($session['area'] == 1){?>The tranquil land of the Han trembles below your feet, as <font color="white"><?=$sending?></font> of your war units enters the capital of Luoyang towards <a href="player.php?pid=<?=$pid?>"><?=$enemy['name']?>'s</a> kingdom...<?}
    if($session['area'] == 2){?>Black smoke fills the air and darkens the sunny sky into an omnious darkness as, <font color="white"><?=$sending?></font> of your war units marches with authority through the peaceful land of Shu towards <a href="player.php?pid=<?=$pid?>"><?=$enemy['name']?>'s</a> kingdom...<?}
    if($session['area'] == 3){?>The war drums beat with a thunderous rhythm as the morale of your <font color="white"><?=$sending?></font> war units reaches a fever pitch as they cross into rich fertile land of Wu, they hasten their pace towards <a href="player.php?pid=<?=$pid?>"><?=$enemy['name']?>'s</a> kingdom...<?}
    if($session['area'] == 4){?>War flags of your great empire flap along the warm breeze as <font color="white"><?=$sending?></font> of your war units confidently runs across the rigid plains of Wei meeting the enemy forces head on. Attacking <a href="player.php?pid=<?=$pid?>"><?=$enemy['name']?>'s</a> kingdom...<?}
    ?>
    <br>
    <br>
    <?if($noprotectDead > 0){?>
    Your units rage out of control "<i><font color="EEEEEE">They are attacking the defenseless</i>!</font>"
    <br>Your warriors executed or destroyed

    <?
    if($enemy[race] == 1){
    $peasants = $die2[unit1]+$die2[miner]+$die2[lumberjack];
    if($peasants){?><font color="white"><?=$peasants?></font> peasants, <?}
    if($die2[unit2]){?><font color="white"><?=$die2[unit2]?></font> <?=$name[$enemy[race]][unit2]?>, <?}
    }
    if($enemy[race] == 2){
    $peons = $die2[unit1]+$die2[miner]+$die2[lumberjack];
    if($peons){?><font color="white"><?=$peons?></font> terrified Slaves <?}
    }
    if($enemy[race] == 3){
    $wisps = $die2[unit1]+$die2[miner]+$die2[lumberjack];
    if($wisps){?><font color="white"><?=$wisps?></font> innocent Crafters <?}
    }
    if($enemy[race] == 4){
    $acolytes = $die2[unit1]+$die2[miner];
    $ghouls = $die2[unit2]+$die2[lumberjack];
    if($acolytes){?><font color=white><?=$acolytes?></font> fleeing Militia, <?}
    if($ghouls){?><font color=white><?=$ghouls?></font> Arrow Knights, <?}
    }
    ?>
    of <a href="player.php?pid=<?=$pid?>"><?=$enemy['name']?>'s</a> units.
    <br>
    <br>
    <?}elseif($die2total > 0){?>
    Leading your empire through the chaotic battle, you assess that
    <br>
    <?
    if(($die2[unit1]) && (!$die2[unit3]) && (!$die2[unit4]) && (!$die2[unit5]) && (!$die2[unit6]) && (!$die2[unit7]) && (!$die2[unit8]) && (!$die2[unit9]) && (!$die2[unit10])) { $and2="and "; }
    if(($die2[unit1]) || ($die2[unit2]) && (!$die2[unit4]) && (!$die2[unit5]) && (!$die2[unit6]) && (!$die2[unit7]) && (!$die2[unit8]) && (!$die2[unit9]) && (!$die2[unit10])) { $and3="and "; }
    if(($die2[unit1]) || ($die2[unit2]) || ($die2[unit3]) && (!$die2[unit5]) && (!$die2[unit6]) && (!$die2[unit7]) && (!$die2[unit8]) && (!$die2[unit9]) && (!$die2[unit10])) { $and4="and "; }
    if(($die2[unit1]) || ($die2[unit2]) || ($die2[unit3]) || ($die2[unit4]) && (!$die2[unit6]) && (!$die2[unit7]) && (!$die2[unit8]) && (!$die2[unit9]) && (!$die2[unit10])) { $and5="and "; }
    if(($die2[unit1]) || ($die2[unit2]) || ($die2[unit3]) || ($die2[unit4]) || ($die2[unit5]) && (!$die2[unit7]) && (!$die2[unit8]) && (!$die2[unit9]) && (!$die2[unit10])) { $and6="and "; }
    if(($die2[unit1]) || ($die2[unit2]) || ($die2[unit3]) || ($die2[unit4]) || ($die2[unit5]) || ($die2[unit6]) && (!$die2[unit8]) && (!$die2[unit9]) && (!$die2[unit10])) { $and7="and "; }
    if(($die2[unit1]) || ($die2[unit2]) || ($die2[unit3]) || ($die2[unit4]) || ($die2[unit5]) || ($die2[unit6]) || ($die2[unit7]) && (!$die2[unit9]) && (!$die2[unit10])) { $and8="and "; }
    if(($die2[unit1]) || ($die2[unit2]) || ($die2[unit3]) || ($die2[unit4]) || ($die2[unit5]) || ($die2[unit6]) || ($die2[unit7]) || ($die2[unit8]) && (!$die2[unit10])) { $and9="and "; }
    if(($die2[unit1]) || ($die2[unit2]) || ($die2[unit3]) || ($die2[unit4]) || ($die2[unit5]) || ($die2[unit6]) || ($die2[unit7]) || ($die2[unit8]) || ($die2[unit9])) { $and10="and "; }

    if($die2[unit2]){?><?=$and2?><font color="white"><?=$die2[unit2]?></font> <?=$name[$enemy[race]][unit2]?>, <?}
    if($die2[unit3]){?><?=$and3?><font color="white"><?=$die2[unit3]?></font> <?=$name[$enemy[race]][unit3]?>, <?}
    if($die2[unit4]){?><?=$and4?><font color="white"><?=$die2[unit4]?></font> <?=$name[$enemy[race]][unit4]?>, <?}
    if($die2[unit5]){?><?=$and5?><font color="white"><?=$die2[unit5]?></font> <?=$name[$enemy[race]][unit5]?>, <?}
    if($die2[unit6]){?><?=$and6?><font color="white"><?=$die2[unit6]?></font> <?=$name[$enemy[race]][unit6]?>, <?}
    if($die2[unit7]){?><?=$and7?><font color="white"><?=$die2[unit7]?></font> <?=$name[$enemy[race]][unit7]?>, <?}
    if($die2[unit8]){?><?=$and8?><font color="white"><?=$die2[unit8]?></font> <?=$name[$enemy[race]][unit8]?>, <?}
    if($die2[unit9]){?><?=$and9?><font color="white"><?=$die2[unit9]?></font> <?=$name[$enemy[race]][unit9]?>, <?}
    if($die2[unit10]){?><?=$and10?><font color="white"><?=$die2[unit10]?></font> <?=$name[$enemy[race]][unit10]?>, <?}
    ?>of <a href="player.php?pid=<?=$pid?>"><?=$enemy['name']?>'s</a> units, have been lost in the fighting.
     
    starscream, Jun 27, 2009 IP
  5. starscream

    starscream Peon

    Messages:
    305
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    <br>
    <br>
    <?}?>
    <?if($totaldestroy > 0){?>
    Your units battered down
    <?
    if($die2[build1]){?><font color="white"><?=$die2[build1]?></font> <?=$name[$enemy[race]][build1]?>s, <?}
    if($die2[build2]){?><font color="white"><?=$die2[build2]?></font> <?=$name[$enemy[race]][build2]?>s, <?}
    if($die2[build3]){?><font color="white"><?=$die2[build3]?></font> <?=$name[$enemy[race]][build3]?>s, <?}
    if($die2[build4]){?><font color="white"><?=$die2[build4]?></font> <?=$name[$enemy[race]][build4]?>s, <?}
    if($die2[build5]){?><font color="white"><?=$die2[build5]?></font> <?=$name[$enemy[race]][build5]?>s, <?}
    if($die2[build6]){?><font color="white"><?=$die2[build6]?></font> <?=$name[$enemy[race]][build6]?>s, <?}
    if($die2[build7]){?><font color="white"><?=$die2[build7]?></font> <?=$name[$enemy[race]][build7]?>s, <?}
    if($die2[build8]){?><font color="white"><?=$die2[build8]?></font> <?=$name[$enemy[race]][build8]?>s, <?}
    if($die2[build9]){?><font color="white"><?=$die2[build9]?></font> <?=$name[$enemy[race]][build9]?>s, <?}
    ?>of <a href="player.php?pid=<?=$pid?>"><?=$enemy['name']?>'s</a> buildings.
    <br>
    <br>
    <?}?>
    <?=$victory?>
    <br>

    <?if($sending == $die1total){?>
    <br>You wait around patiently to hear the good news from one of your returning units, but all you hear is silence...<font color="ff0000><b>Holy Crap!!!</b></font>
    <a href="player.php?pid=<?=$pid?>"><?=$enemy['name']?>'s</a> kingdom wiped out all <font color="white"><?=$sending?></font> of your units.
    <?}elseif($die1total > 0){?>
    <br>After your brave warriors returned from their battle, you noticed that....
    <br>
    <?
    $and2=""; $and3=""; $and4=""; $and5=""; $and6=""; $and7=""; $and8=""; $and9=""; $and10="";
    if(($die1[unit1]) && (!$die1[unit3]) && (!$die1[unit4]) && (!$die1[unit5]) && (!$die1[unit6]) && (!$die1[unit7]) && (!$die1[unit8]) && (!$die1[unit9]) && (!$die1[unit10])) { $and2="and "; }
    if(($die1[unit1]) || ($die1[unit2]) && (!$die1[unit4]) && (!$die1[unit5]) && (!$die1[unit6]) && (!$die1[unit7]) && (!$die1[unit8]) && (!$die1[unit9]) && (!$die1[unit10])) { $and3="and "; }
    if(($die1[unit1]) || ($die1[unit2]) || ($die1[unit3]) && (!$die1[unit5]) && (!$die1[unit6]) && (!$die1[unit7]) && (!$die1[unit8]) && (!$die1[unit9]) && (!$die1[unit10])) { $and4="and "; }
    if(($die1[unit1]) || ($die1[unit2]) || ($die1[unit3]) || ($die1[unit4]) && (!$die1[unit6]) && (!$die1[unit7]) && (!$die1[unit8]) && (!$die1[unit9]) && (!$die1[unit10])) { $and5="and "; }
    if(($die1[unit1]) || ($die1[unit2]) || ($die1[unit3]) || ($die1[unit4]) || ($die1[unit5]) && (!$die1[unit7]) && (!$die1[unit8]) && (!$die1[unit9]) && (!$die1[unit10])) { $and6="and "; }
    if(($die1[unit1]) || ($die1[unit2]) || ($die1[unit3]) || ($die1[unit4]) || ($die1[unit5]) || ($die1[unit6]) && (!$die1[unit8]) && (!$die1[unit9]) && (!$die1[unit10])) { $and7="and "; }
    if(($die1[unit1]) || ($die1[unit2]) || ($die1[unit3]) || ($die1[unit4]) || ($die1[unit5]) || ($die1[unit6]) || ($die1[unit7]) && (!$die1[unit9]) && (!$die1[unit10])) { $and8="and "; }
    if(($die1[unit1]) || ($die1[unit2]) || ($die1[unit3]) || ($die1[unit4]) || ($die1[unit5]) || ($die1[unit6]) || ($die1[unit7]) || ($die1[unit8]) && (!$die1[unit10])) { $and9="and "; }
    if(($die1[unit1]) || ($die1[unit2]) || ($die1[unit3]) || ($die1[unit4]) || ($die1[unit5]) || ($die1[unit6]) || ($die1[unit7]) || ($die1[unit8]) || ($die1[unit9])) { $and10="and "; }

    if($die1[unit2]){?><?=$and2?><font color="white"><?=$die1[unit2]?></font> <?=$name[$session[race]][unit2]?>, <?}
    if($die1[unit3]){?><?=$and3?><font color="white"><?=$die1[unit3]?></font> <?=$name[$session[race]][unit3]?>, <?}
    if($die1[unit4]){?><?=$and4?><font color="white"><?=$die1[unit4]?></font> <?=$name[$session[race]][unit4]?>, <?}
    if($die1[unit5]){?><?=$and5?><font color="white"><?=$die1[unit5]?></font> <?=$name[$session[race]][unit5]?>, <?}
    if($die1[unit6]){?><?=$and6?><font color="white"><?=$die1[unit6]?></font> <?=$name[$session[race]][unit6]?>, <?}
    if($die1[unit7]){?><?=$and7?><font color="white"><?=$die1[unit7]?></font> <?=$name[$session[race]][unit7]?>, <?}
    if($die1[unit8]){?><?=$and8?><font color="white"><?=$die1[unit8]?></font> <?=$name[$session[race]][unit8]?>, <?}
    if($die1[unit9]){?><?=$and9?><font color="white"><?=$die1[unit9]?></font> <?=$name[$session[race]][unit9]?>, <?}
    if($die1[unit10]){?><?=$and10?><font color="white"><?=$die1[unit10]?></font> <?=$name[$session[race]][unit10]?>, <?}
    ?>units, were lost during the great battle.
    <br>
    <?}?>
    <?if(($stealgold) || ($stealwood)){?>
    <br>During the attack, you manage to pillage <font color="white"><?=commas($stealgold)?></font> <img src="images/gold.gif"> and <font color="white"><?=commas($stealwood)?></font> <img src="images/lumber.gif">.
    <br>
    <?}?>
    <br>
    </td>
    </tr>
    </table>
    <?
    if($noprotectDead){

    $message.="<a href=player.php?pid=".$session[id].">".$session[name]."</a> sent <font color=white>".$sending."</font> units into your kingdom and slayed ";

    if($enemy[race] == 1){
    $peasants = $die2[unit1]+$die2[miner]+$die2[lumberjack];
    if($peasants){ $message.="<font color=white>".$peasants."</font> of your peasants,"; }
    if($die2[unit2]){ $message.="<font color=white>".$die2[unit2]."</font> of your ".$name[$enemy[race]][unit2].","; }
    }
    if($enemy[race] == 2){
    $peons = $die2[unit1]+$die2[miner]+$die2[lumberjack];
    if($peons){ $message.="<font color=white>".$peons."</font> of your Slaves"; }
    }
    if($enemy[race] == 3){
    $wisps = $die2[unit1]+$die2[miner]+$die2[lumberjack];
    if($wisps){ $message.="<font color=white>".$wisps."</font> of your Crafters"; }
    }
    if($enemy[race] == 4){
    $acolytes = $die2[unit1]+$die2[miner];
    $ghouls = $die2[unit2]+$die2[lumberjack];
    if($acolytes){ $message.="<font color=white>".$acolytes."</font> of your Militia,"; }
    if($ghouls){ $message.="<font color=white>".$ghouls."</font> of your Arrow Knights,"; }
    }
    $message.="because you had no units to protect them!";
    if($totaldestroy > 0){ $message.="<br><br>You also lost <font color=white>$totaldestroy</font> buildings!"; }


    if($die1total > 0){ $message.="<br><br>During the attack, you did manage to kill off <font color=white>$die1total</font> of <a href=player.php?pid=".$session[id].">".$session[name]."&#39s</a> units."; }

    }else{

    $message.="<a href=player.php?pid=".$session[id].">".$session[name]."</a> sent <font color=white>".$sending."</font> units into your kingdom, killing <font color=white>".$die2total."</font> of your units!";
    if($totaldestroy > 0){ $message.="<br><br><font color=white>$totaldestroy</font> of your buildings where also destroyed!"; }
    if($die1total > 0){ $message.="<br><br>During the attack, your kingdom managed to slay <font color=white>".$die1total."</font> of <a href=player.php?pid=".$session[id].">".$session[name]."&#39s</a> units."; }


    }

    if(($stealgold) || ($stealwood)){ $message.="<br><br>You lost <font color=white>".commas($stealgold)."</font> <img src=/images/gold.gif> and <font color=white>".commas($stealwood)."</font> <img src=/images/lumber.gif> during the attack."; }

    $units1[unit2] = $unit2-$die1[unit2];
    $units1[unit3] = $unit3-$die1[unit3];
    $units1[unit4] = $unit4-$die1[unit4];
    $units1[unit5] = $unit5-$die1[unit5];
    $units1[unit6] = $unit6-$die1[unit6];
    $units1[unit7] = $unit7-$die1[unit7];
    $units1[unit8] = $unit8-$die1[unit8];
    $units1[unit9] = $unit9-$die1[unit9];
    $units1[unit10] = $unit10-$die1[unit10];

    $enemyUnit[unit1] -= $die2[unit1];
    $enemyUnit[unit2] -= $die2[unit2];
    $enemyUnit[unit3] -= $die2[unit3];
    $enemyUnit[unit4] -= $die2[unit4];
    $enemyUnit[unit5] -= $die2[unit5];
    $enemyUnit[unit6] -= $die2[unit6];
    $enemyUnit[unit7] -= $die2[unit7];
    $enemyUnit[unit8] -= $die2[unit8];
    $enemyUnit[unit9] -= $die2[unit9];
    $enemyUnit[unit10] -= $die2[unit10];
    $enemyUnit[lumberjack] -= $die2[lumberjack];
    $enemyUnit[miner] -= $die2[miner];


    $enemyBuild[build1] -= $die2[build1];
    $enemyBuild[build2] -= $die2[build2];
    $enemyBuild[build3] -= $die2[build3];
    $enemyBuild[build4] -= $die2[build4];
    $enemyBuild[build5] -= $die2[build5];
    $enemyBuild[build6] -= $die2[build6];
    $enemyBuild[build7] -= $die2[build7];
    $enemyBuild[build8] -= $die2[build8];
    $enemyBuild[build9] -= $die2[build9];


    $leftover = $units1[unit1]+$units1[unit2]+$units1[unit3]+$units1[unit4]+$units1[unit5]+$units1[unit6]+$units1[unit7]+$units1[unit8]+$units1[unit9]+$units1[unit10];
    ?>
     
    starscream, Jun 27, 2009 IP
  6. kingdan221

    kingdan221 Peon

    Messages:
    84
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If i were you, i would seriously consider using OOP for such thing.
     
    kingdan221, Jun 28, 2009 IP
  7. starscream

    starscream Peon

    Messages:
    305
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #7
    What is OOP?
     
    starscream, Jun 28, 2009 IP
  8. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Could you not retrieve the most kills value from the table and then add the new attack score to it and then update the value.

    So say for example
    
    //Retrieve Most Kills Value
    $result = mysql_query("SELECT MostKills FROM tablename WHERE user = $user");
    //Fetch the result
    $row = mysql_fetch_array($result);
    //Add new kills to value
    $newkills += $row['mostkills'];
    //Now re-insert(update) new total
    mysql_query("UPDATE tablename SET mostkills = '$mostkills' WHERE user = $userid");
    
    PHP:
    BTW OOP stands for Object-Orientated-Programming, but I don't know enough about it I think it uses objects and classes :)
     
    wd_2k6, Jun 28, 2009 IP