• 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

I think that you can use
Code:
doWriteLogFile(file, text)
But you can use it only 1 time beacuse it will save 2nd time in the same file. <_<
 
well i think about creating monsters on map, not to xml file... like spawning random monsters evry time somebody use lever, smth like

doCreateCustomMonster("name", random_health(100,500), random_outfit, etc...)
 
Yeah but it's the same but with
Code:
doCreateMonster(name, pos[, displayError = true])

Because you must create monster in .xml file with
doCreateCustomMonster("name", random_health(100,500), random_outfit, etc...)
and then create this monster in map.
 
ye, but this need reloading monsters and if i want 100 ppl to create monster it will create 100 xml files and will kinda spam monsters folder
 
Hey, hey, hey but what about monsters.xml. There isn't way to declarate "xxxx" monster with function "doWriteLogFile(file, text)" so...
 
Ok, i did something like that and it is working!

Code:
int32_t LuaInterface::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);
	
	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;
	
	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;
}

alalalala.jpg


/custom <name>,<lookType>,<health>
 
Yay, I wanted to code it
now just somehow add attacks to it xD
shouldnt be tHAT hard if you know how to handle lua arrays in c++(I have no idea :( )
This is probably best way to create perfect Kage Bunshin :D
 
But for me it not work ;/. Always when I try to create monster
Code:
[14:7:34.500] [Error - TalkAction Interface]
[14:7:34.500] data/talkactions/scripts/new3.lua:onSay
[14:7:34.500] Description:
[14:7:34.500] data/talkactions/scripts/new3.lua:2: attempt to call global 'doCre
ateCustomMonster' (a nil value)
[14:7:34.500] stack traceback:
[14:7:34.500]   data/talkactions/scripts/new3.lua:2: in function <data/talkactio
ns/scripts/new3.lua:1>
 
Ok, i did something like that and it is working!

Code:
int32_t LuaInterface::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);
	
	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;
	
	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;
}

alalalala.jpg


/custom <name>,<lookType>,<health>

If that is working then you have released one of the best codes for me
 
But for me it not work ;/. Always when I try to create monster
Code:
[14:7:34.500] [Error - TalkAction Interface]
[14:7:34.500] data/talkactions/scripts/new3.lua:onSay
[14:7:34.500] Description:
[14:7:34.500] data/talkactions/scripts/new3.lua:2: attempt to call global 'doCre
ateCustomMonster' (a nil value)
[14:7:34.500] stack traceback:
[14:7:34.500]   data/talkactions/scripts/new3.lua:2: in function <data/talkactio
ns/scripts/new3.lua:1>
Did you compile?
 
Code:
[15:44:38.359] [Error - TalkAction Interface]
[15:44:38.359] data/talkactions/scripts/new3.lua:onSay
[15:44:38.359] Description:
[15:44:38.359] attempt to index a number value
[15:44:38.359] stack traceback:
[15:44:38.359]  [C]: in function 'doCreateCustomMonster'
[15:44:38.359]  data/talkactions/scripts/new3.lua:2: in function <data/talkactio
ns/scripts/new3.lua:1>

Scrpit
LUA:
function onSay(cid, words, param, channel)
	doCreateCustomMonster(Dead, 300, 100)
	return true
end

Something wrong ??? <_<
 
Last edited:
@edit not work
[Error - Action Interface]
data/actions/scripts/test.lua:onUse
Description:
attempt to index a number value
stack traceback:
[C]: in function 'doCreateCustomMonster'
data/actions/scripts/test.lua:2: in function <data/actions/scripts/test.
lua:1>

with code
function onUse(cid, item, fromPosition, itemEx, toPosition)
doCreateCustomMonster("Mame", getCreaturePosition(cid), 100, 300)
return true
end
 
Last edited:
Outfit must be a table.
Code:
doCreateCustomMonster("Mame", getCreaturePosition(cid), [B][COLOR="red"]{lookType=100}[/COLOR][/B], 300)
 
Cyko: any idea how to get other tables, like array containing arrays with attack info?
like
Code:
{
{ name="", interval=, chance=, ..., attributes={shooteffect="", areaeffect=""}}}
This is only thing I have no idea how to get to complete this function :D

@down: gonna play with it a bit, thx

cause my experience in using lua and c++ together is completly NONE, should I expect unexpected?
 
Last edited:
Cyko: any idea how to get other tables, like array containing arrays with attack info?
like
Code:
{
{ name="", interval=, chance=, ..., attributes={shooteffect="", areaeffect=""}}}
This is only thing I have no idea how to get to complete this function :D
lua_getfield(L, ...);
 
Outfit must be a table.
Code:
doCreateCustomMonster("Mame", getCreaturePosition(cid), [B][COLOR="red"]{lookType=100}[/COLOR][/B], 300)

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;
}
 
Last edited:
Back
Top