Hey i have quick request. This should be an easy function to write.
The function, given the stats of a pet (mov,str,def,hp,lvl) it should detect if it is trainable so then return 0. If it is not trainable return the number of levels it needs to gain before it becomes trainable please.
The stats should be provided via array please.
I'll put this in Javascript because I know it and you like it :3
function trainable(statArray)
{
if(statArray[4]*2>statArray[0] && statArray[4]*2>statArray[1] && statArray[4]*2>statArray[2] && statArray[4]*2>statArray[3])
{
return 0
}
else
{
var temp=0
temp = Math.max(statArray[0],statArray[1],statArray[2],statArray[3])
return Math.ceil((temp/2)-statArray[4])
}
}
//mov,str,def,hp,lvl
stats = [15,16,17,18,10]
alert(trainable(stats))
I haven't tested it, but it makes sense. If all stats are less than double the level, return 0... else find the highest stat, divide it by 2, subtract the current level, round up, then return the result that tells you how many levels need to be trained.
EDIT: Don't know why it put my parenthesis on the next line, but clearly it is attached to the previous line.
Edited by jcrboy, 15 May 2010 - 09:42 AM.