int32_t LuaInterface::luaDoCreateCustomMonster(lua_State* L)
{
//doCreateCustomMonster(name, pos, outfit, health, attspell,defensespell,defense,armor,baseSpeed,exp)
// created By MeNi for otland.net //
ScriptEnviroment* env = getEnv();
MonsterType* pobranyTyp = new MonsterType();
Monster* monster;
int64_t health, defense, armor, baseSpeed,experience;
Outfit_t outfit;
PositionEx pos;
experience = popNumber(L);
baseSpeed = popNumber(L);
armor = popNumber(L);
defense = popNumber(L);
std::string defensespells = popString(L);
std::string attackspells = popString(L);
health = popNumber(L);
outfit = popOutfit(L);
popPosition(L, pos);
std::string name = popString(L);
pobranyTyp->spellAttackList.clear();
pobranyTyp->health = health;
pobranyTyp->healthMax = health;
pobranyTyp->outfit = outfit;
pobranyTyp->name = name;
pobranyTyp->nameDescription = name;
pobranyTyp->lookCorpse = 0;
pobranyTyp->targetDistance = 1;
pobranyTyp->experience = experience;
pobranyTyp->isSummonable = false;
pobranyTyp->isIllusionable = false;
pobranyTyp->isConvinceable = false;
pobranyTyp->isWalkable = true;
pobranyTyp->pushable = false;
pobranyTyp->isAttackable = true;
pobranyTyp->isHostile = true;
pobranyTyp->canPushItems = true;
pobranyTyp->canPushCreatures = true;
pobranyTyp->conditionImmunities |= CONDITION_PARALYZE;
pobranyTyp->conditionImmunities |= CONDITION_DRUNK;
pobranyTyp->conditionImmunities |= CONDITION_INVISIBLE;
pobranyTyp->defense = defense;
pobranyTyp->armor = armor;
pobranyTyp->skull = SKULL_RED;
pobranyTyp->baseSpeed = baseSpeed;
pobranyTyp->changeTargetSpeed = 0;
pobranyTyp->changeTargetChance = 0;
if (!attackspells.empty()){
xmlNodePtr root_attack = xmlDocGetRootElement(xmlParseMemory(attackspells.c_str(), attackspells.length()));
xmlNodePtr tmpNode_attack = root_attack->children;
while (tmpNode_attack)
{
if (!xmlStrcmp(tmpNode_attack->name, (const xmlChar*)"attack"))
{
spellBlock_t sb;
if (g_monsters.deserializeSpell(tmpNode_attack, sb, "doCreateCustomMonster"))
pobranyTyp->spellAttackList.push_back(sb);
}
tmpNode_attack = tmpNode_attack->next;
}
}
if (!defensespells.empty()){
xmlNodePtr root_defense = xmlDocGetRootElement(xmlParseMemory(defensespells.c_str(), defensespells.length()));
xmlNodePtr tmpNode_defense = root_defense->children;
while (tmpNode_defense)
{
if (!xmlStrcmp(tmpNode_defense->name, (const xmlChar*)"defense"))
{
spellBlock_t defense;
if (g_monsters.deserializeSpell(tmpNode_defense, defense, "doCreateCustomMonster"))
pobranyTyp->spellDefenseList.push_back(defense);
}
tmpNode_defense = tmpNode_defense->next;
}
}
monster = Monster::createMonster(pobranyTyp);
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;
}