Jump to content

Can someone make this function better please?


Dethman

Recommended Posts

Hey a friend of mine gave me a function to help me make a new one can someone Add some comments and or make it better in the coding part,

Heres the Function:

<?php
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;
}?>

 

Thanx ~Dethman

We'd need to see the script as a whole to really give an honest effort into making it "better." (Please don't post your whole script here).  If you're really serious about making it "better," I suggest hiring someone.  That way they can take a look at your setup/files/code as a whole and evaluate the situation. 

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.