- Joined
- Sep 16, 2004
- Messages
- 117
- Reaction score
- 1
I'm working on rebuilding worldXX-npc.scp files based on GP client, but i'm stuck with the npcpos list because the client is missing data (flag, type, israngecheck) maybe is_obj is one of those, but still 2 missing.
Server
Client
Server
Code:
[NpcPos] Flags Index PosX PosY Type IsRangeCheck
0 0 1 36 41 3 1
Client
Code:
<world id="1" name="world1" type="0" map_file="world_01.mcl" terrain_mesh="" icon="J_icn_map1" m_code="1" t_max_x="1" t_max_z="1" gpsorder="1" allowedwar="0" warcontrol="0" >
<world_npc id="1" npc_name="npc01-0001" x="36" y="41" is_obj="0" />
PHP:
<?php
function xml2array($contents, $get_attributes=1) {
if(!$contents) return array();
if(!function_exists('xml_parser_create')) {
//print "'xml_parser_create()' function not found!";
return array();
}
//Get the XML parser of PHP - PHP must have this module for the parser to work
$parser = xml_parser_create();
xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 );
xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 1 );
xml_parse_into_struct( $parser, $contents, $xml_values );
xml_parser_free( $parser );
if(!$xml_values) return;//Hmm...
//Initializations
$xml_array = array();
$parents = array();
$opened_tags = array();
$arr = array();
$current = &$xml_array;
//Go through the tags.
foreach($xml_values as $data) {
unset($attributes,$value);//Remove existing values, or there will be trouble
//This command will extract these variables into the foreach scope
// tag(string), type(string), level(int), attributes(array).
extract($data);//We could use the array by itself, but this cooler.
$result = '';
if($get_attributes) {//The second argument of the function decides this.
$result = array();
if(isset($value)) $result['value'] = $value;
//Set the attributes too.
if(isset($attributes)) {
foreach($attributes as $attr => $val) {
if($get_attributes == 1) $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr'
/** :TODO: should we change the key name to '_attr'? Someone may use the tagname 'attr'. Same goes for 'value' too */
}
}
} elseif(isset($value)) {
$result = $value;
}
//See tag status and do the needed.
if($type == "open") {//The starting of the tag '<tag>'
$parent[$level-1] = &$current;
if(!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag
$current[$tag] = $result;
$current = &$current[$tag];
} else { //There was another element with the same tag name
if(isset($current[$tag][0])) {
array_push($current[$tag], $result);
} else {
$current[$tag] = array($current[$tag],$result);
}
$last = count($current[$tag]) - 1;
$current = &$current[$tag][$last];
}
} elseif($type == "complete") { //Tags that ends in 1 line '<tag />'
//See if the key is already taken.
if(!isset($current[$tag])) { //New Key
$current[$tag] = $result;
} else { //If taken, put all things inside a list(array)
if((is_array($current[$tag]) and $get_attributes == 0)//If it is already an array...
or (isset($current[$tag][0]) and is_array($current[$tag][0]) and $get_attributes == 1)) {
array_push($current[$tag],$result); // ...push the new element into that array.
} else { //If it is not an array...
$current[$tag] = array($current[$tag],$result); //...Make it an array using using the existing value and the new value
}
}
} elseif($type == 'close') { //End of tag '</tag>'
$current = &$parent[$level-1];
}
}
return($xml_array);
}
function shoplist( $r )
{
$t = " ";
$d = 0;
$c = count($r);
$s = "[ShopLst] NpcsIdx NSetIdx ItemKind ItemOpt ReputationClass DurationIdx Price\n";
if($c == 2)
{
$id = $r["attr"]["id"];
foreach($r["item"] as $k => $v)
{
$s .= $d.$t.$id.$t.$v["attr"]["slot_id"].$t.$v["attr"]["item_id"].$t.$v["attr"]["option"].$t.$v["attr"]["reputation_class"].$t.$v["attr"]["duration_id"].$t.$v["attr"]["price"]."\n";
$d++;
}
return $s;
}
for($i = 0; $i < $c; $i++)
{
$id = $r[$i]["attr"]["id"];
if(count($r[$i]["item"]) == 1 )
{
$v = $r[$i]["item"];
$s .= $d.$t.$id.$t.$v["attr"]["slot_id"].$t.$v["attr"]["item_id"].$t.$v["attr"]["option"].$t.$v["attr"]["reputation_class"].$t.$v["attr"]["duration_id"].$t.$v["attr"]["price"]."\n";
$d++;
continue;
}
foreach($r[$i]["item"] as $k => $v)
{
$s .= $d.$t.$id.$t.$v["attr"]["slot_id"].$t.$v["attr"]["item_id"].$t.$v["attr"]["option"].$t.$v["attr"]["reputation_class"].$t.$v["attr"]["duration_id"].$t.$v["attr"]["price"]."\n";
$d++;
}
}
return $s;
}
function skilllist( $r )
{
$t = " ";
$d = 0;
$c = count($r);
$s = "[SkillLst] NSetIdx NpcsIdx SkillIdx SkillLv\n";
if($c == 2)
{
$id = $r["attr"]["id"];
foreach($r["skill"] as $k => $v)
{
//fwrite($o, $d.$t.$id.$t.$v["attr"]["id"].$t.$v["attr"]["day"].$t.$v["attr"]["hour"]."\n");
$s .= $d.$t.$v["attr"]["slot_id"].$t.$id.$t.$v["attr"]["id"].$t.$v["attr"]["level"]."\n";
$d++;
}
return $s;
}
for($i = 0; $i < $c; $i++)
{
$id = $r["attr"]["id"];
if(count($r[$i]["skill"]) == 1 )
{
$v = $r[$i]["skill"];
$s .= $d.$t.$v["attr"]["slot_id"].$t.$id.$t.$v["attr"]["id"].$t.$v["attr"]["level"]."\n";
$d++;
continue;
}
foreach($r[$i]["skill"] as $k => $v)
{
//fwrite($o, $d.$t.$id.$t.$v["attr"]["id"].$t.$v["attr"]["day"].$t.$v["attr"]["hour"]."\n");
$s .= $d.$t.$v["attr"]["slot_id"].$t.$id.$t.$v["attr"]["id"].$t.$v["attr"]["level"]."\n";
$d++;
}
}
return $s;
}
function warplist( $r )
{
$t = " ";
$d = 0;
$c = count($r);
$s = "[WarpLst] NpcsIdx NSetIdx TargetIdx LV Fee Type\n";
if($c == 2)
{
$id = $r["attr"]["id"];
foreach($r["warp_list"] as $k => $v)
{
$s .= $d.$t.$id.$t.$v["attr"]["order"].$t.$v["attr"]["target_id"].$t.$v["attr"]["level"].$t.$v["attr"]["Fee"].$t.$v["attr"]["type"]."\n";
$d++;
}
return $s;
}
for($i = 0; $i < $c; $i++)
{
$id = $r[$i]["attr"]["id"];
if(count($r[$i]["warp_list"]) == 1 )
{
$v = $r[$i]["warp_list"];
$s .= $d.$t.$id.$t.$v["attr"]["order"].$t.$v["attr"]["target_id"].$t.$v["attr"]["level"].$t.$v["attr"]["Fee"].$t.$v["attr"]["type"]."\n";
$d++;
continue;
}
foreach($r[$i]["warp_list"] as $k => $v)
{
$s .= $d.$t.$id.$t.$v["attr"]["order"].$t.$v["attr"]["target_id"].$t.$v["attr"]["level"].$t.$v["attr"]["Fee"].$t.$v["attr"]["type"]."\n";
$d++;
}
}
return $s;
}
$contents = file_get_contents('cabal.xml');
$r = xml2array($contents);
$c = count($r["cabal"]["cabal_world"]["world"]);
$c = 2;
for($i = 0; $i < $c; $i++)
{
//$shop[$r["cabal"]["cabal_world"]["world"][$i]["attr"]["id"]] = shoplist($r["cabal"]["cabal_world"]["world"][$i]["shop"]);
//$skill[$r["cabal"]["cabal_world"]["world"][$i]["attr"]["id"]] = skilllist($r["cabal"]["cabal_world"]["world"][$i]["trainer"]);
$warp[$r["cabal"]["warp_npc"]["world"][$i]["attr"]["id"]] = warplist($r["cabal"]["warp_npc"]["world"][$i]["npc"]);
}
print_r($warp);
die();
?>