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

RevScripts tile create monsters

jel

Member
Joined
Mar 22, 2014
Messages
302
Reaction score
12
hello, someone convert this script to tfs 1.x

Lua:
local t = {
    monsters = {"Demon Vip", "Rat Vip"}, -- caso tenha mais de um monstro, será aleatório
    monstersCount = 8, -- quantidade de monstros que serão sumonados
    intervalToSummon = {30, "sec"}, -- intervalo para os monstros serem sumonados novamente
    timeForReuse = {1, "min"}, -- tempo para sumonar novamente pisando no tile
    storage = 76760 -- só modifique se necessário
}


tileSummonEvent = {}


local function isWalkableCheck(cid, pos)
    pos.stackpos = 0
    if getTileThingByPos(pos).uid ~= 0 then
        local n = getTileInfo(pos)
        if n.protection == false and n.house == false and getTopCreature(pos).uid == 0 and doTileQueryAdd(cid, pos) == RETURNVALUE_NOERROR then
            return true
        end
    end
end

local function getMyMonsters(cid)
    local p, summons = getPlayerPosition(cid), 0
    for x = -7, 7 do
        for y = -7, 7 do
            local pos = {x = p.x + x, y = p.y + y, z = p.z}
            local creature = getTopCreature(pos)
            if creature then
                if isMonster(creature.uid) then
                    if getPlayerStorageValue(creature.uid, t.storage) == getPlayerGUID(cid) then
                        summons = summons + 1
                    end
                end
            end
        end
    end
    return summons
end


