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

[lua function] doCreateCustomMonster

nothing happens, no errors, no monsters

@edit
with this code
PHP:
	monster* monster = monster::createmonster("base");
	if(!monster)
	{
		errorex(geterror(lua_error_monster_not_found));
		lua_pushboolean(l, false);
		return 1;
	}
i go error
PHP:
[error - action interface]
data/actions/scripts/test.lua:onuse
description:
(luadocreatecustommonster) monster not found



--------------------------------------------------------------------------------------------------------------------------------------------
@next edit
this work for tfs 0.3.6pl1!!
PHP:
int32_t luascriptinterface::luadocreatecustommonster(lua_state* l)
{
	//docreatecustommonster(name, pos, outfit, health)
	int health;
	outfit_t outfit;
	positionex pos;
	monstertype* pobranytyp = null;
	pobranytyp = new monstertype();
	
	int32_t params = lua_gettop(l);

    health = popnumber(l);
	outfit = popoutfit(l);
	popposition(l, pos);
	std::string name = popstring(l);

	pobranytyp->health = health;
    pobranytyp->healthmax = health;
   	pobranytyp->outfit = outfit;
    pobranytyp->name = name;
    pobranytyp->namedescription = name;
	
	monster* monster = monster::createmonster(pobranytyp);
    
	if(!g_game.placecreature(monster, pos, false, false))
	{
		delete monster;
		errorex(geterror(lua_error_thing_not_found));
		lua_pushboolean(l, true);
		return 1;
	}

	scriptenviroment* env = getenv();
	lua_pushnumber(l, env->addthing((thing*)monster));
	return 1;
}

rep++
 
I made it, now i can create also custom spells by lua script..

alalalala.jpg


lua function in c++:
Code:
int32_t LuaInterface::luaDoCreateCustomMonster(lua_State* L)
{
	//doCreateCustomMonster(name, pos, outfit, health, spells )
	
	int health;
	Outfit_t outfit;
	PositionEx pos;
	MonsterType* pobranyTyp = NULL;
	pobranyTyp = new MonsterType();
	
	int32_t params = lua_gettop(L);

	std::string spells = popString(L);
    health = popNumber(L);
	outfit = popOutfit(L);
	popPosition(L, pos);
	std::string name = popString(L);
	
	Monster* monster = Monster::createMonster("base");
	if(!monster)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	
	pobranyTyp = monster->getMonsterType();
	
	pobranyTyp->health = health;
    pobranyTyp->healthMax = health;
   	pobranyTyp->outfit = outfit;
    pobranyTyp->name = name;
    pobranyTyp->nameDescription = name;
    
    	
	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;
}

also i moved
Code:
bool deserializeSpell(xmlNodePtr node, spellBlock_t& sb, const std::string& description = "");
in monsters.h from "private" to "public"


lua script/talkaction to test things:

Code:
function onSay(cid, words, param, channel)
	if(param == '') then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
		return true
	end
	local t = string.explode(param, ",")
	if(not t[3]) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command require 3 params.")
		return true
	end
	
	local position = getCreaturePosition(cid)
	outfit = {lookType = t[2], lookHead = 0, lookBody = 0, lookLegs = 0, lookFeet = 0}

	local attacks = '<a><attack name="melee" interval="2000" chance="100" min="-10" max="-300" range="1"/><attack name="energy" interval="2300" chance="80" min="-15100" max="-18900" range="5"><attribute key="areaEffect" value="bigclouds"/><attribute key="shootEffect" value="flasharrow"/></attack></a>'

	doCreateCustomMonster(t[1],position,outfit,t[3],attacks)

        -- /custom name,looktype,health
	--doCreateCustomMonster(name, pos, outfit, health, attacks )
	return true
end


and it need a base monster (can be copied rat or anything) called "base" in ur monsters folder and added to monsters.xml





I could not find way to send attacks by tabble, so i send it by xml and use bulit in tfs parser to do work.. if any C++ pro (i never programmed in c++, so sorry for coding) could edit it to make it more user friendly or add tabble spells use, will be great
 
You mean that the monster in monster folder and monster.xml is named "base" but you can name it anything you want ingame?
if so I can see this turn into something very awesome for a pet system and much more!
Also I think you can do a table in constant to do this:
Code:
monster = {
rat = 123,
dog = 234
}
 
I made it, now i can create also custom spells by lua script..

alalalala.jpg


lua function in c++:
Code:
int32_t LuaInterface::luaDoCreateCustomMonster(lua_State* L)
{
	//doCreateCustomMonster(name, pos, outfit, health, spells )
	
	int health;
	Outfit_t outfit;
	PositionEx pos;
	MonsterType* pobranyTyp = NULL;
	pobranyTyp = new MonsterType();
	
	int32_t params = lua_gettop(L);

	std::string spells = popString(L);
    health = popNumber(L);
	outfit = popOutfit(L);
	popPosition(L, pos);
	std::string name = popString(L);
	
	Monster* monster = Monster::createMonster("base");
	if(!monster)
	{
		lua_pushboolean(L, false);
		return 1;
	}
	
	pobranyTyp = monster->getMonsterType();
	
	pobranyTyp->health = health;
    pobranyTyp->healthMax = health;
   	pobranyTyp->outfit = outfit;
    pobranyTyp->name = name;
    pobranyTyp->nameDescription = name;
    
    	
	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;
}

also i moved
Code:
bool deserializeSpell(xmlNodePtr node, spellBlock_t& sb, const std::string& description = "");
in monsters.h from "private" to "public"


lua script/talkaction to test things:

Code:
function onSay(cid, words, param, channel)
	if(param == '') then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
		return true
	end
	local t = string.explode(param, ",")
	if(not t[3]) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command require 3 params.")
		return true
	end
	
	local position = getCreaturePosition(cid)
	outfit = {lookType = t[2], lookHead = 0, lookBody = 0, lookLegs = 0, lookFeet = 0}

	local attacks = '<a><attack name="melee" interval="2000" chance="100" min="-10" max="-300" range="1"/><attack name="energy" interval="2300" chance="80" min="-15100" max="-18900" range="5"><attribute key="areaEffect" value="bigclouds"/><attribute key="shootEffect" value="flasharrow"/></attack></a>'

	doCreateCustomMonster(t[1],position,outfit,t[3],attacks)

        -- /custom name,looktype,health
	--doCreateCustomMonster(name, pos, outfit, health, attacks )
	return true
end


and it need a base monster (can be copied rat or anything) called "base" in ur monsters folder and added to monsters.xml





I could not find way to send attacks by tabble, so i send it by xml and use bulit in tfs parser to do work.. if any C++ pro (i never programmed in c++, so sorry for coding) could edit it to make it more user friendly or add tabble spells use, will be great
you should release this on the C++ codes section, it would be very useful
 
Back
Top