I've got a file that has the same code repeated quite a few times in it. I'm trying to extract that code, make it into a function, then add the function to another file that's already included in the original file. I'm having problems passing whatever is needed though. I know how to call a function, and the rough layout for designing it, but I can't seem to get it to work. Here's the code I'm trying to make into a function: $mp_consumned = '0'; if ( $rabbit_user['creature_ability'] == '1' ) { if ( ( $rabbit_user['creature_health'] < $rabbit_user['creature_health_max'] ) && ( $rabbit_user['creature_health'] > 0 ) && ( $rabbit_user['creature_mp'] > $rabbit_general['regeneration_mp_need'] ) ) { $mp_consumned = $rabbit_general['regeneration_mp_need']; $pet_regen = $rabbit_general['regeneration_hp_give']; $battle_message .= sprintf($lang['Rabbitoshi_Adr_battle_regen'], intval($pet_regen)).'<br />' ; } $sql = "UPDATE " . RABBITOSHI_USERS_TABLE . " SET creature_health = creature_health + $pet_regen, creature_mp = creature_mp - $mp_consumned WHERE owner_id = $user_id "; if (!$result = $db->sql_query($sql)) { message_die(GENERAL_ERROR, 'Could not update pet info', '', __LINE__, __FILE__, $sql); } } PHP: I think with it being in an external file, some stuff that would be in the original file isn't there.
need more than that, perhaps you could post the entire page you're talking about, so we know where the data is coming from .....
The file itself is too big to post, so here's a link to a txt version of it http://games.directorygold.com/test/battle.txt