• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Adapt Code to PugiXML

Rajude

New Member
Joined
Jul 3, 2008
Messages
2
Reaction score
0
Hi, i'm trying to adapt this CODE to the new new version of TFS. The problem for me is that the new TFS uses PUGI XML, not LIBXML, and I don't know how to uses PUGI XML yet.

The code is created by MeNi.

Code:
int32_t LuaScriptInterface::luaDoCreateCustomMonster(lua_State* L)
{
    //doCreateCustomMonster(name, pos, outfit, health, spells, corpse, distance, experience )

    // created By MeNi for otland.net //

    uint64_t health, corpse, distance, experience;
    Outfit_t outfit;
    PositionEx pos;
    MonsterType* pobranyTyp = NULL;
    pobranyTyp = new MonsterType();

    experience = popNumber(L);
    distance = popNumber(L);
    corpse = popNumber(L);
    std::string spells = popString(L);
    health = popNumber(L);
    outfit = popOutfit(L);
    popPosition(L, pos);
    std::string name = popString(L);

    Monster* monster;

    pobranyTyp->spellAttackList.clear();

    pobranyTyp->health = health;
    pobranyTyp->healthMax = health;
    pobranyTyp->outfit = outfit;
    pobranyTyp->name = name;
    pobranyTyp->nameDescription = name;
    pobranyTyp->lookCorpse = corpse;
    pobranyTyp->targetDistance = distance;
    pobranyTyp->experience = experience;

    pobranyTyp->isSummonable =
    pobranyTyp->isIllusionable =
    pobranyTyp->isConvinceable =
    pobranyTyp->isWalkable =
    pobranyTyp->pushable = false;

    pobranyTyp->isAttackable =
    pobranyTyp->isHostile =
    pobranyTyp->canPushItems =
    pobranyTyp->canPushCreatures = true;

    pobranyTyp->defense = 50;
    pobranyTyp->armor = 80;
    pobranyTyp->baseSpeed = 200;
    pobranyTyp->changeTargetSpeed =
    pobranyTyp->changeTargetChance = 0;

    xmlDocPtr doc = xmlParseMemory(spells.c_str(), spells.length());
    xmlNodePtr root = xmlDocGetRootElement(doc);

    xmlNodePtr tmpNode = root->children;

    while (tmpNode)
    {
        if (!xmlStrcmp(tmpNode->name, (const xmlChar*)"attack"))
        {
            spellBlock_t sb;
            if (g_monsters.deserializeSpell(tmpNode, sb, "doCreateCustomMonster"))
                pobranyTyp->spellAttackList.push_back(sb);
        }
        tmpNode = tmpNode->next;
    }

    monster = Monster::createMonster(pobranyTyp);

    if (!g_game.placeCreature(monster, pos, false, false))
    {
        delete monster;

        lua_pushboolean(L, true);
        return 1;
    }

    ScriptEnvironment* env = getScriptEnv();
    lua_pushnumber(L, env->addThing((Thing*)monster));
    return 1;
}

The problem is here:

Code:
 xmlDocPtr doc = xmlParseMemory(spells.c_str(), spells.length());
    xmlNodePtr root = xmlDocGetRootElement(doc);

    xmlNodePtr tmpNode = root->children;

    while (tmpNode)
    {
        if (!xmlStrcmp(tmpNode->name, (const xmlChar*)"attack"))
        {
            spellBlock_t sb;
            if (g_monsters.deserializeSpell(tmpNode, sb, "doCreateCustomMonster"))
                pobranyTyp->spellAttackList.push_back(sb);
        }
        tmpNode = tmpNode->next;
    }

So, someone knows what do to adapt this code to PUGI-XML? Thank you.
 
Here you go
Code:
  pugi::xml_document doc;
  pugi::xml_parse_result result = doc.load_buffer_inplace(spells.c_str(), spells.length());

  // if (!result) {
  //  std::cerr << "Something is wrong ;(" << std::endl;
  //  return false;
  // }

  pugi::xml_node root = doc.child("attacks");

  if (root) {
    for (pugi::xml_node tmpNode = root.first_child(); tmpNode; tmpNode = tmpNode.next_sibling())
    {
      spellBlock_t sb;
      if (g_monsters.deserializeSpell(tmpNode, sb, "doCreateCustomMonster")) {
        pobranyTyp->spellAttackList.push_back(sb);
      }
    }
  }
 
The function -> doc.load_buffer_inplace(spells.c_str(), spells.length()) <- doesn't accept the first "spells" because:

std::string spells
Error: argument of type "const char *" is incompatible with parameter of type void *"

I already tryied with load_buffer, it compiles, the monster is created, but without the attacks...
 
Last edited:
Back
Top