local function doPlayerSummonOwnMonsters(cid, monster_count)
    local p, m, range = getPlayerPosition(cid), 0, (monster_count <= 8 and 1 or 2)
    for x = -range, range do
        for y = -range, range do
            local pos = {x = p.x + x, y = p.y + y, z = p.z}
            if isWalkableCheck(cid, pos) then
                if m < monster_count then
                    local monster = doCreateMonster(t.monsters[math.random(1, #t.monsters)], pos, false, true)
                    if isCreature(monster) then
                        doSendMagicEffect(getCreaturePosition(monster), CONST_ME_TELEPORT)
                        setPlayerStorageValue(monster, t.storage, getPlayerGUID(cid))
                        m = m + 1
                    end
                end
            end
        end
    end
end

local function doKeepPlayerSummoning(cid, tile_pos)
    if isPlayer(cid) then
        if doComparePositions(getPlayerPosition(cid), tile_pos) then
            local myMonsters = t.monstersCount - getMyMonsters(cid)
            if myMonsters > 0 then
                doPlayerSummonOwnMonsters(cid, myMonsters)
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Monstros sumonados!")
                setPlayerStorageValue(cid, t.storage, mathtime(t.timeForReuse) + os.time())
            end
            tileSummonEvent[getPlayerGUID(cid)] = addEvent(doKeepPlayerSummoning, mathtime(t.intervalToSummon) * 1000, cid, tile_pos)
        end
    end
end

function onStepIn(cid, item, position, fromPosition)
    if not isPlayer(cid) then return true end
    local check = getPlayerStorageValue(cid, t.storage) - os.time()
    if check > 0 then
        return doPlayerSendCancel(cid, "Aguarde "..check.." segundo"..(check > 1 and "s" or "").." para sumonar os monstros novamente.")
    end 
    if getMyMonsters(cid) >= t.monstersCount then
        return doPlayerSendCancel(cid, "Existem muitos monstros sumonados por você, derrote-os primeiro!")
    end
    local eventId = tileSummonEvent[getPlayerGUID(cid)]
    if eventId then
        stopEvent(eventId)
        eventId = nil
    end
    doPlayerSummonOwnMonsters(cid, t.monstersCount - getMyMonsters(cid))
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Monstros sumonados!")
    setPlayerStorageValue(cid, t.storage, mathtime(t.timeForReuse) + os.time())
    addEvent(doKeepPlayerSummoning, mathtime(t.intervalToSummon) * 1000, cid, position)
    return true
end

function mathtime(table) -- by dwarfer
local unit = {"sec", "min", "hour", "day"}
for i, v in pairs(unit) do
if v == table[2] then
return table[1]*(60^(v == unit[4] and 2 or i-1))*(v == unit[4] and 24 or 1)
end
end
return error("Bad declaration in mathtime function.")
end
 
Lua:
local t = {
    monsters = {"Demon Vip", "Rat Vip"},
    monstersCount = 8,
    intervalToSummon = {30, "sec"},
    timeForReuse = {1, "min"},
    storage = 76760
}

tileSummonEvent = {}

local function isWalkableCheck(player, pos)
    pos.stackpos = 0
    if Tile(pos):getThing(0) then
        local n = Tile(pos):getTileInfo()
        if not n.protection and not n.house and Tile(pos):getTopCreature() == nil and Tile(pos):queryAdd(player) == RETURNVALUE_NOERROR then
            return true
        end
    end
end

local function getMyMonsters(player)
    local p, summons = player:getPosition(), 0
    for x = -7, 7 do
        for y = -7, 7 do
            local pos = {x = p.x + x, y = p.y + y, z = p.z}
            local creature = Tile(pos):getTopCreature()
            if creature then
                if creature:isMonster() then
                    if creature:getStorageValue(t.storage) == player:getGuid() then
                        summons = summons + 1
                    end
                end
            end
        end
    end
    return summons
end

local function doPlayerSummonOwnMonsters(player, monster_count)
    local p, m, range = player:getPosition(), 0, (monster_count <= 8 and 1 or 2)
    for x = -range, range do
        for y = -range, range do
            local pos = {x = p.x + x, y = p.y + y, z = p.z}
            if isWalkableCheck(player, pos) then
                if m < monster_count then
                    local monsterName = t.monsters[math.random(#t.monsters)]
                    local monster = Game.createMonster(monsterName, pos)
                    if monster then
                        monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                        monster:setStorageValue(t.storage, player:getGuid())
                        m = m + 1
                    end
                end
            end
        end
    end
end

local function doKeepPlayerSummoning(playerId, tile_pos)
    local player = Player(playerId)
    if player then
        if player:getPosition() == tile_pos then
            local myMonsters = t.monstersCount - getMyMonsters(player)
            if myMonsters > 0 then
                doPlayerSummonOwnMonsters(player, myMonsters)
                player:sendTextMessage(MESSAGE_INFO_DESCR, "Monstros sumonados!")
                player:setStorageValue(t.storage, mathtime(t.timeForReuse) + os.time())
            end
            tileSummonEvent[player:getGuid()] = addEvent(doKeepPlayerSummoning, mathtime(t.intervalToSummon) * 1000, playerId, tile_pos)
        end
    end
end

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then return true end

    local checkTimeLeft = player:getStorageValue(t.storage) - os.time()
    if checkTimeLeft > 0 then
        return player:sendCancelMessage("Aguarde "..checkTimeLeft.." segundo"..(checkTimeLeft > 1 and "s" or "").." para sumonar os monstros novamente.")
    end 

    if getMyMonsters(player) >= t.monstersCount then
        return player:sendCancelMessage("Existem muitos monstros sumonados por você. Derrote-os primeiro!")
    end

    local eventId = tileSummonEvent[player:getGuid()]
    if eventId then stopEvent(eventId) end

    doPlayerSummonOwnMonsters(player, t.monstersCount - getMyMonsters(player))
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Monstros sumonados!")
    player:setStorageValue(t.storage, mathtime(t.timeForReuse) + os.time())
    
    addEvent(doKeepPlayerSummoning, mathtime(t.intervalToSummon) * 1000, player:getId(), position)
    
    return true 
end

function mathtime(table)
local unit = {"sec", "min", "hour", "day"}
for i,v in pairs(unit) do 
if v == table[2] then 
return table[1]*(60^(v == unit[4] and 2 or i-1))*(v == unit[4] and 24 or 1) 
end 
end 
return error("Bad declaration in mathtime function.")
end

Idk work or no, used chatgpt to do
Anyway its not revscript, its only onstepin with New functions, to change to revscript is easy if script is working
 
Lua:
local t = {
    monsters = {"Demon Vip", "Rat Vip"},
    monstersCount = 8,
    intervalToSummon = {30, "sec"},
    timeForReuse = {1, "min"},
    storage = 76760
}

tileSummonEvent = {}

local function isWalkableCheck(player, pos)
    pos.stackpos = 0
    if Tile(pos):getThing(0) then
        local n = Tile(pos):getTileInfo()
        if not n.protection and not n.house and Tile(pos):getTopCreature() == nil and Tile(pos):queryAdd(player) == RETURNVALUE_NOERROR then
            return true
        end
    end
end

local function getMyMonsters(player)
    local p, summons = player:getPosition(), 0
    for x = -7, 7 do
        for y = -7, 7 do
            local pos = {x = p.x + x, y = p.y + y, z = p.z}
            local creature = Tile(pos):getTopCreature()
            if creature then
                if creature:isMonster() then
                    if creature:getStorageValue(t.storage) == player:getGuid() then
                        summons = summons + 1
                    end
                end
            end
        end
    end
    return summons
end

local function doPlayerSummonOwnMonsters(player, monster_count)
    local p, m, range = player:getPosition(), 0, (monster_count <= 8 and 1 or 2)
    for x = -range, range do
        for y = -range, range do
            local pos = {x = p.x + x, y = p.y + y, z = p.z}
            if isWalkableCheck(player, pos) then
                if m < monster_count then
                    local monsterName = t.monsters[math.random(#t.monsters)]
                    local monster = Game.createMonster(monsterName, pos)
                    if monster then
                        monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                        monster:setStorageValue(t.storage, player:getGuid())
                        m = m + 1
                    end
                end
            end
        end
    end
end

local function doKeepPlayerSummoning(playerId, tile_pos)
    local player = Player(playerId)
    if player then
        if player:getPosition() == tile_pos then
            local myMonsters = t.monstersCount - getMyMonsters(player)
            if myMonsters > 0 then
                doPlayerSummonOwnMonsters(player, myMonsters)
                player:sendTextMessage(MESSAGE_INFO_DESCR, "Monstros sumonados!")
                player:setStorageValue(t.storage, mathtime(t.timeForReuse) + os.time())
            end
            tileSummonEvent[player:getGuid()] = addEvent(doKeepPlayerSummoning, mathtime(t.intervalToSummon) * 1000, playerId, tile_pos)
        end
    end
end

function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then return true end

    local checkTimeLeft = player:getStorageValue(t.storage) - os.time()
    if checkTimeLeft > 0 then
        return player:sendCancelMessage("Aguarde "..checkTimeLeft.." segundo"..(checkTimeLeft > 1 and "s" or "").." para sumonar os monstros novamente.")
    end

    if getMyMonsters(player) >= t.monstersCount then
        return player:sendCancelMessage("Existem muitos monstros sumonados por você. Derrote-os primeiro!")
    end

    local eventId = tileSummonEvent[player:getGuid()]
    if eventId then stopEvent(eventId) end

    doPlayerSummonOwnMonsters(player, t.monstersCount - getMyMonsters(player))
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Monstros sumonados!")
    player:setStorageValue(t.storage, mathtime(t.timeForReuse) + os.time())
   
    addEvent(doKeepPlayerSummoning, mathtime(t.intervalToSummon) * 1000, player:getId(), position)
   
    return true
end

function mathtime(table)
local unit = {"sec", "min", "hour", "day"}
for i,v in pairs(unit) do
if v == table[2] then
return table[1]*(60^(v == unit[4] and 2 or i-1))*(v == unit[4] and 24 or 1)
end
end
return error("Bad declaration in mathtime function.")
end

Idk work or no, used chatgpt to do
Anyway its not revscript, its only onstepin with New functions, to change to revscript is easy if script is working
monsters are not created
 
Back
Top