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

Game.advancedCreateCreature(creature, pos, [effect])

Itutorial

Excellent OT User
Joined
Dec 23, 2014
Messages
2,325
Solutions
68
Reaction score
999
This will allow you to spawn monsters up to 2sqm away from the position. Instead of the normal 1sqm.

data/lib/core/game.lua
Lua:
function Game.advancedCreateMonster(name, position, effect)
    local monster = nil
    local positions = {
        [1] = Position(position.x, position.y, position.z),
        [2] = Position(position.x - 2, position.y - 2, position.z),
        [3] = Position(position.x, position.y - 2, position.z),
        [4] = Position(position.x + 2, position.y - 2, position.z),
        [5] = Position(position.x + 2, position.y, position.z),
        [6] = Position(position.x + 2, position.y + 2, position.z),
        [7] = Position(position.x, position.y + 2, position.z),
        [8] = Position(position.x - 2, position.y + 2, position.z),
        [9] = Position(position.x - 2, position.y, position.z)
    }
    for i = 1, #positions do
        monster = Game.createMonster(name, positions[i])
        if monster then
            if effect then
                monster:getPosition():sendMagicEffect(effect)
            end
            return true
        end
    end
return false
end

Enjoy! If you want to check out my server and help test it to earn some donation points for: outfits, mounts, or VIP for access to more hunting areas come over to: legendsot.com



MODERATOR PLEASE CHANGE TITLE TO: Game.advancedCreateMonster(creature, position, [effect])
 

Attachments

Last edited:
Better position entry in the table:

@edit
Now I noticed that your code does not randomize positions, but always starts from the upper left corner. Corrected version here:
Lua:
function Game.advancedCreateMonster(name, position, effect)
    local positions = {
        {-2, -2, 0},
        {0, -2, 0},
        {2, -2, 0},
        {2, 0, 0},
        {2, 2, 0},
        {0, 2, 0},
        {-2, 2, 0},
        {-2, 0, 0}
    }
    local randomPos = math.random(#positions)
    local monster = Game.createMonster(name, Position(position.x + positions[randomPos][1], position.y + positions[randomPos][2], position.z + positions[randomPos][3]))
    
    if effect then
        monster:getPosition():sendMagicEffect(effect)
    end
    return true
end
 
Last edited:
It doesn't start from upper left. The randomization is in the createmonster code already. Kind of. You don't need it to be completely random anyway. The code I posted is just fine.

edit: in fact with your code the monster wouldn't spawn if the tile and 1sqm around is blocked so actually is wrong.
 
Last edited:
1586722697757.png
This is what he was talking about the "randomisation".
Your code spawns "cave rats" around your position (my character pos in example)
then spawns in that exact order: rats, trolls, frost trolls, swamp trolls, snake, rotworm, wolf, winter wolf.
If you remove the return and call the code you see.


Your code does the job, if you want to spawn in an wider area. I did similar for a feature i was testing, i did a range of 3 and randomisation.

Not sure when it was added (so not sure which tfs it'd work with), but if you add true, after the position in game.createrMonster, it extends the position, giving you a bit more range.
 
You can just use the extended parameter in the createMonster function to achieve this as Leesne said. What would make it better than that, is if you would also check if the tile is pathable from the original position, right now monsters can spawn behind walls, and it's the same thing when you are using the extended parameter
 
Last edited:
In TFS that I have (1.3 i believe) it will only spawn 1sqm around then 1 sqm more in each center so: x - 2, x + 2, y - 2, y + 2.

This was designed for the monster fishing code I am using. So players can trap themselves and if they catch stuff it will still run around so they don't miss out on rare catches. So, through walls, ect. is fine for what I need it for. If that is something someone wants they could ask. This code is just meant to do exactly what I released it to do. If you want to change it in some way feel free to.
 
This looks more like spawnLegion than advancedCreateCreature. Just sayin.
 
Back
Top