MeNi
*^#%$%
- Joined
- Jul 23, 2008
- Messages
- 183
- Reaction score
- 12
Hello. I am releasing lua function i made to create custom monsters by lua script.
function code -> use: doCreateCustomMonster(name, pos, outfit, health, spells, corpse, distance, experience )
u must move in monsters.h from "private" to "public"
sample talkaction to test script: use: /custom name,lookType,health,exp
function code -> use: doCreateCustomMonster(name, pos, outfit, health, spells, corpse, distance, experience )
C++:
int32_t LuaInterface::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;
}
ScriptEnviroment* env = getEnv();
lua_pushnumber(L, env->addThing((Thing*)monster));
return 1;
}
u must move in monsters.h from "private" to "public"
C++:
bool deserializeSpell(xmlNodePtr node, spellBlock_t& sb, const std::string& description = "");
sample talkaction to test script: use: /custom name,lookType,health,exp
Lua:
local spells = {
[1] = {used = 0, text = '<attack name="melee" interval="2000" chance="100" range="5" radius="1" target="0"><attribute key="areaEffect" value="fire"/></attack>'},
[2] = {used = 0, text = '<attack name="melee" interval="1200" chance="100" range="5" radius="1" target="0"><attribute key="areaEffect" value="energyarea"/></attack>'},
[3] = {used = 0, text = '<attack name="melee" interval="700" chance="100" range="5" radius="1" target="0"><attribute key="areaEffect" value="mortarea"/></attack>'}
}
local spellsNumber = 2
function randomNum(range)
local rand = 0
good = false
math.randomseed( os.time() )
math.random()
math.random()
math.random()
while (not good) do
rand = math.random(range)
if (spells[rand].used == 0) then
spells[rand].used = 1
good = true
else
good = false
end
end
return rand
end
function onSay(cid, words, param, channel)
-- /custom name,lookType,health,exp
if(param == '') then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
return true
end
local t = string.explode(param, ",")
if(not t[4]) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command require 2 params.")
return true
end
local position = getCreaturePosition(cid)
outfit = {lookType = t[2], lookHead = 0, lookBody = 0, lookLegs = 0, lookFeet = 0}
local attacks = "<a>"
local num
for i=1,spellsNumber,1 do
num = randomNum(table.getn(spells))
attacks = attacks .. spells[num].text
end
attacks = attacks .. "</a>"
-- doCreateCustomMonster(name, pos, outfit, health, spells, corpse, distance, exp )
doCreateCustomMonster(t[1],position,outfit,t[3],attacks, 6324, 1, t[4])
for i=1,table.getn(spells),1 do
spells[i].used = 0
end
attacks = ""
return true
end
Last edited: