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

Is is possible to check if monster can be spawned on random tile?

ligus

New Member
Joined
Apr 26, 2010
Messages
253
Reaction score
0
Hello,

I have this script:
Code:
local pos = {x=xTable[math.random(#xTable)], y=yTable[math.random(#yTable)], z=7}             
doCreateMonster('Hydra', pos, false, false)

Is it possible to check if pos is not for example mountain or there is no player/monster etc end then create monster?
Becasue I have a lot of errors:
Code:
(LuaInterface::luaDoCreateMonster) Cannot create monster: Hydra

Thanks in advance! :)
 
This is possible. But your script would be a whole lot bigger than 2 lines which you got now haha. I think you need pretty decent lua skills to make it. You could make a list with the forbidden objects and check if the random generated spawning position contains an object from your forbidden object list.

you could make a forbidden object list like this:
local forbiddenObjectList = 2133, 5459, 5344 etc just fill in the itemID nrs. Later in your code you will need to add a loop which is going to check the posistion. For example
Code:
local forbiddenObjectList = 2143, 5678, 9932
i = 0
while i < 1
local pos = {x=xTable[math.random(#xTable)], y=yTable[math.random(#yTable)], z=7}
if pos ==  getTileItemById(pos, forbiddenObjectList[, subType])
else
doSummonCreature(Hydra, pos)
i++
end
another advice is to change doCreateMonster to: doSummonCreature(Hydra, pos)

btw this is not a complete script so please don't expect this to work hehe.
 
Which server do you use?

You can check if the pos is walkable.
Code:
local function isWalkable(pos)
     pos.stackpos = 0
     local tile = getThingfromPos(pos, false)
     if tile ~= 0 and not hasProperty(tile.uid, CONST_PROP_BLOCKSOLID) and not isCreature(getTopCreature(pos).uid) then
         return true
     end
end

Code:
if isWalkable(pos) then

Or do it like the /m talkaction script creature.lua, if that cancel part works on your server.
 
I'm using version 0.3.7

I tried to use your script but
Code:
(LuaInterface::luaGetThingFromPosition) Tile not found
Code:
(LuaInterface::luaHasItemProperty) Item not found

Do you have any idea?
 
You can add
Code:
errors(false)
Above doCreateMonster, so it won't show the errors from that function, under doCreateMonster add errors(true) so it still shows other errors.
 
Last edited:
You can also do something like this.
Code:
if doTileQueryAdd(cid, pos) ~= RETURNVALUE_NOTPOSSIBLE and not isCreature(getTopCreature(pos).uid) then
 
Is it used in a global event? It needs the parameter cid to get a creatureid.
If it's used in a lua made function you can add cid to that function.
 
function canAddThing(pos)
local tile = getTileThingByPos({x=pos.x, y=pos.y, z=pos.z, stackpos=0})
return tile.uid ~= 0 and not hasProperty(tile.uid, CONST_PROP_BLOCKSOLID) and not getTilePzInfo(pos) and not getTileHouseInfo(pos)
end


if canAddThing(pos) then


Try that.
 
function canAddThing(pos)
local tile = getTileThingByPos({x=pos.x, y=pos.y, z=pos.z, stackpos=0})
return tile.uid ~= 0 and not hasProperty(tile.uid, CONST_PROP_BLOCKSOLID) and not getTilePzInfo(pos) and not getTileHouseInfo(pos)
end


if canAddThing(pos) then


Try that.
Still the same:
Code:
(LuaInterface::luaDoCreateMonster) Cannot create monster: Hydra


Is it used in a global event? It needs the parameter cid to get a creatureid.
If it's used in a lua made function you can add cid to that function.
This is mod (lib here)
Code:
                    local playerTable, creatureTable, xTable, yTable = {}, {}, {}, {}

                    for x = config.room.from.x, config.room.to.x do
                        for y = config.room.from.y, config.room.to.y do
                            local n, i = getTileInfo({x=x, y=y, z=7}).creatures, 1
                            if n ~= 0 then
                                local v = getThingfromPos({x=x, y=y, z=7, stackpos=i}).uid
                                while v ~= 0 do
                                    if isPlayer(v) then
                                        table.insert(playerTable, v)
                                        if n == #playerTable then
                                            break
                                        end
                                    elseif isMonster(v) then
                                        table.insert(creatureTable, v)
                                        if n == #creatureTable then
                                            break
                                        end
                                    end
                                    i = i + 1
                                    v = getThingfromPos({x=x, y=y, z=7, stackpos=i}).uid
                                end
                            end
                 
                            table.insert(xTable, x)
                            table.insert(yTable, y)
                        end
                    end

                    local pos = {x=xTable[math.random(#xTable)], y=yTable[math.random(#yTable)], z=7}
                    local pos2 = {x=xTable[math.random(#xTable)], y=yTable[math.random(#yTable)], z=7}
                                 
                    doCreateMonster('Hydra', pos, false, false)
                    doSendMagicEffect(pos, CONST_ME_BATS)
                           
                    doCreateMonster('Giant Spider', pos2, false, false)             
                    doSendMagicEffect(pos2, CONST_ME_BATS)
 
You can add cid in the function that is executing this, then add cid in the function where it's used in the mod (if it's not a globalevent).
If it's a globalevent, you can get cid from an online player from getPlayersOnline() or just use the errors(false) above doCreateMonster and errors(true) under it so it won't print the errors from the function doCreateMonster.
It won't create the monsters on the not valid positions or bug or anything, you only won't see these errors anymore if you do that.
 
Last edited:
Back
Top