• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Simple monster loot for znote

huh now that i see that remove this line from monsters.php, it seems i left out something unfinished here lol:
PHP:
        $item_range = $monster->getItemLevelRange();
can't not find anything related to getitemlevelrange
Lua:
<?php
echo "(0) starting ";
require_once('monster_classes.php');

/* CONFIG */
$data_location = 'C:/Users/felip/OneDrive/Documentos/GitHub/pro-ot/data';
$monster_dir = '/monster/';
$items_dir = '/items/';
$monsters_file = 'monsters.xml';
$items_file = 'items.xml';
$cache_dir = 'monsters';
/* CONFIG */

if (file_exists($cache_dir)) {
    echo "(1) cache exists ";
    die();
}
mkdir($cache_dir, 0777, true);
echo "(2) mkdir done ";

$items_loaded = array();
$items_xml = simplexml_load_file($data_location . $items_dir . $items_file);
echo "(3) loaded items.xml ";
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 = simplexml_load_file($data_location . $monster_dir . $monsters_file);
echo "(5) loaded monsters.xml ";

$monsters_paths = array();

foreach ($monsters_xml->children() as $monster) {
    array_push($monsters_paths, $data_location . $monster_dir . $monster['file']);
}

echo "(6) loaded monsters ";

$monsters_loaded = array();
foreach ($monsters_paths as $monster_path) {
    $monster_xml = simplexml_load_file($monster_path);
    $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));
}

echo "(8) cache files done ";

?>
Code:
 
because that's not the monsters.php file that's the monster_loader.php
 
edit: manage to solve it thanks
Code:
    <!-- raids -->
        <!-- <monster name="Orc1" file="orcs/Orc Sambackpack.xml"/> -->
    <!-- <monster name="Orc Warlord1" file="orcs/orcarmor.xml"/> -->
    <!-- <monster name="Orc Warlord2" file="orcs/orchelmet.xml"/> -->
    <!-- <monster name="Orc Warlord3" file="orcs/orcshield.xml"/> -->
    <!-- <monster name="Draken Elite" file="monsters/zao/zao elite.xml"/> -->
    <!-- <monster name="Draken Spellweaver" file="monsters/Lizards/draken spellweaver.xml"/> -->
removed these, and the code you told me now it works :D
Post automatically merged:

page 100% finished... thanks for share script
View attachment 69811
View attachment 69812
can you share with us how you did to load monster looktype and items please?
 
Last edited:
page 100% finished... thanks for share script
View attachment 69811
View attachment 69812
Possible to convert for OTServBR Canary?

Reading all folders and files in monster folder since we use .lua for monsters?

I mean should it not basically be to convert things in here?


PHP:
$monsters_xml = simplexml_load_file($data_location . $monster_dir . $monsters_file);

$monsters_paths = array();

foreach ($monsters_xml->children() as $monster) {
    array_push($monsters_paths, $data_location . $monster_dir . $monster['file']);
}

$monsters_loaded = array();
foreach ($monsters_paths as $monster_path) {
    $monster_xml = simplexml_load_file($monster_path);
    $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);
}

foreach ($monsters_loaded as $monster) {
    $cache_file = fopen($cache_dir . '/' . $monster->getName() . '.cache', "w");
    fwrite($cache_file, serialize($monster));
}

?>
 
best way would be generating jsons from lua from monstertypes rather than parsing lua ;d
 
Back
Top