• 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!

Help with c++ change in MonsterType:getAttackList() TFS 1.2

bizao030188

Member
Joined
Jun 4, 2012
Messages
50
Solutions
2
Reaction score
7
Hello friends!
I am working in a system that needs to get the name of the attacks from monster xml.
I found out in luascript.cpp the correspondent function but it does not have the option to return the name:

C++:
int LuaScriptInterface::luaMonsterTypeGetAttackList(lua_State* L)
{
    // monsterType:getAttackList()
    MonsterType* monsterType = getUserdata<MonsterType>(L, 1);
    if (!monsterType) {
        lua_pushnil(L);
        return 1;
    }

    lua_createtable(L, monsterType->info.attackSpells.size(), 0);

    int index = 0;
    for (const auto& spellBlock : monsterType->info.attackSpells) {
        lua_createtable(L, 0, 8);

        setField(L, "chance", spellBlock.chance);
        setField(L, "isCombatSpell", spellBlock.combatSpell ? 1 : 0);
        setField(L, "isMelee", spellBlock.isMelee ? 1 : 0);
        setField(L, "minCombatValue", spellBlock.minCombatValue);
        setField(L, "maxCombatValue", spellBlock.maxCombatValue);
        setField(L, "range", spellBlock.range);
        setField(L, "speed", spellBlock.speed);
        pushUserdata<CombatSpell>(L, static_cast<CombatSpell*>(spellBlock.spell));
        lua_setfield(L, -2, "spell");

        lua_rawseti(L, -2, ++index);
    }
    return 1;
}

so I want to add a new field setField(L, "name", spellBlock.name); but I got some errors saying that struct spellBlock has no member called "name" . So the question is, where else should I insert the "name" field?

Thanks in advance!
 
Last edited:
Solution

Thanks!
It worked. For people who also need this:

In monster.h after
Code:
int32_t maxCombatValue = 0;
add:
Code:
std::string name;

In monsters.h
after:
Code:
maxCombatValue(other.maxCombatValue),
add:
Code:
name(other.name),
after:
Code:
int32_t maxCombatValue = 0;
add:
std::string name = "none";

In monsters.cpp
after:
Code:
    if ((attr = node.attribute("min"))) {
        sb.minCombatValue = pugi::cast<int32_t>(attr.value());
    }
add:
Code:
    if ((attr = node.attribute("name"))) {
        sb.name = attr.as_string();
    }

On function luaMonsterTypeGetAttackList in luascript.cpp...

Thanks!
It worked. For people who also need this:

In monster.h after
Code:
int32_t maxCombatValue = 0;
add:
Code:
std::string name;

In monsters.h
after:
Code:
maxCombatValue(other.maxCombatValue),
add:
Code:
name(other.name),
after:
Code:
int32_t maxCombatValue = 0;
add:
std::string name = "none";

In monsters.cpp
after:
Code:
    if ((attr = node.attribute("min"))) {
        sb.minCombatValue = pugi::cast<int32_t>(attr.value());
    }
add:
Code:
    if ((attr = node.attribute("name"))) {
        sb.name = attr.as_string();
    }

On function luaMonsterTypeGetAttackList in luascript.cpp
change:
Code:
lua_createtable(L, 0, 8);
to:
Code:
lua_createtable(L, 0, 9);
and add after:
Code:
setField(L, "maxCombatValue", spellBlock.maxCombatValue);
this:
Code:
setField(L, "name", spellBlock.name);
 
Solution
Back
Top