Code:
<?php
$connection = mysql_connect("localhost", "root", "12345") or die("Connection to Database failed");
mysql_select_db("world") or die ("Database selection failed");
$myFile = "update.sql";
$fh = fopen($myFile, 'w') or die("can't open file");
$q = mysql_query("SELECT * FROM creature_names");
$q2 = mysql_query("SELECT * FROM creature_proto");
echo "Running...";
while($row = mysql_fetch_array($q))
{
$row2 = mysql_fetch_array($q2);
$string = "replace into `creature_template` (`entry`, `difficulty_entry_1`, `difficulty_entry_2`, `difficulty_entry_3`, `KillCredit1`, `KillCredit2`, `modelid1`, `modelid2`, `modelid3`, `modelid4`, `name`, `subname`, `IconName`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction_A`, `faction_H`, `npcflag`, `speed_walk`, `speed_run`, `scale`, `rank`, `mindmg`, `maxdmg`, `dmgschool`, `attackpower`, `dmg_multiplier`, `baseattacktime`, `rangeattacktime`, `unit_class`, `unit_flags`, `unit_flags2`, `dynamicflags`, `family`, `trainer_type`, `trainer_spell`, `trainer_class`, `trainer_race`, `minrangedmg`, `maxrangedmg`, `rangedattackpower`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `resistance1`, `resistance2`, `resistance3`, `resistance4`, `resistance5`, `resistance6`, `spell1`, `spell2`, `spell3`, `spell4`, `spell5`, `spell6`, `spell7`, `spell8`, `PetSpellDataId`, `VehicleId`, `mingold`, `maxgold`, `AIName`, `MovementType`, `InhabitType`, `HoverHeight`, `Health_mod`, `Mana_mod`, `Armor_mod`, `RacialLeader`, `questItem1`, `questItem2`, `questItem3`, `questItem4`, `questItem5`, `questItem6`, `movementId`, `RegenHealth`, `equipment_id`, `mechanic_immune_mask`, `flags_extra`, `ScriptName`, `WDBVerified`) VALUES ('{$row[0]}', '0', '0', '0', '0', '0', ";
$string = $string . "'{$row['male_displayid']}', '{$row['female_displayid']}', '{$row['male_displayid2']}', '{$row['female_displayid2']}',";
$name = str_replace("\"", "\\\"", $row['name']);
$subname = str_replace("\"", "\\\"", $row['subname']);
$string = $string . "\"{$name}\", \"{$subname}\", '{$row['info_str']}', '0',"; // 0 = gossip menu ID
$string = $string . "'{$row2['minlevel']}', '{$row2['maxlevel']}', '0', '{$row2['faction']}', '{$row2['faction']}',"; // 0 = exp
$string = $string . "'{$row2['npcflags']}', '1', '1', '{$row2['scale']}',";
$string = $string . "'{$row['rank']}', '{$row2['mindamage']}', '{$row2['maxdamage']}', '0',"; // 0 = school damage
$attackpower = $row2['maxlevel'] * 2;
$string = $string . "'{$attackpower}', '1', '{$row2['attacktime']}', '{$row2['rangedattacktime']}',";
$string = $string . "'1', '0', '{$row2['npcflags']}', '8', '{$row['family']}', '0', '0', '0', '0', "; // `trainer_type`, `trainer_spell`, `trainer_class`, `trainer_race`,
$string = $string . "'{$row2['rangedmindamage']}', '{$row2['rangedmaxdamage']}', '{$attackpower}',";
$lootid = $row[0];
$string = $string . "'{$row['type']}', '0', '{$lootid}', '0', '0',";
$string = $string . "'{$row2['resistance1']}', ";
$string = $string . "'{$row2['resistance2']}', ";
$string = $string . "'{$row2['resistance3']}', ";
$string = $string . "'{$row2['resistance4']}', ";
$string = $string . "'{$row2['resistance5']}', ";
$string = $string . "'{$row2['resistance6']}', ";
$string = $string . "'{$row2['spell1']}', ";
$string = $string . "'{$row2['spell2']}', ";
$string = $string . "'{$row2['spell3']}', ";
$string = $string . "'{$row2['spell4']}', ";
$string = $string . "'{$row2['spell5']}', ";
$string = $string . "'{$row2['spell6']}', ";
$string = $string . "'{$row2['spell7']}', ";
$string = $string . "'{$row2['spell8']}', '0', "; // PetSpellDataId
$string = $string . "'{$row2['vehicleid']}', '{$row2['money']}', '{$row2['money']}',";
$string = $string . "'', '0', '3', '1', '1', '1', '1', '{$row2['boss']}', ";
$string = $string . "'{$row['questitem1']}', '{$row['questitem2']}', ";
$string = $string . "'{$row['questitem3']}', '{$row['questitem4']}', ";
$string = $string . "'{$row['questitem5']}', '{$row['questitem6']}', ";
$equipmentID = "0";
$string = $string . "'0', '1', '{$equipmentID}', '{$row2['modImmunities']}', ";
$string = $string . "'0', '', '12340'";
$string = $string . ");\n";
$q3 = mysql_query("SELECT * FROM loot_creatures WHERE `entryid` = '{$lootid}'");
while($lr = mysql_fetch_array($q3))
{
$string = $string . "replace into `creature_loot_template` VALUES (";
$string = $string . "'{$lootid}', '{$lr['itemid']}', '{$lr['normal10percentchance']}', '1', '0', '{$lr['mincount']}', '{$lr['maxcount']}'";
$string = $string . ");\n";
}
fwrite($fh, $string);
}
echo "<br>Done.";
fclose($fh);
mysql_close($connection);
?>