• 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 Help finish a script tfs 1.x

simbabrasil

New Member
Joined
Apr 23, 2023
Messages
31
Reaction score
1
hi guys, smn helped me with a script but i need one specific part, this part is on pet systems and pokemon servers, i need a script that the monster bring back to the item it was created everything i found was not working, gonna show some:
if not (getTilePzInfo(getCreaturePosition(cid))) then
------------------------------------
if #summon >= 1 then
for _, pid in ipairs(summon) do
doRemoveCreature(pid)
doCreatureSay(cid, ""..go.pet..", Recuar!", TALKTYPE_ORANGE_1)
end
return true
end
-----------------------------------------
and another one
-------------------------------------
local summons = getCreatureSummons(cid)
if(table.maxn(summons) < MaximoSummon) then -- no summons
doConvinceCreature(cid, doCreateMonster(MonsterName, getCreaturePosition(cid)))
else
for _, pid in ipairs(summons) do
doRemoveCreature(pid)
end
end
return true
end
----------------------------------------

I tried everything i found and nothing working the right way, the problem is the monster dont back to item, when click again on item it summons 2 monster and if i put max limit 1 monster after sumonning the first one when click on item again says that it cannot use the object, please help
 
Post the full script or there's no way to really help
 
Post the full script or there's no way to really help
thanks for replyin bro, gonna put my full script here and im lookin for a way to bring the monster back to item while the item is active(theres a time expire)

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local monsterName = "Rat" -- Nome do monstro a ser invocado
local despawnTime = 1 * 60 * 1000 -- Tempo em milissegundos para o monstro ser removido (1 minutos)
-- Verifica se o jogador está em uma zona de proteção
if player:getTile():hasFlag(TILESTATE_PROTECTIONZONE) then
player:sendCancelMessage("Você não pode usar este item em uma zona de proteção.")
return true
end
-- Verifica se há paredes ou itens ao redor do jogador
local directions = {NORTH, EAST, SOUTH, WEST, NORTHEAST, NORTHWEST, SOUTHEAST, SOUTHWEST}
local validPositions = {}
for i = 1, #directions do
local checkPosition = player:getPosition()
checkPosition:getNextPosition(directions)
local tile = Tile(checkPosition)
if tile then
if tile:hasFlag(TILESTATE_BLOCKSOLID) then
player:sendCancelMessage("Você precisa de espaço para poder criar seu Dummy aqui.")
return true
else
if tile:getTopCreature() ~= nil then
player:sendCancelMessage("Você precisa de espaço para poder criar seu Dummy aqui.")
return true
else
table.insert(validPositions, checkPosition)
end
end
end
end
-- Escolhe aleatoriamente uma posição válida para invocar o monstro e remove o item usado
local summonPosition = validPositions[math.random(#validPositions)]
local monster = Game.createMonster(monsterName, summonPosition)
-- Adiciona um evento para remover o monstro após o tempo especificado
addEvent(function()
if monster and monster:isCreature() then
monster:remove()
end
end, despawnTime)
return true
end
 
thanks for replyin bro, gonna put my full script here and im lookin for a way to bring the monster back to item while the item is active(theres a time expire)

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local monsterName = "Rat" -- Nome do monstro a ser invocado
local despawnTime = 1 * 60 * 1000 -- Tempo em milissegundos para o monstro ser removido (1 minutos)
-- Verifica se o jogador está em uma zona de proteção
if player:getTile():hasFlag(TILESTATE_PROTECTIONZONE) then
player:sendCancelMessage("Você não pode usar este item em uma zona de proteção.")
return true
end
-- Verifica se há paredes ou itens ao redor do jogador
local directions = {NORTH, EAST, SOUTH, WEST, NORTHEAST, NORTHWEST, SOUTHEAST, SOUTHWEST}
local validPositions = {}
for i = 1, #directions do
local checkPosition = player:getPosition()
checkPosition:getNextPosition(directions)
local tile = Tile(checkPosition)
if tile then
if tile:hasFlag(TILESTATE_BLOCKSOLID) then
player:sendCancelMessage("Você precisa de espaço para poder criar seu Dummy aqui.")
return true
else
if tile:getTopCreature() ~= nil then
player:sendCancelMessage("Você precisa de espaço para poder criar seu Dummy aqui.")
return true
else
table.insert(validPositions, checkPosition)
end
end
end
end
-- Escolhe aleatoriamente uma posição válida para invocar o monstro e remove o item usado
local summonPosition = validPositions[math.random(#validPositions)]
local monster = Game.createMonster(monsterName, summonPosition)
-- Adiciona um evento para remover o monstro após o tempo especificado
addEvent(function()
if monster and monster:isCreature() then
monster:remove()
end
end, despawnTime)
return true
end
 
thanks for replyin bro, gonna put my full script here and im lookin for a way to bring the monster back to item while the item is active(theres a time expire)

When posting a script, use [ code=lua] before and [/ code] after removing the space before the Word code

Ex.:
[ Code=lua]code here[/ code] < without space inside [ ]

Chatgpt:
Lua:
local SUMMON_TIME = 60 * 60 * 1000 -- 1 hora em milissegundos
local SUMMON_NAME = "Orc Leader"

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getTile():hasFlag(TILESTATE_PROTECTIONZONE) then
        player:sendCancelMessage("Você não pode usar este item em uma zona de proteção.")
        return true
    end

    local summons = player:getSummons()
    for i = 1, #summons do
        local summon = summons[i]
        if summon:getType():getName() == SUMMON_NAME then
            summon:remove()
            stopEvent(removeEvent)
            return true
        end
    end

    local summonPosition = player:getClosestFreePosition(player:getPosition(), false)
    if not summonPosition then
        player:sendCancelMessage("Não há espaço suficiente para invocar o summon.")
        return true
    end

    local summon = Game.createMonster(SUMMON_NAME, summonPosition)
    if not summon then
        player:sendCancelMessage("Não foi possível invocar o summon.")
        return true
    end

    player:addSummon(summon)
    summon:setMaster(player)

    removeEvent = addEvent(function()
        if summon and summon:isCreature() then
            summon:remove()
            item:remove(1)
        end
    end, SUMMON_TIME)

    return true
end

I don't get what you really want, summon when clkck and remove summon when click again? Remove item or no? Auto remove summom after some time or no?
 
Last edited:
When posting a script, use [ code=lua] before and [/ code] after removing the space before the Word code

Ex.:
[ Code=lua]code here[/ code] < without space inside [ ]

Chatgpt:
Lua:
local SUMMON_TIME = 60 * 60 * 1000 -- 1 hora em milissegundos
local SUMMON_NAME = "Orc Leader"

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getTile():hasFlag(TILESTATE_PROTECTIONZONE) then
        player:sendCancelMessage("Você não pode usar este item em uma zona de proteção.")
        return true
    end

    local summons = player:getSummons()
    for i = 1, #summons do
        local summon = summons[i]
        if summon:getType():getName() == SUMMON_NAME then
            summon:remove()
            stopEvent(removeEvent)
            return true
        end
    end

    local summonPosition = player:getClosestFreePosition(player:getPosition(), false)
    if not summonPosition then
        player:sendCancelMessage("Não há espaço suficiente para invocar o summon.")
        return true
    end

    local summon = Game.createMonster(SUMMON_NAME, summonPosition)
    if not summon then
        player:sendCancelMessage("Não foi possível invocar o summon.")
        return true
    end

    player:addSummon(summon)
    summon:setMaster(player)

    removeEvent = addEvent(function()
        if summon and summon:isCreature() then
            summon:remove()
            item:remove(1)
        end
    end, SUMMON_TIME)

    return true
end

I don't get what you really want, summon when clkck and remove summon when click again? Remove item or no? Auto remove summom after some time or no?
hi bro thank u again, is that what u got, except the part masters because the monsters is only a pocket training with expiration time, its exactly like u did i will only delete the part master the monster cuz as i said its not a utevo res, its only a monster that the char can train for a while and it expire, thank u very much brother, tmj pai
Post automatically merged:

hi bro thank u again, is that what u got, except the part masters because the monsters is only a pocket training with expiration time, its exactly like u did i will only delete the part master the monster cuz as i said its not a utevo res, its only a monster that the char can train for a while and it expire, thank u very much brother, tmj pai
theres crazy thing happening, when use the item with god it work exactly the way im thinking, but when i try to use with a player it summon many monsters insted of one and the player cant bring it back to item, when click again it summons another one lol
 
Last edited:
hi bro thank u again, is that what u got, except the part masters because the monsters is only a pocket training with expiration time, its exactly like u did i will only delete the part master the monster cuz as i said its not a utevo res, its only a monster that the char can train for a while and it expire, thank u very much brother, tmj pai
Post automatically merged:


theres crazy thing happening, when use the item with god it work exactly the way im thinking, but when i try to use with a player it summon many monsters insted of one and the player cant bring it back to item, when click again it summons another one lol
Its because before its a summon, so script can check and return player summon, now, the script cant return because u removed players summon
 
Its because before its a summon, so script can check and return player summon, now, the script cant return because u removed players summon
hi yes i thought was that but i back the script with master part and it still summoning many, thank u very much ever helpin
 
hi yes i thought was that but i back the script with master part and it still summoning many, thank u very much ever helpin
be a lot easier to help if you actually posted your script correctly so we can look at it.
 
be a lot easier to help if you actually posted your script correctly so we can look at it.
thank u bro, the script mano368 sent is working good with god but with normal players it is summoning many monster instead of one, click on item and spawn monster, click again and the monster back to item but when i do this with good it works perfectly, but when doin with players it not working

Lua:
local SUMMON_TIME = 60 * 60 * 1000 -- 1 hora em milissegundos
local SUMMON_NAME = "Orc Leader"

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getTile():hasFlag(TILESTATE_PROTECTIONZONE) then
        player:sendCancelMessage("Você não pode usar este item em uma zona de proteção.")
        return true
    end

    local summons = player:getSummons()
    for i = 1, #summons do
        local summon = summons[i]
        if summon:getType():getName() == SUMMON_NAME then
            summon:remove()
            stopEvent(removeEvent)
            return true
        end
    end

    local summonPosition = player:getClosestFreePosition(player:getPosition(), false)
    if not summonPosition then
        player:sendCancelMessage("Não há espaço suficiente para invocar o summon.")
        return true
    end

    local summon = Game.createMonster(SUMMON_NAME, summonPosition)
    if not summon then
        player:sendCancelMessage("Não foi possível invocar o summon.")
        return true
    end

    player:addSummon(summon)
    summon:setMaster(player)

    removeEvent = addEvent(function()
        if summon and summon:isCreature() then
            summon:remove()
            item:remove(1)
        end
    end, SUMMON_TIME)

    return true
end
Post automatically merged:

When posting a script, use [ code=lua] before and [/ code] after removing the space before the Word code

Ex.:
[ Code=lua]code here[/ code] < without space inside [ ]

Chatgpt:
Lua:
local SUMMON_TIME = 60 * 60 * 1000 -- 1 hora em milissegundos
local SUMMON_NAME = "Orc Leader"

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getTile():hasFlag(TILESTATE_PROTECTIONZONE) then
        player:sendCancelMessage("Você não pode usar este item em uma zona de proteção.")
        return true
    end

    local summons = player:getSummons()
    for i = 1, #summons do
        local summon = summons[i]
        if summon:getType():getName() == SUMMON_NAME then
            summon:remove()
            stopEvent(removeEvent)
            return true
        end
    end

    local summonPosition = player:getClosestFreePosition(player:getPosition(), false)
    if not summonPosition then
        player:sendCancelMessage("Não há espaço suficiente para invocar o summon.")
        return true
    end

    local summon = Game.createMonster(SUMMON_NAME, summonPosition)
    if not summon then
        player:sendCancelMessage("Não foi possível invocar o summon.")
        return true
    end

    player:addSummon(summon)
    summon:setMaster(player)

    removeEvent = addEvent(function()
        if summon and summon:isCreature() then
            summon:remove()
            item:remove(1)
        end
    end, SUMMON_TIME)

    return true
end

I don't get what you really want, summon when clkck and remove summon when click again? Remove item or no? Auto remove summom after some time or no?
bro i did not see u was using chat gpt lol i tried here and wtf, i was creating script by my own what a fool lol now i discover the world thank u all guys now i can make everything
 
Last edited:
bro did not see u was using chat gpt lol i tried here and wtf, i was creating script by my own what a fool lol now i discover the world thank u all guys now i can make everything

Not everything, but ye, its a good start
 
Not everything, but ye, its a good start
thank u so much and thanks @Xikini for the time and the heart to help, when i found out chatgpt could help it was way easier, i could improve the code @mano368 with chat cpt help and now it has some improvements and players can use it too, i will put below if smn need smeday

Lua:
local SUMMON_TIME = 1 * 60 * 1000 -- 1 minuto em milissegundos
local SUMMON_NAME = "Training Monk"
local removeEvent = nil
local summon = nil -- Referência ao monstro invocado
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if summon then
        summon:remove()
        summon = nil -- Limpar a referência do monstro
        if removeEvent then
            stopEvent(removeEvent)
            removeEvent = nil -- Limpar a referência do evento
        end
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Você removeu o Training Monk.")
        return true
    end
    local playerPosition = player:getPosition()
    local directions = {NORTH, EAST, SOUTH, WEST, NORTHEAST, NORTHWEST, SOUTHEAST, SOUTHWEST}
    local validPositions = {}
    for i = 1, #directions do
        local checkPosition = Position(playerPosition.x, playerPosition.y, playerPosition.z)
        checkPosition:getNextPosition(directions[I])
        local tile = Tile(checkPosition)
        
        if tile then
            if tile:hasFlag(TILESTATE_BLOCKSOLID) then
                player:sendCancelMessage("Você precisa de espaço para poder criar seu Dummy aqui.")
                return true
            else
                if tile:getTopCreature() then
                    player:sendCancelMessage("Você precisa de espaço para poder criar seu Dummy aqui.")
                    return true
                else
                    table.insert(validPositions, checkPosition)
                end
            end
        end
    end
    if #validPositions == 0 then
        player:sendCancelMessage("Você precisa de espaço para poder criar seu Dummy.")
        return true
    end
    local summonPosition = validPositions[math.random(#validPositions)]
    summon = Game.createMonster(SUMMON_NAME, summonPosition)
    if not summon or not summon:isCreature() then
        player:sendCancelMessage("Não foi possível invocar o summon.")
        return true
    end
    player:addSummon(summon)
    summon:setMaster(player)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Você invocou um Training Monk!")
    if removeEvent then
        stopEvent(removeEvent)
    end
    removeEvent = addEvent(function()
        if summon and summon:isCreature() then
            summon:remove()
            item:remove(1)
            summon = nil -- Limpar a referência do monstro
            removeEvent = nil -- Limpar a referência do evento
        end
    end, SUMMON_TIME)
    return true
end
[/I]
 
Back
Top