xoligy Posted May 11, 2008 Share Posted May 11, 2008 Hey all well after posting on another forum and getting no help whatso ever i thought i would try another forum (hope you all dont mind!) anyway, ive decided to plunge into html and mysql with some luck and some bad luck lol Right now my biggest problem is this one! Ive starred at the code for about 3weeks now and got no-where so im hoping someone or some people will be kind enough to help me out, i am new to the whole world so excuse me if i ask alot of questions lol Anyway here is the whole code well the php <? include "vsys.php"; function getKilled($count){ return (rand(0,100))?0:(($count>1)?1:0); } function getWeaponStrA($user,$wA,$n,$turns){ //$defWeapons=$defWeaponsA[0]; //$defWeaponsWas=$defWeaponsA[1]; // $defWeaponsIs=$defWeaponsA[2]; // $defWeaponsCount=$defWeaponsA[3]; global $conf; for ($i=0;$i<count($wA);$i++){ //echo $wA[$i]->isAtack.";;".$n."<br>"; //if ($wA[$i]->isAtack==$n) { $Weapons[0].=$wA[$i]->weaponID.";"; $Weapons[1].=$wA[$i]->weaponStrength.";"; $allWeaponStrength=$conf["race"][$user->race]["weapon"][$wA[$i]->weaponID]["strength"]; $weaponDamage=round(rand($allWeaponStrength/200*$turns,($allWeaponStrength/50*$turns<0)?$allWeaponStrength/50*$turns:1)); $newWeaponStrength=$wA[$i]->weaponStrength-$weaponDamage; if ($newWeaponStrength<=0){ $newWeaponStrength=0; delWeapon($wA[$i]->ID); }else{ setWeapon($wA[$i]->ID," weaponStrength ='$newWeaponStrength' "); } $Weapons[2].=$newWeaponStrength.";"; $Weapons[3].=$wA[$i]->weaponCount.";"; } } for ($i=0;$i<4;$i++){ if ($Weapons[$i]){$Weapons[$i]=substr($Weapons[$i],0,strlen($Weapons[$i])-1);} } return $Weapons; } function spiedValue($value,$difPerc){ $value=(rand(($difPerc-100),$difPerc)>0)?$value:"???"; return $value; } if ($cgi ['defender_id2']||$cgi ['defender_id']){ if (($cgi ['defender_id2']==$_SESSION['isLogined'])||($cgi ['defender_id']==$_SESSION['isLogined'])) { $strErr=" You can not attack or spy yourself. "; $cgi['id']=($cgi ['defender_id2'])?$cgi ['defender_id2']:$cgi ['defender_id']; $cgi ['defender_id2']=''; $cgi ['defender_id']=''; } } if ($cgi ['defender_id2']){ $cgi['id']=$cgi ['defender_id2']; if ($cgi['attacks']){ //--------------------------Attacking $fields="atackTurns ,atackStrength, defStrength, gold, phrase,atackUsersKilled,defUsersKilled,atackTrained,atackUnTrained,defTrained,defUnTrained,atackWeapons,defWeapons,atackWeaponWas,atackWeaponIs,atackWeaponCount, defWeaponWas, defWeaponIs, defWeaponCount,time"; $atacker=getUserDetails($_SESSION['isLogined']); if ($cgi['attacks']>15){$cgi['attacks']=15;} if ($cgi['attacks']<1){$cgi['attacks']=1;} if ($atacker->attackTurns >=$cgi['attacks']){ $defender=getUserDetails($cgi['id']); $atackStrength=getStrikeAction($atacker); $atackStrength=rand(round($atackStrength/2),$atackStrength); $defStrength=getDefenseAction($defender); $defStrength=rand(round($defStrength/2),$defStrength); $phrase=$conf["phrase"][rand(0,count($conf["phrase"])-1)]; if ($atackStrength>$defStrength){ $gold=$defender->gold/15; $gold=floor (rand ($gold*$cgi['attacks']/2, $gold*$cgi['attacks'])); }else $gold=0; $atackTrained=$atacker->trainedAttackSold +$atacker->trainedAttackMerc; $atackUnTrained=$atacker->untrainedMerc+$atacker->untrainedSold; $defTrained=$defender->trainedAttackSold +$defender->trainedAttackMerc; $defUnTrained=$defender->untrainedMerc+$defender->untrainedSold; $atackUsersKilledAS=getKilled($atacker->trainedAttackSold); $atackUsersKilledAM=getKilled($atacker->trainedAttackMerc); $atackUsersKilledUM=getKilled($atacker->untrainedMerc); $atackUsersKilledUS=getKilled($atacker->untrainedSold); $atackUsersKilled=$atackUsersKilledAS+$atackUsersKilledAM+$atackUsersKilledUS+$atackUsersKilledUM; $defUsersKilledDS=getKilled($defender->trainedDefSold ); $defUsersKilledDM=getKilled($defender->trainedDefMerc ); $defUsersKilledUM=getKilled($defender->untrainedMerc); $defUsersKilledUS=getKilled($defender->untrainedSold); $defUsersKilled=$defUsersKilledAS+$defUsersKilledAM+$defUsersKilledUS+$defUsersKilledUM; $aW=getUserWeapon($atacker); $atackWeaponsA=getWeaponStrA($atacker,$aW,1,$cgi['attacks']); $atackWeapons=$atackWeaponsA[0]; $atackWeaponWas=$atackWeaponsA[1]; $atackWeaponIs=$atackWeaponsA[2]; $atackWeaponCount=$atackWeaponsA[3]; $aW=getDefUserWeapon($defender); $defWeaponsA=getWeaponStrA($defender,$aW,0,$cgi['attacks']); $defWeapons=$defWeaponsA[0]; $defWeaponWas=$defWeaponsA[1]; $defWeaponIs=$defWeaponsA[2]; $defWeaponCount=$defWeaponsA[3]; $time=time(); updateUser($_SESSION['isLogined'],"attackTurns=attackTurns - {$cgi['attacks']} , gold=gold+$gold, trainedAttackSold=trainedAttackSold-$atackUsersKilledAS ,trainedAttackMerc =trainedAttackMerc- $atackUsersKilledAM,untrainedSold=untrainedSold - $atackUsersKilledUS,untrainedMerc=untrainedMerc-$atackUsersKilledUM "); updateUser($cgi['id'], " gold=gold-$gold, trainedDefSold=trainedDefSold-$defUsersKilledDS ,trainedDefMerc =trainedDefMerc- $defUsersKilledDM,untrainedSold=untrainedSold - $defUsersKilledUS,untrainedMerc=untrainedMerc-$defUsersKilledUM " ); $values="'{$cgi['attacks']}','$atackStrength', '$defStrength', '$gold', '$phrase','$atackUsersKilled','$defUsersKilled','$atackTrained','$atackUnTrained','$defTrained','$defUnTrained','$atackWeapons','$defWeapons','$atackWeaponWas','$atackWeaponIs','$atackWeaponCount', '$defWeaponWas', '$defWeaponIs', '$defWeaponCount', '$time'"; //echo $values; //return; addAtack($_SESSION['isLogined'],$cgi['id'],$fields,$values); $atak=getAtackByUser1User2AndTime($_SESSION['isLogined'],$cgi['id'],$time, " ID "); header("Location: battlelog.php?id={$atak->ID}"); }else{ $strErr="You do not have enough turns."; } } }elseif($cgi ['defender_id']){ $cgi['id']=$cgi ['defender_id']; $atacker=getUserDetails($_SESSION['isLogined']); if ($cgi['numspies']>$atacker->spies)$cgi['numspies']=$atacker->spies; if ($cgi['numspies']>10){$cgi['numspies']=10;} if ($cgi['numspies']<1){$cgi['numspies']=1;} if ($cgi['numspies']&&$atacker->spies){ //echo "Spying "; $defender=getUserDetails($cgi['id']); $time=time(); //echo ($atacker->currentSpySkill+1).";;".$defender->currentSpySkill."##<br>"; //if (($atacker->currentSpySkill+1)<$defender->currentSpySkill){ $tSpies=$atacker->spies; $atacker->spies=$atacker->spies-$cgi['numspies']; $spyStrength=getCovertAction($atacker); $atacker->spies=$tSpies; $spyDefStrength=getCovertAction($defender); if ($spyStrength<($spyDefStrength-100)){ $isSuccess=0; $fields=" `time` , `spies`, `isSuccess`"; $values="'$time' , '".$cgi['numspies']."', '$isSuccess'"; updateUser($atacker->ID, " spies=spies-{$cgi['numspies']} "); }else{ $isSuccess=1; $spies=$cgi['numspies']; $race=$defender->race; //$atacker->spies=$cgi['numspies']; $dif=$spyStrength-$spyDefStrength; if ($dif>100)$dif=100; $dif+=100; $difPerc=$dif/2; // echo "--$difPerc--<br>"; $trainedAttackSold=spiedValue($defender->trainedAttackSold,$difPerc); $trainedAttackMerc=spiedValue($defender->trainedAttackMerc,$difPerc); $trainedDefSold=spiedValue($defender->trainedDefSold,$difPerc); $trainedDefMerc=spiedValue($defender->trainedDefMerc,$difPerc); $untrainedMerc=spiedValue($defender->untrainedMerc,$difPerc); $untrainedSold=spiedValue($defender->untrainedSold,$difPerc); $strikeAction=getStrikeAction($defender); $strikeAction=spiedValue($strikeAction,$difPerc); $defenceAction=getDefenseAction($defender); $defenceAction=spiedValue($defenceAction,$difPerc); $covertSkill=spiedValue($defender->currentSpySkill ,$difPerc); $covertOperatives=spiedValue($defender->spies ,$difPerc); $siegeLevel=spiedValue($defender->siegeLevel,$difPerc); $atackTurns=spiedValue($defender->attackTurns,$difPerc); $unitProduction=spiedValue($defender->currentUnitProduction ,$difPerc); /* $weapons $types $quantities $strengths $allStrengths */ $weapon1=getUserAllWeapon($defender); for ($i=0;$i<count($weapon1);$i++){ if (!spiedValue(0,$difPerc)){ $weapons.=spiedValue($weapon1[$i]->weaponID,$difPerc).";"; $types.=spiedValue($weapon1[$i]->isAtack ,$difPerc).";"; $types2.=$weapon1[$i]->isAtack.";"; $quantities.=spiedValue($weapon1[$i]->weaponCount ,$difPerc).";"; $strengths.=spiedValue($weapon1[$i]->weaponStrength ,$difPerc).";"; //$allStrengths.=spiedValue($weapon1[$i]->weaponID,$difPerc).";"; if ($weapon1[$i]->isAtack){ $tS=$conf["race"][$defender->race]["weapon"][$weapon1[$i]->weaponID]["strength"]; }else{ $tS=$conf["race"][$defender->race]["defenseweapon"][$weapon1[$i]->weaponID]["strength"]; } $allStrengths.=spiedValue($tS,$difPerc).";"; } } if (strlen($weapons)){ $weapons=substr($weapons,0,strlen($weapons)-1); $types=substr($types,0,strlen($types)-1); $types2=substr($types2,0,strlen($types2)-1); $quantities=substr($quantities,0,strlen($quantities)-1); $strengths=substr($strengths,0,strlen($strengths)-1); $allStrengths=substr($allStrengths,0,strlen($allStrengths)-1); } $trainedAttackSold =$defender->trainedAttackSold; $fields="`spyStrength`, `spyDefStrength`, `trainedAttackSold`, `trainedAttackMerc`, `trainedDefSold`, `trainedDefMerc`, `untrainedMerc`, `untrainedSold`, `strikeAction` , `defenceAction`, `covertSkill` , `covertOperatives`, `siegeLevel` , `atackTurns` , `unitProduction` , `weapons`, `types`, `types2` , `quantities`, `strengths` , `allStrengths`, `time` , `spies`, `isSuccess`, `race`"; $values="'$spyStrength', '$spyDefStrength', '$trainedAttackSold', '$trainedAttackMerc', '$trainedDefSold', '$trainedDefMerc', '$untrainedMerc', '$untrainedSold', '$strikeAction', '$defenceAction', '$covertSkill', '$covertOperatives', '$siegeLevel' , '$atackTurns' , '$unitProduction' , '$weapons', '$types', '$types2' , '$quantities', '$strengths' ,'$allStrengths', '$time' , '$spies', '$isSuccess', '$race'"; } //echo $fields."<br>"; //echo $values; //return; addSpy($atacker->ID,$defender->ID,$fields,$values); //return; $spy=getSpyByUser1User2AndTime($atacker->ID,$defender->ID,$time, " ID "); header("Location: spylog.php?id={$spy->ID}"); }else{$strErr="You should enter number of (o have) spies to send.";} } ?> Also how would i go about making a "max" buy button for an item? Hope someone can help me out Quote Link to comment Share on other sites More sharing options...
rarebit Posted May 11, 2008 Share Posted May 11, 2008 whats the problem? Quote Link to comment Share on other sites More sharing options...
dank Posted May 11, 2008 Share Posted May 11, 2008 lol @ All those "atacker" and "defender" and "spy" variables. What game is it? I noticed that you spell attack two different ways: "attack" and "atack" I'd be consistent with variable naming. Also, as rarebit asked, knowing the problem would be helpful for those who are trying to help you. Quote Link to comment Share on other sites More sharing options...
xoligy Posted May 11, 2008 Author Share Posted May 11, 2008 Yea i was just about to edit the post to say whats up and you replied anyway this is from the post i made on another site, the code is from a kingsofchaos clone im just adding things i can now and again and this is the biggest problem anyway the problem: Ok here is what i have, i have put the game onto a local host and then tried the attack script now the way it should work is that the attack should be upto the users attack strength and a little below (random but not too random) the problem is its far too random, ive even had hits for -4bil (testing) Quote Link to comment Share on other sites More sharing options...
dank Posted May 11, 2008 Share Posted May 11, 2008 <?php $atackStrength=getStrikeAction($atacker); $atackStrength=rand(round($atackStrength/2),$atackStrength); ?> Is this where it determines the attack strength? If so, I'd check the getStrikeAction function. In seems to be in the vsys.php file, I presume. Quote Link to comment Share on other sites More sharing options...
xoligy Posted May 11, 2008 Author Share Posted May 11, 2008 Sorry for the slow reply i was just messing about with ubuntru (learning that too) Yes i beliebe thats the attack part and this is what i found in the vsys function getStrikeAction($user){ global $conf; $num=0; $trainedCount=$user->trainedAttackSold+$user->trainedAttackMerc; $untrainedCount=$user->untrainedMerc+$user->untrainedSold; $weaponA1=getUserWeapon($user); if (!count($weaponA1)&&!$trainedCount) return 0; /*$k=0; for ($i=0;$i<count($weaponA1);$i++){ for ($j=0; $j<$weaponA1[$i]->weaponCount ;$j++){ $weaponA[$k]=$weaponA1[$i]; $k++; } }*/ $weaponA=getWeaponArray($weaponA1); if ($weaponA){ $wepAlloc=getWeaponAllocation($user,$weaponA,$trainedCount,$untrainedCount); $wI=0; for ($i=0; $i<$wepAlloc["trainedW"];$i++,$wI++){ $num+=$weaponA[$wI]->weaponStrength*5; } for ($i=0; $i<$wepAlloc["untrainedW"];$i++,$wI++){ $num+=$weaponA[$wI]->weaponStrength*4; } }else{ $wepAlloc["trainedUnW"]=$trainedCount; $wepAlloc["untrainedUnW"]=$untrainedCount; } $num+=$wepAlloc["trainedUnW"]*5; $num+=$wepAlloc["untrainedUnW"]*4; for ($i=0; $i<=$user->siegeLevel;$i++){ if ($conf["race"][$user->race]["siege"][$i]["attack"]){ $num+=round(($num*$conf["race"][$user->race]["siege"][$i]["attack"])/100); } } if ($conf["race"][$user->race]["attack"]){ $num+=round(($num*$conf["race"][$user->race]["attack"])/100); } return $num; Quote Link to comment Share on other sites More sharing options...
dank Posted May 12, 2008 Share Posted May 12, 2008 To me, it is difficult to weed out a flaw in a code that is written by somebody else, especially one at that length. Now, you said the you've made changes to the original script. I assume that the script worked prior to your modifications, so I would suggest that you review the changes you've made. If you cannot figure out anything, I would suggest starting over and making changes one at a time. For example: make one change, make sure everything works fine, then make another change. Sorry I couldn't help you any further. Quote Link to comment Share on other sites More sharing options...
xoligy Posted May 12, 2008 Author Share Posted May 12, 2008 No problem Dank, yes i have made a few minor changes but there more to do with the layout and styling, im no great coder far from it to be honest its been a while since i done any HTML or css ofr that matter! Thats all ive really dabbled with nothing on the php side unless its calling a function that already works. In the original script the attack page never worked as it should do. Someone with a similar script was kind enough to write this to me but i dont understand it completly For the random factor, look to the 'rand' part in the 'gold' win or the attack/defence values. You can change that to whatever you want, or eliminate it. Just search 'rand' and comment out the line if you dont want random value alteration... I know rand means random, but the rand part is just "rand(round($atackStrength/2),$atackStrength)" so im unsure what to do ??? Quote Link to comment Share on other sites More sharing options...
dank Posted May 12, 2008 Share Posted May 12, 2008 Well that's the problem, when I saw "rand(round($atackStrength/2),$atackStrength)" I had no idea where $atackStrength was coming from or how it was being formed. So what that person said to you, was that you can change that rand() to whatever you want to. For example: <?php rand(1,10); ?> Produces a random value from 1 to 10. <?php rand(round($atackStrength/2),$atackStrength) ?> So if the person's strength value was 100, they're strength against their opponent would range from 50 to 100. That's all, that simple. The question still remains, however, where the value $atackStrength comes from. So what you're doing is like a puzzle. You have to scan through the code where $atackStrength is defined. Given the length of the code, that will be a very difficult thing to do. It is most likely due to some math flaws in vsys.php I know I'm not that much help. But I'll end by saying that the best lesson I've learned in programming is that it's always best to do everything yourself. If you use other people's scripts, you are trapped with the way that person wants it to work. But everyone has their own ideas of how something should work. Then making modifications is much more difficult since you have no idea what is going on in the code that the other person wrote. So it's really a nuisance. Making your own scripts is the best way to learn. And if you are having trouble, you download someone else's script and skim through it for reference to see how they did it. Then you write it your own way. It's like writing an essay, and looking at other ones for ideas, but you have to have it in your own words and in your own way. And if it's in your own words, it's much easier to understand what you're saying opposed to it being in someone else's words. Good luck with the script. It's definitely a challenge. Quote Link to comment Share on other sites More sharing options...
xoligy Posted May 13, 2008 Author Share Posted May 13, 2008 Aaah ok thanks Andrew! I'll give it ago and see what happens as for $atackStrength thats only on attack.php it's calling for getStrikeAction on vsys.php thats why i put getStrikeAction above when you asked for it Ive noticed 1/2 other bugs so no doubt be back when i figure out a few other things. Quote Link to comment Share on other sites More sharing options...
xoligy Posted May 13, 2008 Author Share Posted May 13, 2008 Meh, seems im going to have to get a coder to look at it i canna figure it out. Besides that ive noticed the max hit, defence and cash possible is something like 2bil so seems alot of work would need to be done... 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.