//doCreateCustomMonster(....)
lua_register(luaState, "doCreateCustomMonster", LuaScriptInterface::luaDoCreateCustomMonster);
int32_t LuaScriptInterface::luaDoCreateCustomMonster(lua_State* L)
{
//doCreateCustomMonster(name, pos, outfit, health, attspell,defensespell,defense,armor,baseSpeed,exp,skull)
// created By MeNi for otland.net //
ScriptEnvironment* env = getScriptEnv();
MonsterType* pobranyTyp = new MonsterType();
Monster* monster;
int64_t health, defense, armor, baseSpeed, experience;
Outfit_t outfit;
Skulls_t skull;
Position pos;
skull = (Skulls_t)getNumber<uint32_t>(L, -1);
experience = getNumber<uint32_t>(L, -1);
baseSpeed = getNumber<uint32_t>(L, -1);
armor = getNumber<uint32_t>(L, -1);
defense = getNumber<uint32_t>(L, -1);
std::string defensespells = popString(L);
std::string attackspells = popString(L);
health = getNumber<uint32_t>(L, -1);
outfit = getOutfit(L, -1);
pushPosition(L, pos);
std::string name = popString(L);
pobranyTyp->info.attackSpells.clear();
pobranyTyp->info.health = health;
pobranyTyp->info.healthMax = health;
pobranyTyp->info.outfit = outfit;
pobranyTyp->name = name;
pobranyTyp->nameDescription = name;
pobranyTyp->info.lookcorpse = 0;
pobranyTyp->info.targetDistance = 1;
pobranyTyp->info.experience = experience;
pobranyTyp->info.isSummonable = false;
pobranyTyp->info.isIllusionable = false;
pobranyTyp->info.isConvinceable = false;
pobranyTyp->info.pushable = false;
pobranyTyp->info.isAttackable = true;
pobranyTyp->info.isHostile = true;
pobranyTyp->info.isConvinceable = true;
pobranyTyp->info.canPushItems = true;
pobranyTyp->info.canPushCreatures = true;
pobranyTyp->info.conditionImmunities |= CONDITION_PARALYZE;
pobranyTyp->info.conditionImmunities |= CONDITION_DRUNK;
pobranyTyp->info.conditionImmunities |= CONDITION_INVISIBLE;
pobranyTyp->info.defense = defense;
pobranyTyp->info.armor = armor;
pobranyTyp->info.skull = skull;
pobranyTyp->info.baseSpeed = baseSpeed;
pobranyTyp->info.changeTargetSpeed = 0;
pobranyTyp->info.changeTargetChance = 0;
if (!attackspells.empty()) {
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file("data\spells\spells.xml");
// if (!result) {
// std::cerr << "Something is wrong ;(" << std::endl;
// return false;
// }
pugi::xml_node root1 = doc.child("attack");
if (root1) {
for (pugi::xml_node tmpNode = root1.first_child(); tmpNode; tmpNode = tmpNode.next_sibling())
{
spellBlock_t sb;
if (g_monsters.deserializeSpell(tmpNode, sb, "doCreateCustomMonster")) {
pobranyTyp->info.attackSpells.push_back(sb);
}
}
}
// if (!result) {
// std::cerr << "Something is wrong ;(" << std::endl;
// return false;
// }
pugi::xml_node root2 = doc.child("healing");
if (root2) {
for (pugi::xml_node tmpNode = root2.first_child(); tmpNode; tmpNode = tmpNode.next_sibling())
{
spellBlock_t sb;
if (g_monsters.deserializeSpell(tmpNode, sb, "doCreateCustomMonster")) {
pobranyTyp->info.defenseSpells.push_back(sb);
}
}
}
monster = Monster::createMonster(getString(L, 1));
if (!g_game.placeCreature(monster, pos, false, false))
{
delete monster;
lua_pushboolean(L, false);
return 1;
}
lua_pushnumber(L, env->addThing((Thing*)monster));
return 1;
}
}