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

Error: Cannot create monster: Rat

Xagul

deathzot.net
Joined
Jun 30, 2008
Messages
1,294
Solutions
3
Reaction score
1,037
Hello, I've made a script to summon a rat however when there is not enough room it should say "Not enough room" Currently the script I am using works if there is monsters surounding me completly but if there is an item such as a "wall" or "water" then it sends an error to the console and does not say "Not enough room"
Anyone know why this is? Here is my current script:

Code:
function onSay(cid, words, param, channel)
	local pos = getClosestFreeTile(cid, getCreaturePosition(cid), false, false)
	if(not pos or isInArray({pos.x, pos.y}, 0)) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Not enough room.")
		return true
	end

	local tmp = getCreaturePosition(cid)
	if(doCreateMonster("Rat", tmp)) then
		doCreatureSay(cid, "rats!", TALKTYPE_ORANGE_1, cid)
	end
    return TRUE
end
 
Code:
function onSay(cid, words, param, channel)
	if doCreateMonster('Rat', getClosestFreeTile(cid, getThingPos(cid)) or getThingPos(cid), false) then
		doCreatureSay(cid, 'rats!', TALKTYPE_ORANGE_1, false, cid)
	else
		doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHROOM)
	end
	return true
end
 
Its still spamming errors to the console when it fails to summon the creature, its also not sending the cancel msg (if that helps)
 
Yes of course xD

Code:
[1:41:36.265] [Error - TalkAction Interface]
[1:41:36.265] data/talkactions/scripts/test.lua:onSay
[1:41:36.265] Description:
[1:41:36.265] (luaDoCreateMonster) Cannot create monster: Rat
 
replace this;
Code:
if doCreateMonster('Rat', getClosestFreeTile(cid, getThingPos(cid)) or getThingPos(cid), false) then
with this;
Code:
if doCreateMonster('Rat', getClosestFreeTile(cid, getThingPos(cid)) or getThingPos(cid), false) == RETURNVALUE_NOERROR then
this will remove the error in console but will give the default cancel (tested it) even if theres enough room. also if you put a "return" near doCreatureSay wont work still, gl
 
replace this;
Code:
if doCreateMonster('Rat', getClosestFreeTile(cid, getThingPos(cid)) or getThingPos(cid), false) then
with this;
Code:
if doCreateMonster('Rat', getClosestFreeTile(cid, getThingPos(cid)) or getThingPos(cid), false) == RETURNVALUE_NOERROR then
this will remove the error in console but will give the default cancel (tested it) even if theres enough room. also if you put a "return" near doCreatureSay wont work still, gl
Nah, mine has to work. He's probably using an unsupported distro.
Also this function return boolean (true/false) and not RETURNVALUE_NOERROR (1) or 0
 
@Gelio
Yes I have the monster in my server it summons a rat however if there is no room it sends an error to console instead of just saying "not enough room"

@OzIcO
Still sends an error when I change that line.

@Cykotitan
I am using 0.4 also the script I have been using stops the error if all tiles surrounding me are filled with monsters however if even 1 object is causing the spell to be blocked then it sends an error still. It is odd lol.
 
Last edited:
I am using 0.4 and yes I have the monster in my server it summons a rat however if there is no room it sends an error to console instead of just saying "not enough room"
replace this;
Code:
if doCreateMonster('Rat', getClosestFreeTile(cid, getThingPos(cid)) or getThingPos(cid), false) then
with this;
Code:
if doCreateMonster('Rat', getClosestFreeTile(cid, getThingPos(cid)) or getThingPos(cid), false) == RETURNVALUE_NOERROR then
this will remove the error in console but will give the default cancel (tested it) even if theres enough room. also if you put a "return" near doCreatureSay wont work still, gl
...
 
Okay, fixed.
Code:
function onSay(cid, words, param, channel)
	local ret = doCreateMonster('Rat', getClosestFreeTile(cid, getThingPos(cid)), false)
	if type(ret) == "number" then
		doCreatureSay(cid, 'rats!', TALKTYPE_ORANGE_1, false, cid)
		doSendMagicEffect(getThingPos(ret), CONST_ME_TELEPORT)
	else
		doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHROOM)
	end
	return doSendMagicEffect(getThingPos(cid), type(ret) == "number" and CONST_ME_MAGIC_BLUE or CONST_ME_POFF)
end
 
Yea that worked as far as saying not enough room, but it still shows the error in console. Is there a way to just hide the error? It is not a big deal I am sure but it still makes it hard to see the important errors since you know how players are, they don't just try once they spam it till it works xD

Edit:
doCreateMonster(name, pos[, displayError = true])
it seems you added false already so I am guessing displayError false does not work properly in 0.4.
 
Then replace the respective part in your luascript.cpp with this:
Code:
int32_t LuaScriptInterface::luaDoCreateMonster(lua_State* L)
{
	//doCreateMonster(name, pos[, displayError = true])
	bool displayError = true;
	if(lua_gettop(L) > 2)
		displayError = popNumber(L);

	PositionEx pos;
	popPosition(L, pos);

	std::string name = popString(L);
	Monster* monster = Monster::createMonster(name.c_str());
	if(!monster)
	{
		if(displayError)
			errorEx("Monster with name '" + name + "' not found");

		lua_pushboolean(L, false);
		return 1;
	}

	if(!g_game.placeCreature(monster, pos))
	{
		delete monster;
		if(displayError)
			errorEx("Cannot create monster: " + name);

		lua_pushboolean(L, true);
		return 1;
	}

	ScriptEnviroment* env = getEnv();
	lua_pushnumber(L, env->addThing((Thing*)monster));
	return 1;
}
 
Back
Top