johnsamir
Advanced OT User
im using this file it's a modified version taken from here i've edited it a bit because of problems Simple monster loot for znote (https://otland.net/threads/simple-monster-loot-for-znote.274296/page-2)
im facing this, ofcourse the file do exists
im facing this, ofcourse the file do exists
Code:
(0) starting (1) cache exists (3) loaded items.xml (4) loaded items Error: monsters.xml file does not exist at C:/Users/slim/Desktop/data/monsters/monsters.xml
Lua:
<?php
###### MONSTER LOOT CHECKER ######
###### VERSION: 1.5
echo "(0) starting ";
require_once('monster_classes.php');
/* CONFIG */
$data_location = 'C:/Users/felip/Documents/GitHub/pro-ot/data';
$monster_dir = '/monsters/';
$items_dir = '/items/';
$monsters_file = 'monsters.xml';
$items_file = 'items.xml';
$cache_dir = 'monsters';
/* CONFIG */
if (file_exists($cache_dir)) {
echo "(1) cache exists ";
} else {
if (mkdir($cache_dir, 0777, true)) {
echo "(2) mkdir done ";
} else {
die("Error: Could not create cache directory");
}
}
$items_loaded = array();
$items_xml_path = $data_location . $items_dir . $items_file;
if (file_exists($items_xml_path)) {
$items_xml = simplexml_load_file($items_xml_path);
if ($items_xml === false) {
die('Error: Could not load items.xml');
}
echo "(3) loaded items.xml ";
} else {
die("Error: items.xml file does not exist at $items_xml_path");
}
foreach ($items_xml->children() as $item) {
if (empty(strval($item['fromid']))) {
$items_loaded[(int)strval($item['id'])] = strval($item['name']);
continue;
}
$fromid = (int) strval($item['fromid']);
$toid = (int) strval($item['toid']);
for ($i = $fromid; $i <= $toid; $i++) {
$items_loaded[$i] = strval($item['name']);
}
}
echo "(4) loaded items ";
$monsters_xml_path = $data_location . $monster_dir . $monsters_file;
if (file_exists($monsters_xml_path)) {
$monsters_xml = simplexml_load_file($monsters_xml_path);
if ($monsters_xml === false) {
die('Error: Could not load monsters.xml');
}
echo "(5) loaded monsters.xml ";
} else {
die("Error: monsters.xml file does not exist at $monsters_xml_path");
}
$monsters_paths = array();
foreach ($monsters_xml->children() as $monster) {
$monster_file_path = $data_location . $monster_dir . $monster['file'];
if (file_exists($monster_file_path)) {
array_push($monsters_paths, $monster_file_path);
} else {
echo "Warning: Monster file does not exist at $monster_file_path\n";
}
}
echo "(6) loaded monsters paths ";
$monsters_loaded = array();
foreach ($monsters_paths as $monster_path) {
$monster_xml = simplexml_load_file($monster_path);
if ($monster_xml === false) {
echo "Warning: Could not load monster file at $monster_path\n";
continue;
}
$monster = new Monster();
$basename = basename($monster_path, '.xml');
$basename = str_replace('_', " ", $basename);
$monster->setName($basename);
$monster->setExperience((int)strval($monster_xml['experience']));
$monster->setHealth((int)strval($monster_xml->health['max']));
if ($monster_xml->loot->item == null) {
array_push($monsters_loaded, $monster);
continue;
}
foreach ($monster_xml->loot->item as $item) {
$item_o = new Item();
if (!empty(strval($item['name']))) {
$item_o->setName(strval($item['name']));
}
if (!empty(strval($item['id']))) {
$offset = (int)strval($item['id']);
if (array_key_exists($offset, $items_loaded)) {
$item_o->setName($items_loaded[$offset]);
}
}
if (!empty(strval($item['countmax']))) {
$item_o->setCountMax((int)strval($item['countmax']));
}
if (!empty(strval($item['chance']))) {
$item_o->setChance((int)strval($item['chance']));
}
$monster->addToLoot($item_o);
}
array_push($monsters_loaded, $monster);
}
echo "(7) monster classes done ";
foreach ($monsters_loaded as $monster) {
$cache_file = fopen($cache_dir . '/' . $monster->getName() . '.cache', "w");
fwrite($cache_file, serialize($monster));
fclose($cache_file);
}
echo "(8) cache files done ";
?>