jaybones Posted March 4, 2008 Share Posted March 4, 2008 I have a script that checks troop sizes and kills them off in order. Ok, i'll break it out alittle more so u can understand the whole thing. First here is the random killer, lol function getKilled($count){ $killedtroopmin=($count*.001)/4; $killedtroopmax=($count*.001); if ($killedtroopmin < 0){$killedtroopmin=0;} if ($killedtroopmax < 0){$killedtroopmax=1;} return (rand($killedtroopmin,$killedtroopmax)); } Now i load both players total fighting forces: $atackertff=getTotalFightingForce($atacker); $defendertff=getTotalFightingForce($defender); Next i find out how many kills or losts each army will take. $attsize=getKilled($atackertff); $defsize=getKilled($defendertff); Next i determines if the player has the number of troops he lost can be taking away from: First it will see if his merc size is equal or greater then size lost. If so it takes that amount If thats not true the next if statements takes any merc and zero them out. The takes how many mercs u had minus it from the size u lost and the remaining value it takes away from your untrained troops.. Now if the value is higher then your merc and untrained troops. the next if statement does the same as last but removes merc and untrained troops then determines how many trained troops to take.. Any the last else is a fail safe just incase the amount killed is greater then your force. witch will never happen. I space out the code so its easyer to read. if($attsize <= ($atacker->trainedAttackMerc+$atacker->untrainedSold+$atacker->trainedAttackSold)){ If($attsize <= ($atacker->trainedAttackMerc+$atacker->untrainedSold)){ if($attsize <= ($atacker->trainedAttackMerc)){ $atackUsersKilledAM=$attsize; $atackUsersKilledAS=0; $atackUsersKilledUS=0; $atackUsersKilledUM=0; } if($attsize > ($atacker->trainedAttackMerc)){ $atackUsersKilledAM="$atacker->trainedAttackMerc"; $atackUsersKilledUS=($attsize-$atacker->trainedAttackMerc); $atackUsersKilledAS=0; $atackUsersKilledUM=0; } }else{ $atackUsersKilledAM=$atacker->trainedAttackMerc; $atackUsersKilledUS=$atacker->untrainedSold; $atackUsersKilledAS=($attsize-$atacker->trainedAttackMerc-$atacker->untrainedSold); $atackUsersKilledUM=0; } }else{ $atackUsersKilledAM=$atacker->trainedAttackMerc; $atackUsersKilledUS=$atacker->untrainedSold; $atackUsersKilledAS=$atacker->trainedAttackSold; $atackUsersKilledUM=0; } $atackUsersKilled=$atackUsersKilledAS+$atackUsersKilledAM+$atackUsersKilledUS+$atackUsersKilledUM; The very last line takes the value of each killed and adds them. $atackUsersKilled is used in the attack page to show u how many troops u lost.. $atackUsersKilledAS are trained Attack Soldiers $atackUsersKilledAM are trained Attack Mercs $atackUsersKilledUS are untrained Soldiers $atackUsersKilledUM are untrained Merc witch is always 0 since i remove the option 2 buy them.. Ok, i hope this helps alittle explaining how and why this script works.. Now we just need it to work the way its explained. jay Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.