empathon
15.10.2006, 08:38
Npcdata converter by me:
<?php
//*************** DB insert script by empathon (c) 2006 ***********************//
//************************************************** *****************************//
$db_host = 'localhost';
$db_user = 'root';
$db_pass = 'pass';
//Functions
function cut($string, $open_tag, $end_tag)
{
$pos_start = strpos($string, $open_tag) + strlen($open_tag);
$pos_end = strpos($string, $end_tag, $pos_start);
$cut = substr($string, $pos_start, $pos_end - $pos_start);
return $cut;
}
//Main program
echo "<span style=\"font-size: x-small; font-family: Verdana\">";
if (file_exists("server_files/npcdata.txt")&&file_exists("client_files/npcname-e.txt"))
{
echo "Files OK... ";
$npcdata = file ('server_files/npcdata.txt');
$npcdata_count = sizeof($npcdata);
$npcname = file ('client_files/npcname-e.txt');
$npcname_count = sizeof($npcname);
$brace = array ("[", "]");
set_time_limit(0);
$npcids = array_fill(0, $npcname_count, 0);
for ($i = 0; $i < $npcname_count; $i++)
{
$npcids[$i] = cut( $npcname[$i], "id=", " ");
}
//DB
$connection = mysql_connect($db_host, $db_user, $db_pass)
or die ("Cant connect to database.");
mysql_select_db ("l2drop") or die ("Cant select database.");
//Importing loop
for ( $i = 0; $i < $npcdata_count; $i++)
{
$npc = explode(" ", $npcdata[$i]);
$id = $npc[2];
$server_name = str_replace( $brace, "", $npc[3]);
$client_line = array_search( $id, $npcids);
// echo "client line =".$client_line;
$client_name = cut ($npcname[$client_line], "name=[", "] ");
$client_nick = cut ($npcname[$client_line], "nick=[", "] ");
$nickcolor = cut ($npcname[$client_line], "nickcolor=", " ");
if ($nickcolor == "default") $nickcolor = "d"; elseif ($nickcolor == "quest") $nickcolor = "q"; elseif ($nickcolor == "raid") $nickcolor = "r";
$client_name = str_replace("'", "\'", $client_name);
$client_nick = str_replace("'", "\'", $client_nick);
// if ( $client_nick == "" ) $client_nick = none;
// if ( $client_name == "" ) $client_name = none;
$type = $npc[1];
$level = cut ( $npcdata[$i], "level=", " ");
$aggressive = 0; /* << */
$acquire_exp = pow( $level, 2) * cut( $npcdata[$i], "acquire_exp_rate=", " ");
$acquire_sp = cut( $npcdata[$i], "acquire_sp=", " ");
$clan = cut( $npcdata[$i], "clan={@", "} ");
$clan_help_range = $clan = cut( $npcdata[$i], "clan_help_range=", " ");
$race = cut( $npcdata[$i], "race=", " ");
$undying = cut( $npcdata[$i], "undying=", " ");
// if ($undying == 1) $undying = TRUE; else $undying = FALSE;
if ( $type == "boss") $hp_multipler = 2.38; else $hp_multipler = 1.58;
$org_hp = cut( $npcdata[$i], "org_hp=", " ") * $hp_multipler;
$org_hp_regen = cut( $npcdata[$i], "org_hp_regen=", " ");
$org_mp = cut ( $npcdata[$i], "org_mp=", " ");
$org_mp_regen = cut ( $npcdata[$i], "org_mp_regen=", " ");
$base_attack_type = cut ( $npcdata[$i], "base_attack_type=", " ");
$base_attack_range = cut ( $npcdata[$i], "base_attack_range=", " ");
$base_attack_speed = cut ( $npcdata[$i], "base_attack_speed=", " ");
$base_magic_attack = cut ( $npcdata[$i], "base_magic_attack=", " ");
$base_defend = cut ( $npcdata[$i], "base_defend=", " ");
$base_magic_defend = cut ( $npcdata[$i], "base_magic_defend=", " ");
$soulshot_count = cut ( $npcdata[$i], "soulshot_count=", " ");
$spiritshot_count = cut ( $npcdata[$i], "spiritshot_count=", " ");
$base_physical_attack = cut ( $npcdata[$i], "base_physical_attack=", " ");
$base_physical_attack = ceil ( $base_physical_attack);
$str = cut ( $npcdata[$i], "str=", " ");
$int = cut ( $npcdata[$i], "int=", " ");
$dex = cut ( $npcdata[$i], "dex=", " ");
$wit = cut ( $npcdata[$i], "wit=", " ");
$con = cut ( $npcdata[$i], "con=", " ");
$men = cut ( $npcdata[$i], "men=", " ");
$query = "INSERT INTO npcdata VALUES($id, '$server_name', '$client_name', '$client_nick', '$type', $level, $aggressive, $acquire_exp, $acquire_sp, '$clan', $clan_help_range, '$race', $undying, $org_hp, $org_hp_regen, $org_mp, $org_mp_regen, '$base_attack_type', $base_attack_range, $base_attack_speed, $base_magic_attack, $base_defend, $base_magic_defend, $soulshot_count, $spiritshot_count, '$nickcolor', $base_physical_attack, $str, $int, $dex, $wit, $con, $men, '$passive_skills', '$active_skills')";
// echo $query."<br />";
$result = mysql_query ($query) or die ("<b>Query has been failed. [</b> $query <b>]</b>");
}
// mysql_free_result($result);
mysql_close($connection);
echo "Done.";
}
else
{
echo "Server and client files not full. Script needs npcdata.txt\n";
}
echo "</span>";
?>
db script:
CREATE TABLE npcdata ( id SMALLINT UNSIGNED NOT NULL, server_name VARCHAR(40), client_name VARCHAR(40), client_nick VARCHAR(16), type CHAR(20), level SMALLINT UNSIGNED, aggressive BOOL, acquire_exp DECIMAL(15,0) UNSIGNED, acquire_sp DECIMAL(15,0), clan VARCHAR(20), clan_help_range SMALLINT UNSIGNED, race CHAR(20), undying BOOL, org_hp INT UNSIGNED, org_hp_regen SMALLINT UNSIGNED, org_mp SMALLINT UNSIGNED, org_mp_regen SMALLINT UNSIGNED, base_attack_type VARCHAR(10), base_attack_range SMALLINT UNSIGNED, base_attack_speed SMALLINT UNSIGNED, base_magic_attack DECIMAL(5, 0) UNSIGNED, base_defend DECIMAL(5, 0) UNSIGNED, base_magic_defend DECIMAL(5, 0) UNSIGNED, soulshot_count SMALLINT UNSIGNED, spiritshot_count SMALLINT UNSIGNED, nickcolor VARCHAR(1), base_physical_attack SMALLINT UNSIGNED, str SMALLINT UNSIGNED, inte SMALLINT UNSIGNED, dex SMALLINT UNSIGNED, wit SMALLINT UNSIGNED, con SMALLINT UNSIGNED, men SMALLINT UNSIGNED, passive_skills TEXT, active_skills TEXT, PRIMARY KEY(id));
for drop table:
<?php
//*************** DB insert script by empathon (c) 2006 ***********************//
//************************************************** *****************************//
$db_host = 'localhost';
$db_user = 'root';
$db_pass = 'pass';
//Functions
function cut($string, $open_tag, $end_tag)
{
$pos_start = strpos($string, $open_tag) + strlen($open_tag);
$pos_end = strpos($string, $end_tag, $pos_start);
$cut = substr($string, $pos_start, $pos_end - $pos_start);
return $cut;
}
//Main program
echo "<span style=\"font-size: x-small; font-family: Verdana\">";
if (file_exists("server_files/npcdata.txt"))
{
echo "Files OK... ";
$npcdata = file ('server_files/npcdata.txt');
$npcdata_count = sizeof($npcdata);
// $fraction = file ('fraction.txt');
$brace = array ("{", "}", "]", "[");
set_time_limit(0);
//DB
$connection = mysql_connect($db_host, $db_user, $db_pass) or die ("Cant connect to database.");
mysql_select_db ("l2drop") or die ("Cant select database.");
//Importing loop
echo "<br>";
$count = 1;
for ( $i = 0; $i < $npcdata_count; $i++)
{
$drops = cut ( $npcdata[$i], "additional_make_multi_list=", " ");
if ($drops == '{}') continue;
$npc = explode(" ", $npcdata[$i]);
$id = $npc[2];
echo "<b>".$i."</b> for npc id <i>".$id."</i><br>";
$drop_groups = explode ( "};{{", $drops);
$groups_number = sizeof($drop_groups);
for ($group = 0; $group < $groups_number; $group++)
{
//Group
echo "---> ".$group;
$group_sep = explode( "}};", $drop_groups[$group]);
$group_chance = str_replace ( $brace, "", $group_sep[1]);
echo " and group drop chance = ".$group_chance." <b>(</b> "; // << Group chance
$drops_sep = explode( "};{", $group_sep[0]);
echo $group_sep[0]." <b>)</b><br>";
$drop_count = sizeof($drops_sep);
echo $drop_count." exp.:".$drops_sep[0]."<br>";
for ($drop_i = 0; $drop_i < $drop_count; $drop_i++)
{
//Drop
echo "=======>".$drop_i."<br>";
$drop = str_replace( $brace, "", $drops_sep[$drop_i]);
$param = explode ( ";", $drop);
$id_npc = $id;
$item_name = str_replace( "'", "\'", $param[0]);
$drop_min = $param[1];
$drop_max = $param[2];
$per1 = ( $param[3] * $group_chance ) / 100;
$query = "INSERT INTO drop_rate VALUES( $id_npc, '$item_name', $drop_min, $drop_max, $per1, $count)";
$result = mysql_query ($query) or die ("<b>Query has been failed. [</b> $query <b>]</b>");
$count++;
}
}
// echo $query."<br />";
}
// mysql_free_result($result);
mysql_close($connection);
echo "Done.";
}
else
{
echo "Server and client files not full.\n";
}
echo "</span>";
?>
db script for that:
CREATE TABLE drop_rate ( id_npc SMALLINT UNSIGNED , item_name VARCHAR(40), drop_min INT UNSIGNED, drop_max INT UNSIGNED, per1 FLOAT UNSIGNED, id INT UNSIGNED NOT NULL, PRIMARY KEY(id));
Spoil is similar just look into files and change few lines. Its just part of full script :P GL