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

Lua doCreateMonster - A little help please? :)

Gidedin

New Member
Joined
May 16, 2013
Messages
7
Reaction score
0
Hello everyone.

I need some help using the doCreateMonster() function. Right now, I'm using it this way:

Code:
cid = doCreateMonster( creatureName, selectecPos, false, false )
if cid then
    [... CodeHere ...]
end

It works. But, if it is unable to create the monster ( Let's say there is a Fire Field in every 8 squares near the spawn pos ), it generates few errors on my Server Prompt. I already control the spawn position by defining when the error shows up and re-do the procedure, but those errors keep showing and that is annoying.

There is any way to change that? Control when the error shows?

I haven't tried
Code:
cid = doCreateMonster( creatureName, selectecPos, false, false ) or false
Because that just came to my mind and I'm not close to the server right now, but I still think the error will show up =(

I have tried
Code:
if doCreateMonster( creatureName, selectecPos, false, false ) ~= LUA_ERROR then
But it just failed until my failSafe broke the loop.

Another thing :p

Can someone tell me the exactly parameters used in the doCreateMonster function? I know that it is different from server to server, but I'm using one that, unfortunately, don't came with the Source Code. It is based on the 0.3.7 TFS.

Thank you and sorry if you can't understand it, still learning english.

If you want to reproduce the problem, do the command on a position where every field near it has any kind of field. Like, Fire or Eletric.
 
Hello Gidedin,

To not show the error, you have to change the source code in luascript.cpp

For example in my server the code is:

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

                lua_pushboolean(L, false);
                return 1;
        }

In this case just comment the line
PHP:
//errorEx("Cannot create monster: " + name);
and they will not show the error in your screen (but still cannot place the monster).

For the parameters in this function:

//doCreateMonster(name, pos[, extend = false[, force = false]])

name - The name of the monster you want to create. This name tag is inside your xml monster.
pos - Position to create the monster
extend - Extends the position to place the monster. Will add 4 more tiles with chance to place the creature
force - Basically it will add the monster even if is in the Protection zone.

Best Regards,
 
Thank you psychomen!

Unfortunately, I can't edit the source because I don't have any :( But I'll work around that, already made some changes that basically, will avoid errors :)
 
force parameter should basically ignore fire fields etc.

Otherwise try:
errors(false)
-- summon here
errors(true)
 
Hey Pnurt.

Basically, I can't give the code out yet because it is a work in progress arena, but it is not really that hard to avoid the errors.

Here is some part of the code:

Code:
		local spawnPoint = { 
			x = math.random( arena[1].x , arena[2].x ),
			y = math.random( arena[1].y , arena[2].y ),
			z = math.random( arena[1].z , arena[2].z ),
			stackpos = 253
		}
				
		local posicaoBusca = {
			-- Normais
			["E"] = { x = spawnPoint.x + 1, y = spawnPoint.y, z = spawnPoint.z, stackpos = 253},
			["D"] = { x = spawnPoint.x - 1, y = spawnPoint.y, z = spawnPoint.z, stackpos = 253},
			["N"] = { x = spawnPoint.x, y = spawnPoint.y + 1, z = spawnPoint.z, stackpos = 253},
			["S"] = { x = spawnPoint.x, y = spawnPoint.y - 1, z = spawnPoint.z, stackpos = 253},
			-- Diagonais
			["NE"] = { x = spawnPoint.x + 1, y = spawnPoint.y - 1, z = spawnPoint.z, stackpos = 253},
			["ND"] = { x = spawnPoint.x - 1, y = spawnPoint.y + 1, z = spawnPoint.z, stackpos = 253},
			["SE"] = { x = spawnPoint.x - 1, y = spawnPoint.y + 1, z = spawnPoint.z, stackpos = 253},
			["SD"] = { x = spawnPoint.x + 1, y = spawnPoint.y - 1, z = spawnPoint.z, stackpos = 253},
			-- Posição do Spawn
			["X"] = { x = spawnPoint.x, y = spawnPoint.y, z = spawnPoint.z, stackpos = 253}
		}
		
		local chao = 
			( 
				( table.find( arena[3], getTileInfo(posicaoBusca["E"]).itemid ) ) and
				( table.find( arena[3], getTileInfo(posicaoBusca["D"]).itemid ) ) and
				( table.find( arena[3], getTileInfo(posicaoBusca["N"]).itemid ) ) and
				( table.find( arena[3], getTileInfo(posicaoBusca["S"]).itemid ) ) and
				( table.find( arena[3], getTileInfo(posicaoBusca["NE"]).itemid ) ) and
				( table.find( arena[3], getTileInfo(posicaoBusca["ND"]).itemid ) ) and
				( table.find( arena[3], getTileInfo(posicaoBusca["SE"]).itemid ) ) and
				( table.find( arena[3], getTileInfo(posicaoBusca["SD"]).itemid ) )
			) or false
			
		if  ( chao ) and ( monstrosAdicionados < limite ) then
			-- Spawn your monster
		end

I'm validating if it is possible to spawn the creature there.

On my Arena configs, I've the Arena coordinates with the the tile specific where monsters can spawn. An example is the grass tiles. It'll check if all the tiles around the random chosen place is allowed and if it is, it'll spawn it. That way, i can make custom arenas with mountains, rivers, pools and all that.

Already tested an arena with over 1400 sqms and was allowed to summon few times over 400 monsters in less then 0.3 seconds without a single error in the console.

It may not be the best approach to this situation, but certainly, in't the worst as it works and very fast.

Tell me if it helped you and if not, I'll see what I can do to help :)

Ah, the Vars are in portuguese, so let me translate here really fast:

Code:
Chao is the boolean var that will check if the tiles are the allowed IDs.
spawnPoint is the random position.
The positions: E is East, D is West, N is North, S is South. NE is North East, ND is NorthWest, SE is SouthEast and SD is SouthWest. X is the Chosen Position.
monstrosAdicionados is the current number of spawned monsters and limite is the max number of monsters allowed to be spawned.

Cheers,
Gid.
 
Pnurt, the problem about changing the source is that you'll not have control if the monster have really spawn or not.

Let's say (In my case), I must have 3 enemies in the arena in the first round. If one monster don't spawn (And i'm suppressing the error), only two will spawn and the player will be locked in there.

The way I did, I'll avoid these errors and always the right number of monsters will spawn.

But, that is the case for me :)

I hope you can make your things work now.

Ad about SQL, there is no SQL involved in anything.
 
EDIT: Waow I'm really tired atm. Holy shit. Sorry guys I've been babbling about something totally irrelevant.

Good night....
 
Humm... That is something I have to work around :p

But, right now, I've created many new monsters for the arena and removed all Field Type attacks (And corpses).

But, you gave me an idea :)

Tonight I'll make some tests and if I find a good approach for that, I'll post here :)

But, I'm pretty sure if you look for the Stack 253, you'll always get the Tile ID? (Don't know if I'm saying the true here. I'll test and post in few minutes).

---

So yeah, I tested it and even if there is fire field all over the place, I'll still get the Tile ID ( Using the getTileInfo ) and so, will be able to force the monster spawn :) But, for that, I'll have to use the force parameter in the command or the monster will be unable to spawn.

But I'll still leave the monsters without Field Type attacks and corpses. That way, I don't have to keep cleaning the arena every time a new player starts it. They aready have random death effects and is pretty cool :p
 
Last edited:
Back
Top